/external/apache-harmony/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TreeMapExtendTest.java

https://gitlab.com/brian0218/rk3188_r-box_android4.2.2_sdk · Java · 1345 lines · 1009 code · 240 blank · 96 comment · 11 complexity · 0397a875e7614b624723d9d60c68ba28 MD5 · raw file

  1. package org.apache.harmony.luni.tests.java.util;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. import java.util.Collection;
  19. import java.util.Collections;
  20. import java.util.Comparator;
  21. import java.util.Iterator;
  22. import java.util.Map;
  23. import java.util.NavigableMap;
  24. import java.util.NavigableSet;
  25. import java.util.NoSuchElementException;
  26. import java.util.Set;
  27. import java.util.SortedMap;
  28. import java.util.SortedSet;
  29. import java.util.TreeMap;
  30. import java.util.Map.Entry;
  31. import junit.framework.TestCase;
  32. import org.apache.harmony.luni.tests.java.util.TreeMapTest.MockComparator;
  33. //
  34. public class TreeMapExtendTest extends TestCase {
  35. TreeMap tm;
  36. TreeMap tm_comparator;
  37. SortedMap subMap_default;
  38. SortedMap subMap_startExcluded_endExcluded;
  39. SortedMap subMap_startExcluded_endIncluded;
  40. SortedMap subMap_startIncluded_endExcluded;
  41. SortedMap subMap_startIncluded_endIncluded;
  42. SortedMap subMap_default_beforeStart_100;
  43. SortedMap subMap_default_afterEnd_109;
  44. NavigableMap navigableMap_startExcluded_endExcluded;
  45. NavigableMap navigableMap_startExcluded_endIncluded;
  46. NavigableMap navigableMap_startIncluded_endExcluded;
  47. NavigableMap navigableMap_startIncluded_endIncluded;
  48. SortedMap subMap_default_comparator;
  49. SortedMap subMap_startExcluded_endExcluded_comparator;
  50. SortedMap subMap_startExcluded_endIncluded_comparator;
  51. SortedMap subMap_startIncluded_endExcluded_comparator;
  52. SortedMap subMap_startIncluded_endIncluded_comparator;
  53. Object objArray[] = new Object[1000];
  54. public void test_TreeMap_Constructor_Default() {
  55. TreeMap treeMap = new TreeMap();
  56. assertTrue(treeMap.isEmpty());
  57. assertNull(treeMap.comparator());
  58. assertEquals(0, treeMap.size());
  59. try {
  60. treeMap.firstKey();
  61. fail("should throw NoSuchElementException");
  62. } catch (NoSuchElementException e) {
  63. // Expected
  64. }
  65. assertNull(treeMap.firstEntry());
  66. try {
  67. treeMap.lastKey();
  68. fail("should throw NoSuchElementException");
  69. } catch (NoSuchElementException e) {
  70. // Expected
  71. }
  72. assertNull(treeMap.lastEntry());
  73. try {
  74. treeMap.ceilingKey(1);
  75. } catch (NoSuchElementException e) {
  76. // Expected
  77. }
  78. assertNull(treeMap.ceilingEntry(1));
  79. try {
  80. treeMap.floorKey(1);
  81. } catch (NoSuchElementException e) {
  82. // Expected
  83. }
  84. assertNull(treeMap.floorEntry(1));
  85. assertNull(treeMap.lowerKey(1));
  86. assertNull(treeMap.lowerEntry(1));
  87. assertNull(treeMap.higherKey(1));
  88. assertNull(treeMap.higherEntry(1));
  89. assertFalse(treeMap.containsKey(1));
  90. assertFalse(treeMap.containsValue(1));
  91. assertNull(treeMap.get(1));
  92. assertNull(treeMap.pollFirstEntry());
  93. assertNull(treeMap.pollLastEntry());
  94. assertEquals(0, treeMap.values().size());
  95. }
  96. public void test_TreeMap_Constructor_Comparator() {
  97. MockComparator mockComparator = new MockComparator();
  98. TreeMap treeMap = new TreeMap(mockComparator);
  99. assertEquals(mockComparator, treeMap.comparator());
  100. }
  101. public void test_TreeMap_Constructor_Map() {
  102. TreeMap treeMap = new TreeMap(tm);
  103. assertEquals(tm.size(), treeMap.size());
  104. assertEquals(tm.firstKey(), treeMap.firstKey());
  105. assertEquals(tm.firstEntry(), treeMap.firstEntry());
  106. assertEquals(tm.lastKey(), treeMap.lastKey());
  107. assertEquals(tm.lastEntry(), treeMap.lastEntry());
  108. assertEquals(tm.keySet(), treeMap.keySet());
  109. String key = new Integer(100).toString();
  110. assertEquals(tm.ceilingKey(key), treeMap.ceilingKey(key));
  111. assertEquals(tm.ceilingEntry(key), treeMap.ceilingEntry(key));
  112. assertEquals(tm.floorKey(key), treeMap.floorKey(key));
  113. assertEquals(tm.floorEntry(key), treeMap.floorEntry(key));
  114. assertEquals(tm.lowerKey(key), treeMap.lowerKey(key));
  115. assertEquals(tm.lowerEntry(key), treeMap.lowerEntry(key));
  116. assertEquals(tm.higherKey(key), treeMap.higherKey(key));
  117. assertEquals(tm.higherEntry(key), treeMap.higherEntry(key));
  118. assertEquals(tm.entrySet(), treeMap.entrySet());
  119. }
  120. public void test_TreeMap_Constructor_SortedMap() {
  121. TreeMap treeMap = new TreeMap(subMap_default);
  122. assertEquals(subMap_default.size(), treeMap.size());
  123. assertEquals(subMap_default.firstKey(), treeMap.firstKey());
  124. assertEquals(subMap_default.lastKey(), treeMap.lastKey());
  125. assertEquals(subMap_default.keySet(), treeMap.keySet());
  126. assertEquals(subMap_default.entrySet(), treeMap.entrySet());
  127. }
  128. public void test_TreeMap_clear() {
  129. tm.clear();
  130. assertEquals(0, tm.size());
  131. }
  132. public void test_TreeMap_clone() {
  133. TreeMap cloneTreeMap = (TreeMap) tm.clone();
  134. assertEquals(tm, cloneTreeMap);
  135. }
  136. public void test_SubMap_Constructor() {
  137. }
  138. public void test_SubMap_clear() {
  139. subMap_default.clear();
  140. assertEquals(0, subMap_default.size());
  141. }
  142. public void test_SubMap_comparator() {
  143. assertEquals(tm.comparator(), subMap_default.comparator());
  144. }
  145. public void test_SubMap_containsKey() {
  146. String key = null;
  147. for (int counter = 101; counter < 109; counter++) {
  148. key = objArray[counter].toString();
  149. assertTrue("SubMap contains incorrect elements", subMap_default
  150. .containsKey(key));
  151. assertTrue("SubMap contains incorrect elements",
  152. subMap_startExcluded_endExcluded.containsKey(key));
  153. assertTrue("SubMap contains incorrect elements",
  154. subMap_startExcluded_endIncluded.containsKey(key));
  155. assertTrue("SubMap contains incorrect elements",
  156. subMap_startIncluded_endExcluded.containsKey(key));
  157. assertTrue("SubMap contains incorrect elements",
  158. subMap_startIncluded_endIncluded.containsKey(key));
  159. }
  160. // Check boundary
  161. key = objArray[100].toString();
  162. assertTrue("SubMap contains incorrect elements", subMap_default
  163. .containsKey(key));
  164. assertFalse("SubMap contains incorrect elements",
  165. subMap_startExcluded_endExcluded.containsKey(key));
  166. assertFalse("SubMap contains incorrect elements",
  167. subMap_startExcluded_endIncluded.containsKey(key));
  168. assertTrue("SubMap contains incorrect elements",
  169. subMap_startIncluded_endExcluded.containsKey(key));
  170. assertTrue("SubMap contains incorrect elements",
  171. subMap_startIncluded_endIncluded.containsKey(key));
  172. key = objArray[109].toString();
  173. assertFalse("SubMap contains incorrect elements", subMap_default
  174. .containsKey(key));
  175. assertFalse("SubMap contains incorrect elements",
  176. subMap_startExcluded_endExcluded.containsKey(key));
  177. assertTrue("SubMap contains incorrect elements",
  178. subMap_startExcluded_endIncluded.containsKey(key));
  179. assertFalse("SubMap contains incorrect elements",
  180. subMap_startIncluded_endExcluded.containsKey(key));
  181. assertTrue("SubMap contains incorrect elements",
  182. subMap_startIncluded_endIncluded.containsKey(key));
  183. // With Comparator
  184. for (int counter = 101; counter < 109; counter++) {
  185. key = objArray[counter].toString();
  186. assertTrue("SubMap contains incorrect elements",
  187. subMap_default_comparator.containsKey(key));
  188. assertTrue("SubMap contains incorrect elements",
  189. subMap_startExcluded_endExcluded_comparator
  190. .containsKey(key));
  191. assertTrue("SubMap contains incorrect elements",
  192. subMap_startExcluded_endIncluded_comparator
  193. .containsKey(key));
  194. assertTrue("SubMap contains incorrect elements",
  195. subMap_startIncluded_endExcluded_comparator
  196. .containsKey(key));
  197. assertTrue("SubMap contains incorrect elements",
  198. subMap_startIncluded_endIncluded_comparator
  199. .containsKey(key));
  200. }
  201. // Check boundary
  202. key = objArray[100].toString();
  203. assertTrue("SubMap contains incorrect elements",
  204. subMap_default_comparator.containsKey(key));
  205. assertFalse("SubMap contains incorrect elements",
  206. subMap_startExcluded_endExcluded_comparator.containsKey(key));
  207. assertFalse("SubMap contains incorrect elements",
  208. subMap_startExcluded_endIncluded_comparator.containsKey(key));
  209. assertTrue("SubMap contains incorrect elements",
  210. subMap_startIncluded_endExcluded_comparator.containsKey(key));
  211. assertTrue("SubMap contains incorrect elements",
  212. subMap_startIncluded_endIncluded_comparator.containsKey(key));
  213. key = objArray[109].toString();
  214. assertFalse("SubMap contains incorrect elements",
  215. subMap_default_comparator.containsKey(key));
  216. assertFalse("SubMap contains incorrect elements",
  217. subMap_startExcluded_endExcluded_comparator.containsKey(key));
  218. assertTrue("SubMap contains incorrect elements",
  219. subMap_startExcluded_endIncluded_comparator.containsKey(key));
  220. assertFalse("SubMap contains incorrect elements",
  221. subMap_startIncluded_endExcluded_comparator.containsKey(key));
  222. assertTrue("SubMap contains incorrect elements",
  223. subMap_startIncluded_endIncluded_comparator.containsKey(key));
  224. }
  225. public void test_SubMap_containsValue() {
  226. Object value = null;
  227. for (int counter = 101; counter < 109; counter++) {
  228. value = objArray[counter];
  229. assertTrue("SubMap contains incorrect elements", subMap_default
  230. .containsValue(value));
  231. assertTrue("SubMap contains incorrect elements",
  232. subMap_startExcluded_endExcluded.containsValue(value));
  233. assertTrue("SubMap contains incorrect elements",
  234. subMap_startExcluded_endIncluded.containsValue(value));
  235. assertTrue("SubMap contains incorrect elements",
  236. subMap_startIncluded_endExcluded.containsValue(value));
  237. assertTrue("SubMap contains incorrect elements",
  238. subMap_startIncluded_endIncluded.containsValue(value));
  239. }
  240. // Check boundary
  241. value = objArray[100];
  242. assertTrue("SubMap contains incorrect elements", subMap_default
  243. .containsValue(value));
  244. assertFalse("SubMap contains incorrect elements",
  245. subMap_startExcluded_endExcluded.containsValue(value));
  246. assertFalse("SubMap contains incorrect elements",
  247. subMap_startExcluded_endIncluded.containsValue(value));
  248. assertTrue("SubMap contains incorrect elements",
  249. subMap_startIncluded_endExcluded.containsValue(value));
  250. assertTrue("SubMap contains incorrect elements",
  251. subMap_startIncluded_endIncluded.containsValue(value));
  252. value = objArray[109];
  253. assertFalse("SubMap contains incorrect elements", subMap_default
  254. .containsValue(value));
  255. assertFalse("SubMap contains incorrect elements",
  256. subMap_startExcluded_endExcluded.containsValue(value));
  257. assertTrue("SubMap contains incorrect elements",
  258. subMap_startExcluded_endIncluded.containsValue(value));
  259. assertFalse("SubMap contains incorrect elements",
  260. subMap_startIncluded_endExcluded.containsValue(value));
  261. assertTrue("SubMap contains incorrect elements",
  262. subMap_startIncluded_endIncluded.containsValue(value));
  263. assertFalse(subMap_default.containsValue(null));
  264. TreeMap tm_null = new TreeMap();
  265. tm_null.put("0", 1);
  266. tm_null.put("1", null);
  267. tm_null.put("2", 2);
  268. SortedMap subMap = tm_null.subMap("0", "2");
  269. assertTrue(subMap.containsValue(null));
  270. subMap.remove("1");
  271. assertFalse(subMap.containsValue(null));
  272. }
  273. public void test_SubMap_entrySet() {
  274. Set entrySet = subMap_default.entrySet();
  275. assertFalse(entrySet.isEmpty());
  276. assertEquals(9, entrySet.size());
  277. entrySet = subMap_startExcluded_endExcluded.entrySet();
  278. assertFalse(entrySet.isEmpty());
  279. assertEquals(8, entrySet.size());
  280. entrySet = subMap_startExcluded_endIncluded.entrySet();
  281. assertFalse(entrySet.isEmpty());
  282. assertEquals(9, entrySet.size());
  283. entrySet = subMap_startIncluded_endExcluded.entrySet();
  284. assertFalse(entrySet.isEmpty());
  285. assertEquals(9, entrySet.size());
  286. entrySet = subMap_startIncluded_endIncluded.entrySet();
  287. assertFalse(entrySet.isEmpty());
  288. assertEquals(10, entrySet.size());
  289. }
  290. public void test_SubMap_firstKey() {
  291. String firstKey1 = new Integer(100).toString();
  292. String firstKey2 = new Integer(101).toString();
  293. assertEquals(firstKey1, subMap_default.firstKey());
  294. assertEquals(firstKey2, subMap_startExcluded_endExcluded.firstKey());
  295. assertEquals(firstKey2, subMap_startExcluded_endIncluded.firstKey());
  296. assertEquals(firstKey1, subMap_startIncluded_endExcluded.firstKey());
  297. assertEquals(firstKey1, subMap_startIncluded_endIncluded.firstKey());
  298. try {
  299. subMap_default.subMap(firstKey1, firstKey1).firstKey();
  300. fail("should throw NoSuchElementException");
  301. } catch (NoSuchElementException e) {
  302. // Expected
  303. }
  304. try {
  305. subMap_startExcluded_endExcluded.subMap(firstKey2, firstKey2)
  306. .firstKey();
  307. fail("should throw NoSuchElementException");
  308. } catch (NoSuchElementException e) {
  309. // Expected
  310. }
  311. try {
  312. subMap_startExcluded_endIncluded.subMap(firstKey2, firstKey2)
  313. .firstKey();
  314. fail("should throw NoSuchElementException");
  315. } catch (NoSuchElementException e) {
  316. // Expected
  317. }
  318. try {
  319. subMap_startIncluded_endExcluded.subMap(firstKey1, firstKey1)
  320. .firstKey();
  321. fail("should throw NoSuchElementException");
  322. } catch (NoSuchElementException e) {
  323. // Expected
  324. }
  325. try {
  326. subMap_startIncluded_endIncluded.subMap(firstKey1, firstKey1)
  327. .firstKey();
  328. fail("should throw NoSuchElementException");
  329. } catch (NoSuchElementException e) {
  330. // Expected
  331. }
  332. // With Comparator
  333. assertEquals(firstKey1, subMap_default_comparator.firstKey());
  334. assertEquals(firstKey2, subMap_startExcluded_endExcluded_comparator
  335. .firstKey());
  336. assertEquals(firstKey2, subMap_startExcluded_endIncluded_comparator
  337. .firstKey());
  338. assertEquals(firstKey1, subMap_startIncluded_endExcluded_comparator
  339. .firstKey());
  340. assertEquals(firstKey1, subMap_startIncluded_endIncluded_comparator
  341. .firstKey());
  342. try {
  343. subMap_default_comparator.subMap(firstKey1, firstKey1).firstKey();
  344. fail("should throw NoSuchElementException");
  345. } catch (NoSuchElementException e) {
  346. // Expected
  347. }
  348. try {
  349. subMap_startExcluded_endExcluded_comparator.subMap(firstKey2,
  350. firstKey2).firstKey();
  351. fail("should throw NoSuchElementException");
  352. } catch (NoSuchElementException e) {
  353. // Expected
  354. }
  355. try {
  356. subMap_startExcluded_endIncluded_comparator.subMap(firstKey2,
  357. firstKey2).firstKey();
  358. fail("should throw NoSuchElementException");
  359. } catch (NoSuchElementException e) {
  360. // Expected
  361. }
  362. try {
  363. subMap_startIncluded_endExcluded_comparator.subMap(firstKey1,
  364. firstKey1).firstKey();
  365. fail("should throw NoSuchElementException");
  366. } catch (NoSuchElementException e) {
  367. // Expected
  368. }
  369. try {
  370. subMap_startIncluded_endIncluded_comparator.subMap(firstKey1,
  371. firstKey1).firstKey();
  372. fail("should throw NoSuchElementException");
  373. } catch (NoSuchElementException e) {
  374. // Expected
  375. }
  376. }
  377. public void test_SubMap_lastKey() {
  378. String lastKey1 = new Integer(108).toString();
  379. String lastKey2 = new Integer(109).toString();
  380. assertEquals(lastKey1, subMap_default.lastKey());
  381. assertEquals(lastKey1, subMap_startExcluded_endExcluded.lastKey());
  382. assertEquals(lastKey2, subMap_startExcluded_endIncluded.lastKey());
  383. assertEquals(lastKey1, subMap_startIncluded_endExcluded.lastKey());
  384. assertEquals(lastKey2, subMap_startIncluded_endIncluded.lastKey());
  385. try {
  386. subMap_default.subMap(lastKey1, lastKey1).lastKey();
  387. fail("should throw NoSuchElementException");
  388. } catch (NoSuchElementException e) {
  389. // Expected
  390. }
  391. try {
  392. subMap_startExcluded_endExcluded.subMap(lastKey1, lastKey1)
  393. .lastKey();
  394. fail("should throw NoSuchElementException");
  395. } catch (NoSuchElementException e) {
  396. // Expected
  397. }
  398. try {
  399. subMap_startExcluded_endIncluded.subMap(lastKey2, lastKey2)
  400. .lastKey();
  401. fail("should throw NoSuchElementException");
  402. } catch (NoSuchElementException e) {
  403. // Expected
  404. }
  405. try {
  406. subMap_startIncluded_endExcluded.subMap(lastKey1, lastKey1)
  407. .lastKey();
  408. fail("should throw NoSuchElementException");
  409. } catch (NoSuchElementException e) {
  410. // Expected
  411. }
  412. try {
  413. subMap_startIncluded_endIncluded.subMap(lastKey2, lastKey2)
  414. .lastKey();
  415. fail("should throw NoSuchElementException");
  416. } catch (NoSuchElementException e) {
  417. // Expected
  418. }
  419. // With Comparator
  420. assertEquals(lastKey1, subMap_default_comparator.lastKey());
  421. assertEquals(lastKey1, subMap_startExcluded_endExcluded_comparator
  422. .lastKey());
  423. assertEquals(lastKey2, subMap_startExcluded_endIncluded_comparator
  424. .lastKey());
  425. assertEquals(lastKey1, subMap_startIncluded_endExcluded_comparator
  426. .lastKey());
  427. assertEquals(lastKey2, subMap_startIncluded_endIncluded_comparator
  428. .lastKey());
  429. try {
  430. subMap_default_comparator.subMap(lastKey1, lastKey1).lastKey();
  431. fail("should throw NoSuchElementException");
  432. } catch (NoSuchElementException e) {
  433. // Expected
  434. }
  435. try {
  436. subMap_startExcluded_endExcluded_comparator.subMap(lastKey1,
  437. lastKey1).lastKey();
  438. fail("should throw NoSuchElementException");
  439. } catch (NoSuchElementException e) {
  440. // Expected
  441. }
  442. try {
  443. subMap_startExcluded_endIncluded_comparator.subMap(lastKey2,
  444. lastKey2).lastKey();
  445. fail("should throw NoSuchElementException");
  446. } catch (NoSuchElementException e) {
  447. // Expected
  448. }
  449. try {
  450. subMap_startIncluded_endExcluded_comparator.subMap(lastKey1,
  451. lastKey1).lastKey();
  452. fail("should throw NoSuchElementException");
  453. } catch (NoSuchElementException e) {
  454. // Expected
  455. }
  456. try {
  457. subMap_startIncluded_endIncluded_comparator.subMap(lastKey2,
  458. lastKey2).lastKey();
  459. fail("should throw NoSuchElementException");
  460. } catch (NoSuchElementException e) {
  461. // Expected
  462. }
  463. }
  464. public void test_SubMap_get() {
  465. // left boundary
  466. Integer value = new Integer(100);
  467. assertEquals(value, subMap_default.get(value.toString()));
  468. assertEquals(null, subMap_startExcluded_endExcluded.get(value
  469. .toString()));
  470. assertEquals(null, subMap_startExcluded_endIncluded.get(value
  471. .toString()));
  472. assertEquals(value, subMap_startIncluded_endExcluded.get(value
  473. .toString()));
  474. assertEquals(value, subMap_startIncluded_endIncluded.get(value
  475. .toString()));
  476. // normal value
  477. value = new Integer(105);
  478. assertEquals(value, subMap_default.get(value.toString()));
  479. assertEquals(value, subMap_startExcluded_endExcluded.get(value
  480. .toString()));
  481. assertEquals(value, subMap_startExcluded_endIncluded.get(value
  482. .toString()));
  483. assertEquals(value, subMap_startIncluded_endExcluded.get(value
  484. .toString()));
  485. assertEquals(value, subMap_startIncluded_endIncluded.get(value
  486. .toString()));
  487. // right boundary
  488. value = new Integer(109);
  489. assertEquals(null, subMap_default.get(value.toString()));
  490. assertEquals(null, subMap_startExcluded_endExcluded.get(value
  491. .toString()));
  492. assertEquals(value, subMap_startExcluded_endIncluded.get(value
  493. .toString()));
  494. assertEquals(null, subMap_startIncluded_endExcluded.get(value
  495. .toString()));
  496. assertEquals(value, subMap_startIncluded_endIncluded.get(value
  497. .toString()));
  498. // With Comparator to test inInRange
  499. // left boundary
  500. value = new Integer(100);
  501. assertEquals(value, subMap_default_comparator.get(value.toString()));
  502. // normal value
  503. value = new Integer(105);
  504. assertEquals(value, subMap_default_comparator.get(value.toString()));
  505. // right boundary
  506. value = new Integer(109);
  507. assertEquals(null, subMap_default_comparator.get(value.toString()));
  508. }
  509. public void test_SubMap_headMap() {
  510. String endKey = new Integer(99).toString();
  511. try {
  512. subMap_default.headMap(endKey);
  513. fail("should throw IllegalArgumentException");
  514. } catch (IllegalArgumentException e) {
  515. // Expected
  516. }
  517. try {
  518. subMap_startExcluded_endExcluded.headMap(endKey);
  519. fail("should throw IllegalArgumentException");
  520. } catch (IllegalArgumentException e) {
  521. // Expected
  522. }
  523. try {
  524. subMap_startExcluded_endIncluded.headMap(endKey);
  525. fail("should throw IllegalArgumentException");
  526. } catch (IllegalArgumentException e) {
  527. // Expected
  528. }
  529. try {
  530. subMap_startIncluded_endExcluded.headMap(endKey);
  531. fail("should throw IllegalArgumentException");
  532. } catch (IllegalArgumentException e) {
  533. // Expected
  534. }
  535. try {
  536. subMap_startIncluded_endIncluded.headMap(endKey);
  537. fail("should throw IllegalArgumentException");
  538. } catch (IllegalArgumentException e) {
  539. // Expected
  540. }
  541. SortedMap headMap = null;
  542. endKey = new Integer(100).toString();
  543. headMap = subMap_default.headMap(endKey);
  544. assertEquals(0, headMap.size());
  545. headMap = subMap_startExcluded_endExcluded.headMap(endKey);
  546. assertEquals(0, headMap.size());
  547. headMap = subMap_startExcluded_endIncluded.headMap(endKey);
  548. assertEquals(0, headMap.size());
  549. headMap = subMap_startIncluded_endExcluded.headMap(endKey);
  550. assertEquals(0, headMap.size());
  551. headMap = subMap_startIncluded_endIncluded.headMap(endKey);
  552. assertEquals(0, headMap.size());
  553. for (int i = 0, j = 101; i < 8; i++) {
  554. endKey = new Integer(i + j).toString();
  555. headMap = subMap_default.headMap(endKey);
  556. assertEquals(i + 1, headMap.size());
  557. headMap = subMap_startExcluded_endExcluded.headMap(endKey);
  558. assertEquals(i, headMap.size());
  559. headMap = subMap_startExcluded_endIncluded.headMap(endKey);
  560. assertEquals(i, headMap.size());
  561. headMap = subMap_startIncluded_endExcluded.headMap(endKey);
  562. assertEquals(i + 1, headMap.size());
  563. headMap = subMap_startIncluded_endIncluded.headMap(endKey);
  564. assertEquals(i + 1, headMap.size());
  565. }
  566. endKey = new Integer(109).toString();
  567. headMap = subMap_default.headMap(endKey);
  568. assertEquals(9, headMap.size());
  569. headMap = subMap_startExcluded_endExcluded.headMap(endKey);
  570. assertEquals(8, headMap.size());
  571. headMap = subMap_startExcluded_endIncluded.headMap(endKey);
  572. assertEquals(8, headMap.size());
  573. headMap = subMap_startIncluded_endExcluded.headMap(endKey);
  574. assertEquals(9, headMap.size());
  575. headMap = subMap_startIncluded_endIncluded.headMap(endKey);
  576. assertEquals(9, headMap.size());
  577. endKey = new Integer(110).toString();
  578. try {
  579. subMap_default.headMap(endKey);
  580. fail("should throw IllegalArgumentException");
  581. } catch (IllegalArgumentException e) {
  582. // Expected
  583. }
  584. try {
  585. subMap_startExcluded_endExcluded.headMap(endKey);
  586. fail("should throw IllegalArgumentException");
  587. } catch (IllegalArgumentException e) {
  588. // Expected
  589. }
  590. try {
  591. subMap_startExcluded_endIncluded.headMap(endKey);
  592. fail("should throw IllegalArgumentException");
  593. } catch (IllegalArgumentException e) {
  594. // Expected
  595. }
  596. try {
  597. subMap_startIncluded_endExcluded.headMap(endKey);
  598. fail("should throw IllegalArgumentException");
  599. } catch (IllegalArgumentException e) {
  600. // Expected
  601. }
  602. try {
  603. subMap_startIncluded_endIncluded.headMap(endKey);
  604. fail("should throw IllegalArgumentException");
  605. } catch (IllegalArgumentException e) {
  606. // Expected
  607. }
  608. // With Comparator
  609. endKey = new Integer(99).toString();
  610. try {
  611. subMap_default_comparator.headMap(endKey);
  612. fail("should throw IllegalArgumentException");
  613. } catch (IllegalArgumentException e) {
  614. // Expected
  615. }
  616. try {
  617. subMap_startExcluded_endExcluded_comparator.headMap(endKey);
  618. fail("should throw IllegalArgumentException");
  619. } catch (IllegalArgumentException e) {
  620. // Expected
  621. }
  622. try {
  623. subMap_startExcluded_endIncluded_comparator.headMap(endKey);
  624. fail("should throw IllegalArgumentException");
  625. } catch (IllegalArgumentException e) {
  626. // Expected
  627. }
  628. try {
  629. subMap_startIncluded_endExcluded_comparator.headMap(endKey);
  630. fail("should throw IllegalArgumentException");
  631. } catch (IllegalArgumentException e) {
  632. // Expected
  633. }
  634. try {
  635. subMap_startIncluded_endIncluded_comparator.headMap(endKey);
  636. fail("should throw IllegalArgumentException");
  637. } catch (IllegalArgumentException e) {
  638. // Expected
  639. }
  640. headMap = null;
  641. endKey = new Integer(100).toString();
  642. headMap = subMap_default_comparator.headMap(endKey);
  643. assertEquals(0, headMap.size());
  644. headMap = subMap_startExcluded_endExcluded_comparator.headMap(endKey);
  645. assertEquals(0, headMap.size());
  646. headMap = subMap_startExcluded_endIncluded_comparator.headMap(endKey);
  647. assertEquals(0, headMap.size());
  648. headMap = subMap_startIncluded_endExcluded_comparator.headMap(endKey);
  649. assertEquals(0, headMap.size());
  650. headMap = subMap_startIncluded_endIncluded_comparator.headMap(endKey);
  651. assertEquals(0, headMap.size());
  652. for (int i = 0, j = 101; i < 8; i++) {
  653. endKey = new Integer(i + j).toString();
  654. headMap = subMap_default_comparator.headMap(endKey);
  655. assertEquals(i + 1, headMap.size());
  656. headMap = subMap_startExcluded_endExcluded_comparator
  657. .headMap(endKey);
  658. assertEquals(i, headMap.size());
  659. headMap = subMap_startExcluded_endIncluded_comparator
  660. .headMap(endKey);
  661. assertEquals(i, headMap.size());
  662. headMap = subMap_startIncluded_endExcluded_comparator
  663. .headMap(endKey);
  664. assertEquals(i + 1, headMap.size());
  665. headMap = subMap_startIncluded_endIncluded_comparator
  666. .headMap(endKey);
  667. assertEquals(i + 1, headMap.size());
  668. }
  669. endKey = new Integer(108).toString();
  670. headMap = subMap_default_comparator.headMap(endKey);
  671. assertEquals(8, headMap.size());
  672. headMap = subMap_startExcluded_endExcluded_comparator.headMap(endKey);
  673. assertEquals(7, headMap.size());
  674. headMap = subMap_startExcluded_endIncluded_comparator.headMap(endKey);
  675. assertEquals(7, headMap.size());
  676. headMap = subMap_startIncluded_endExcluded_comparator.headMap(endKey);
  677. assertEquals(8, headMap.size());
  678. headMap = subMap_startIncluded_endIncluded_comparator.headMap(endKey);
  679. assertEquals(8, headMap.size());
  680. endKey = new Integer(110).toString();
  681. try {
  682. subMap_default_comparator.headMap(endKey);
  683. fail("should throw IllegalArgumentException");
  684. } catch (IllegalArgumentException e) {
  685. // Expected
  686. }
  687. try {
  688. subMap_startExcluded_endExcluded_comparator.headMap(endKey);
  689. fail("should throw IllegalArgumentException");
  690. } catch (IllegalArgumentException e) {
  691. // Expected
  692. }
  693. try {
  694. subMap_startExcluded_endIncluded_comparator.headMap(endKey);
  695. fail("should throw IllegalArgumentException");
  696. } catch (IllegalArgumentException e) {
  697. // Expected
  698. }
  699. try {
  700. subMap_startIncluded_endExcluded_comparator.headMap(endKey);
  701. fail("should throw IllegalArgumentException");
  702. } catch (IllegalArgumentException e) {
  703. // Expected
  704. }
  705. try {
  706. subMap_startIncluded_endIncluded_comparator.headMap(endKey);
  707. fail("should throw IllegalArgumentException");
  708. } catch (IllegalArgumentException e) {
  709. // Expected
  710. }
  711. }
  712. public void test_SubMap_isEmpty() {
  713. assertFalse(subMap_default.isEmpty());
  714. assertFalse(subMap_startExcluded_endExcluded.isEmpty());
  715. assertFalse(subMap_startExcluded_endIncluded.isEmpty());
  716. assertFalse(subMap_startIncluded_endExcluded.isEmpty());
  717. assertFalse(subMap_startIncluded_endIncluded.isEmpty());
  718. Object startKey = new Integer(100);
  719. Object endKey = startKey;
  720. SortedMap subMap = tm.subMap(startKey.toString(), endKey.toString());
  721. assertTrue(subMap.isEmpty());
  722. subMap = subMap_default.subMap(startKey.toString(), endKey.toString());
  723. assertTrue(subMap.isEmpty());
  724. subMap = subMap_startIncluded_endExcluded.subMap(startKey.toString(),
  725. endKey.toString());
  726. assertTrue(subMap.isEmpty());
  727. subMap = subMap_startIncluded_endIncluded.subMap(startKey.toString(),
  728. endKey.toString());
  729. assertTrue(subMap.isEmpty());
  730. for (int i = 0, j = 101; i < 8; i++) {
  731. startKey = i + j;
  732. endKey = startKey;
  733. subMap = subMap_default.subMap(startKey.toString(), endKey
  734. .toString());
  735. assertTrue(subMap.isEmpty());
  736. subMap = subMap_startExcluded_endExcluded.subMap(startKey
  737. .toString(), endKey.toString());
  738. assertTrue(subMap.isEmpty());
  739. subMap = subMap_startExcluded_endIncluded.subMap(startKey
  740. .toString(), endKey.toString());
  741. assertTrue(subMap.isEmpty());
  742. subMap = subMap_startIncluded_endExcluded.subMap(startKey
  743. .toString(), endKey.toString());
  744. assertTrue(subMap.isEmpty());
  745. subMap = subMap_startIncluded_endIncluded.subMap(startKey
  746. .toString(), endKey.toString());
  747. assertTrue(subMap.isEmpty());
  748. }
  749. for (int i = 0, j = 101; i < 5; i++) {
  750. startKey = i + j;
  751. endKey = i + j + 4;
  752. subMap = subMap_default.subMap(startKey.toString(), endKey
  753. .toString());
  754. assertFalse(subMap.isEmpty());
  755. subMap = subMap_startExcluded_endExcluded.subMap(startKey
  756. .toString(), endKey.toString());
  757. assertFalse(subMap.isEmpty());
  758. subMap = subMap_startExcluded_endIncluded.subMap(startKey
  759. .toString(), endKey.toString());
  760. assertFalse(subMap.isEmpty());
  761. subMap = subMap_startIncluded_endExcluded.subMap(startKey
  762. .toString(), endKey.toString());
  763. assertFalse(subMap.isEmpty());
  764. subMap = subMap_startIncluded_endIncluded.subMap(startKey
  765. .toString(), endKey.toString());
  766. assertFalse(subMap.isEmpty());
  767. }
  768. startKey = new Integer(109).toString();
  769. endKey = startKey;
  770. subMap = tm.subMap(startKey.toString(), endKey.toString());
  771. assertTrue(subMap.isEmpty());
  772. subMap = subMap_startExcluded_endIncluded.subMap(startKey, endKey);
  773. assertTrue(subMap.isEmpty());
  774. subMap = subMap_startIncluded_endIncluded.subMap(startKey, endKey);
  775. assertTrue(subMap.isEmpty());
  776. }
  777. public void test_SubMap_keySet() {
  778. Set keySet = subMap_default.keySet();
  779. assertFalse(keySet.isEmpty());
  780. assertEquals(9, keySet.size());
  781. keySet = subMap_startExcluded_endExcluded.entrySet();
  782. assertFalse(keySet.isEmpty());
  783. assertEquals(8, keySet.size());
  784. keySet = subMap_startExcluded_endIncluded.entrySet();
  785. assertFalse(keySet.isEmpty());
  786. assertEquals(9, keySet.size());
  787. keySet = subMap_startIncluded_endExcluded.entrySet();
  788. assertFalse(keySet.isEmpty());
  789. assertEquals(9, keySet.size());
  790. keySet = subMap_startIncluded_endIncluded.entrySet();
  791. assertFalse(keySet.isEmpty());
  792. assertEquals(10, keySet.size());
  793. }
  794. public void test_SubMap_put() {
  795. Integer value = new Integer(100);
  796. int addValue = 5;
  797. subMap_default.put(value.toString(), value + addValue);
  798. assertEquals(value + addValue, subMap_default.get(value.toString()));
  799. try {
  800. subMap_startExcluded_endExcluded.put(value.toString(), value
  801. + addValue);
  802. fail("should throw IllegalArgumentException");
  803. } catch (IllegalArgumentException e) {
  804. // Expected
  805. }
  806. try {
  807. subMap_startExcluded_endIncluded.put(value.toString(), value
  808. + addValue);
  809. fail("should throw IllegalArgumentException");
  810. } catch (IllegalArgumentException e) {
  811. // Expected
  812. }
  813. subMap_startIncluded_endExcluded
  814. .put(value.toString(), value + addValue);
  815. assertEquals(value + addValue, subMap_startIncluded_endExcluded
  816. .get(value.toString()));
  817. subMap_startIncluded_endIncluded
  818. .put(value.toString(), value + addValue);
  819. assertEquals(value + addValue, subMap_startIncluded_endIncluded
  820. .get(value.toString()));
  821. value = new Integer(109);
  822. try {
  823. subMap_default.put(value.toString(), value + addValue);
  824. fail("should throw IllegalArgumentException");
  825. } catch (IllegalArgumentException e) {
  826. // Expected
  827. }
  828. try {
  829. subMap_startExcluded_endExcluded.put(value.toString(), value
  830. + addValue);
  831. fail("should throw IllegalArgumentException");
  832. } catch (IllegalArgumentException e) {
  833. // Expected
  834. }
  835. subMap_startExcluded_endIncluded
  836. .put(value.toString(), value + addValue);
  837. assertEquals(value + addValue, subMap_startExcluded_endIncluded
  838. .get(value.toString()));
  839. try {
  840. subMap_startIncluded_endExcluded.put(value.toString(), value
  841. + addValue);
  842. fail("should throw IllegalArgumentException");
  843. } catch (IllegalArgumentException e) {
  844. // Expected
  845. }
  846. subMap_startIncluded_endIncluded
  847. .put(value.toString(), value + addValue);
  848. assertEquals(value + addValue, subMap_startIncluded_endIncluded
  849. .get(value.toString()));
  850. }
  851. public void test_SubMap_remove() {
  852. Integer value = new Integer(100);
  853. subMap_default.remove(value.toString());
  854. assertNull(subMap_default.get(value.toString()));
  855. subMap_startExcluded_endExcluded.remove(value.toString());
  856. assertNull(subMap_startExcluded_endExcluded.get(value.toString()));
  857. subMap_startExcluded_endIncluded.remove(value.toString());
  858. assertNull(subMap_startExcluded_endIncluded.get(value.toString()));
  859. subMap_startIncluded_endExcluded.remove(value.toString());
  860. assertNull(subMap_startIncluded_endExcluded.get(value.toString()));
  861. subMap_startIncluded_endIncluded.remove(value.toString());
  862. assertNull(subMap_startIncluded_endIncluded.get(value.toString()));
  863. value = new Integer(109);
  864. subMap_default.remove(value.toString());
  865. assertNull(subMap_default.get(value.toString()));
  866. subMap_startExcluded_endExcluded.remove(value.toString());
  867. assertNull(subMap_startExcluded_endExcluded.get(value.toString()));
  868. subMap_startExcluded_endIncluded.remove(value.toString());
  869. assertNull(subMap_startExcluded_endIncluded.get(value.toString()));
  870. subMap_startIncluded_endExcluded.remove(value.toString());
  871. assertNull(subMap_startIncluded_endExcluded.get(value.toString()));
  872. subMap_startIncluded_endIncluded.remove(value.toString());
  873. assertNull(subMap_startIncluded_endIncluded.get(value.toString()));
  874. }
  875. public void test_SubMap_subMap_NoComparator() {
  876. String startKey = new Integer[100].toString();
  877. String endKey = new Integer[100].toString();
  878. try {
  879. subMap_default.subMap(startKey, endKey);
  880. fail("should throw IllegalArgumentException");
  881. } catch (IllegalArgumentException e) {
  882. // Expected
  883. }
  884. try {
  885. subMap_startExcluded_endExcluded.subMap(startKey, endKey);
  886. fail("should throw IllegalArgumentException");
  887. } catch (IllegalArgumentException e) {
  888. // Expected
  889. }
  890. try {
  891. subMap_startExcluded_endIncluded.subMap(startKey, endKey);
  892. fail("should throw IllegalArgumentException");
  893. } catch (IllegalArgumentException e) {
  894. // Expected
  895. }
  896. try {
  897. subMap_startIncluded_endExcluded.subMap(startKey, endKey);
  898. fail("should throw IllegalArgumentException");
  899. } catch (IllegalArgumentException e) {
  900. // Expected
  901. }
  902. try {
  903. subMap_startIncluded_endIncluded.subMap(startKey, endKey);
  904. fail("should throw IllegalArgumentException");
  905. } catch (IllegalArgumentException e) {
  906. // Expected
  907. }
  908. SortedMap subSubMap = null;
  909. for (int i = 101; i < 109; i++) {
  910. startKey = new Integer(i).toString();
  911. endKey = startKey;
  912. subSubMap = subMap_default.subMap(startKey, endKey);
  913. assertEquals(0, subSubMap.size());
  914. subSubMap = subMap_startExcluded_endExcluded.subMap(startKey,
  915. endKey);
  916. assertEquals(0, subSubMap.size());
  917. subSubMap = subMap_startExcluded_endIncluded.subMap(startKey,
  918. endKey);
  919. assertEquals(0, subSubMap.size());
  920. subSubMap = subMap_startIncluded_endExcluded.subMap(startKey,
  921. endKey);
  922. assertEquals(0, subSubMap.size());
  923. subSubMap = subMap_startIncluded_endIncluded.subMap(startKey,
  924. endKey);
  925. assertEquals(0, subSubMap.size());
  926. }
  927. for (int i = 101, j = 5; i < 105; i++) {
  928. startKey = new Integer(i).toString();
  929. endKey = new Integer(i + j).toString();
  930. subSubMap = subMap_default.subMap(startKey, endKey);
  931. assertEquals(j, subSubMap.size());
  932. subSubMap = subMap_startExcluded_endExcluded.subMap(startKey,
  933. endKey);
  934. assertEquals(j, subSubMap.size());
  935. subSubMap = subMap_startExcluded_endIncluded.subMap(startKey,
  936. endKey);
  937. assertEquals(j, subSubMap.size());
  938. subSubMap = subMap_startIncluded_endExcluded.subMap(startKey,
  939. endKey);
  940. assertEquals(j, subSubMap.size());
  941. subSubMap = subMap_startIncluded_endIncluded.subMap(startKey,
  942. endKey);
  943. assertEquals(j, subSubMap.size());
  944. }
  945. startKey = new Integer(108).toString();
  946. endKey = new Integer(109).toString();
  947. subSubMap = subMap_default.subMap(startKey, endKey);
  948. assertEquals(1, subSubMap.size());
  949. subSubMap = subMap_startExcluded_endExcluded.subMap(startKey, endKey);
  950. assertEquals(1, subSubMap.size());
  951. subSubMap = subMap_startExcluded_endIncluded.subMap(startKey, endKey);
  952. assertEquals(1, subSubMap.size());
  953. subSubMap = subMap_startIncluded_endExcluded.subMap(startKey, endKey);
  954. assertEquals(1, subSubMap.size());
  955. subSubMap = subMap_startIncluded_endIncluded.subMap(startKey, endKey);
  956. assertEquals(1, subSubMap.size());
  957. startKey = new Integer(109).toString();
  958. endKey = new Integer(109).toString();
  959. try {
  960. subMap_default.subMap(startKey, endKey);
  961. fail("should throw IllegalArgumentException");
  962. } catch (IllegalArgumentException e) {
  963. // Expected
  964. }
  965. try {
  966. subMap_startExcluded_endExcluded.subMap(startKey, endKey);
  967. fail("should throw IllegalArgumentException");
  968. } catch (IllegalArgumentException e) {
  969. // Expected
  970. }
  971. subSubMap = subMap_startExcluded_endIncluded.subMap(startKey, endKey);
  972. assertEquals(0, subSubMap.size());
  973. try {
  974. subMap_startIncluded_endExcluded.subMap(startKey, endKey);
  975. fail("should throw IllegalArgumentException");
  976. } catch (IllegalArgumentException e) {
  977. // Expected
  978. }
  979. subSubMap = subMap_startIncluded_endIncluded.subMap(startKey, endKey);
  980. assertEquals(0, subSubMap.size());
  981. }
  982. public void test_SubMap_subMap_Comparator() {
  983. String startKey = new Integer[100].toString();
  984. String endKey = new Integer[100].toString();
  985. try {
  986. subMap_default_comparator.subMap(startKey, endKey);
  987. fail("should throw IllegalArgumentException");
  988. } catch (IllegalArgumentException e) {
  989. // Expected
  990. }
  991. try {
  992. subMap_startExcluded_endExcluded_comparator
  993. .subMap(startKey, endKey);
  994. fail("should throw IllegalArgumentException");
  995. } catch (IllegalArgumentException e) {
  996. // Expected
  997. }
  998. try {
  999. subMap_startExcluded_endIncluded_comparator
  1000. .subMap(startKey, endKey);
  1001. fail("should throw IllegalArgumentException");
  1002. } catch (IllegalArgumentException e) {
  1003. // Expected
  1004. }
  1005. try {
  1006. subMap_startIncluded_endExcluded_comparator
  1007. .subMap(startKey, endKey);
  1008. fail("should throw IllegalArgumentException");
  1009. } catch (IllegalArgumentException e) {
  1010. // Expected
  1011. }
  1012. try {
  1013. subMap_startIncluded_endIncluded_comparator
  1014. .subMap(startKey, endKey);
  1015. fail("should throw IllegalArgumentException");
  1016. } catch (IllegalArgumentException e) {
  1017. // Expected
  1018. }
  1019. SortedMap subSubMap = null;
  1020. for (int i = 101; i < 109; i++) {
  1021. startKey = new Integer(i).toString();
  1022. endKey = startKey;
  1023. subSubMap = subMap_default_comparator.subMap(startKey, endKey);
  1024. assertEquals(0, subSubMap.size());
  1025. subSubMap = subMap_startExcluded_endExcluded_comparator.subMap(
  1026. startKey, endKey);
  1027. assertEquals(0, subSubMap.size());
  1028. subSubMap = subMap_startExcluded_endIncluded_comparator.subMap(
  1029. startKey, endKey);
  1030. assertEquals(0, subSubMap.size());
  1031. subSubMap = subMap_startIncluded_endExcluded_comparator.subMap(
  1032. startKey, endKey);
  1033. assertEquals(0, subSubMap.size());
  1034. subSubMap = subMap_startIncluded_endIncluded_comparator.subMap(
  1035. startKey, endKey);
  1036. assertEquals(0, subSubMap.size());
  1037. }
  1038. for (int i = 101, j = 5; i < 105; i++) {
  1039. startKey = new Integer(i).toString();
  1040. endKey = new Integer(i + j).toString();
  1041. subSubMap = subMap_default_comparator.subMap(startKey, endKey);
  1042. assertEquals(j, subSubMap.size());
  1043. subSubMap = subMap_startExcluded_endExcluded_comparator.subMap(
  1044. startKey, endKey);
  1045. assertEquals(j, subSubMap.size());
  1046. subSubMap = subMap_startExcluded_endIncluded_comparator.subMap(
  1047. startKey, endKey);
  1048. assertEquals(j, subSubMap.size());
  1049. subSubMap = subMap_startIncluded_endExcluded_comparator.subMap(
  1050. startKey, endKey);
  1051. assertEquals(j, subSubMap.size());
  1052. subSubMap = subMap_startIncluded_endIncluded_comparator.subMap(
  1053. startKey, endKey);
  1054. assertEquals(j, subSubMap.size());
  1055. }
  1056. startKey = new Integer(108).toString();
  1057. endKey = new Integer(109).toString();
  1058. subSubMap = subMap_default_comparator.subMap(startKey, endKey);
  1059. assertEquals(1, subSubMap.size());
  1060. subSubMap = subMap_startExcluded_endExcluded_comparator.subMap(
  1061. startKey, endKey);
  1062. assertEquals(1, subSubMap.size());
  1063. subSubMap = subMap_startExcluded_endIncluded_comparator.subMap(
  1064. startKey, endKey);
  1065. assertEquals(1, subSubMap.size());
  1066. subSubMap = subMap_startIncluded_endExcluded_comparator.subMap(
  1067. startKey, endKey);
  1068. assertEquals(1, subSubMap.size());
  1069. subSubMap = subMap_startIncluded_endIncluded_comparator.subMap(
  1070. startKey, endKey);
  1071. assertEquals(1, subSubMap.size());
  1072. startKey = new Integer(109).toString();
  1073. endKey = new Integer(109).toString();
  1074. try {
  1075. subMap_default_comparator.subMap(startKey, endKey);
  1076. fail("should throw IllegalArgumentException");
  1077. } catch (IllegalArgumentException e) {
  1078. // Expected
  1079. }
  1080. try {
  1081. subMap_startExcluded_endExcluded_comparator
  1082. .subMap(startKey, endKey);
  1083. fail("should throw IllegalArgumentException");
  1084. } catch (IllegalArgumentException e) {
  1085. // Expected
  1086. }
  1087. subSubMap = subMap_startExcluded_endIncluded_comparator.subMap(
  1088. startKey, endKey);
  1089. assertEquals(0, subSubMap.size());
  1090. try {
  1091. subMap_startIncluded_endExcluded_comparator
  1092. .subMap(startKey, endKey);
  1093. fail("should throw IllegalArgumentException");
  1094. } catch (IllegalArgumentException e) {
  1095. // Expected
  1096. }
  1097. subSubMap = subMap_startIncluded_endIncluded_comparator.subMap(
  1098. startKey, endKey);
  1099. assertEquals(0, subSubMap.size());
  1100. }
  1101. public void test_SubMap_tailMap() {
  1102. String startKey = new Integer(99).toString();
  1103. try {
  1104. subMap_default.tailMap(startKey);
  1105. fail("should throw IllegalArgumentException");