77 |
|
try { |
78 |
|
TreeSet q = new TreeSet((Collection)null); |
79 |
|
shouldThrow(); |
80 |
< |
} |
81 |
< |
catch (NullPointerException success) {} |
80 |
> |
} catch (NullPointerException success) {} |
81 |
|
} |
82 |
|
|
83 |
|
/** |
88 |
|
Integer[] ints = new Integer[SIZE]; |
89 |
|
TreeSet q = new TreeSet(Arrays.asList(ints)); |
90 |
|
shouldThrow(); |
91 |
< |
} |
93 |
< |
catch (NullPointerException success) {} |
91 |
> |
} catch (NullPointerException success) {} |
92 |
|
} |
93 |
|
|
94 |
|
/** |
101 |
|
ints[i] = new Integer(i); |
102 |
|
TreeSet q = new TreeSet(Arrays.asList(ints)); |
103 |
|
shouldThrow(); |
104 |
< |
} |
107 |
< |
catch (NullPointerException success) {} |
104 |
> |
} catch (NullPointerException success) {} |
105 |
|
} |
106 |
|
|
107 |
|
/** |
108 |
|
* Set contains all elements of collection used to initialize |
109 |
|
*/ |
110 |
|
public void testConstructor6() { |
111 |
< |
try { |
112 |
< |
Integer[] ints = new Integer[SIZE]; |
113 |
< |
for (int i = 0; i < SIZE; ++i) |
114 |
< |
ints[i] = new Integer(i); |
115 |
< |
TreeSet q = new TreeSet(Arrays.asList(ints)); |
116 |
< |
for (int i = 0; i < SIZE; ++i) |
120 |
< |
assertEquals(ints[i], q.pollFirst()); |
121 |
< |
} |
122 |
< |
finally {} |
111 |
> |
Integer[] ints = new Integer[SIZE]; |
112 |
> |
for (int i = 0; i < SIZE; ++i) |
113 |
> |
ints[i] = new Integer(i); |
114 |
> |
TreeSet q = new TreeSet(Arrays.asList(ints)); |
115 |
> |
for (int i = 0; i < SIZE; ++i) |
116 |
> |
assertEquals(ints[i], q.pollFirst()); |
117 |
|
} |
118 |
|
|
119 |
|
/** |
120 |
|
* The comparator used in constructor is used |
121 |
|
*/ |
122 |
|
public void testConstructor7() { |
123 |
< |
try { |
124 |
< |
MyReverseComparator cmp = new MyReverseComparator(); |
125 |
< |
TreeSet q = new TreeSet(cmp); |
126 |
< |
assertEquals(cmp, q.comparator()); |
127 |
< |
Integer[] ints = new Integer[SIZE]; |
128 |
< |
for (int i = 0; i < SIZE; ++i) |
129 |
< |
ints[i] = new Integer(i); |
130 |
< |
q.addAll(Arrays.asList(ints)); |
131 |
< |
for (int i = SIZE-1; i >= 0; --i) |
138 |
< |
assertEquals(ints[i], q.pollFirst()); |
139 |
< |
} |
140 |
< |
finally {} |
123 |
> |
MyReverseComparator cmp = new MyReverseComparator(); |
124 |
> |
TreeSet q = new TreeSet(cmp); |
125 |
> |
assertEquals(cmp, q.comparator()); |
126 |
> |
Integer[] ints = new Integer[SIZE]; |
127 |
> |
for (int i = 0; i < SIZE; ++i) |
128 |
> |
ints[i] = new Integer(i); |
129 |
> |
q.addAll(Arrays.asList(ints)); |
130 |
> |
for (int i = SIZE-1; i >= 0; --i) |
131 |
> |
assertEquals(ints[i], q.pollFirst()); |
132 |
|
} |
133 |
|
|
134 |
|
/** |
168 |
|
TreeSet q = populatedSet(SIZE); |
169 |
|
q.add(null); |
170 |
|
shouldThrow(); |
171 |
< |
} catch (NullPointerException success) { } |
171 |
> |
} catch (NullPointerException success) {} |
172 |
|
} |
173 |
|
|
174 |
|
/** |
199 |
|
q.add(new Object()); |
200 |
|
q.add(new Object()); |
201 |
|
shouldThrow(); |
202 |
< |
} |
212 |
< |
catch (ClassCastException success) {} |
202 |
> |
} catch (ClassCastException success) {} |
203 |
|
} |
204 |
|
|
205 |
|
/** |
210 |
|
TreeSet q = new TreeSet(); |
211 |
|
q.addAll(null); |
212 |
|
shouldThrow(); |
213 |
< |
} |
224 |
< |
catch (NullPointerException success) {} |
213 |
> |
} catch (NullPointerException success) {} |
214 |
|
} |
215 |
|
/** |
216 |
|
* addAll of a collection with null elements throws NPE |
221 |
|
Integer[] ints = new Integer[SIZE]; |
222 |
|
q.addAll(Arrays.asList(ints)); |
223 |
|
shouldThrow(); |
224 |
< |
} |
236 |
< |
catch (NullPointerException success) {} |
224 |
> |
} catch (NullPointerException success) {} |
225 |
|
} |
226 |
|
/** |
227 |
|
* addAll of a collection with any null elements throws NPE after |
235 |
|
ints[i] = new Integer(i); |
236 |
|
q.addAll(Arrays.asList(ints)); |
237 |
|
shouldThrow(); |
238 |
< |
} |
251 |
< |
catch (NullPointerException success) {} |
238 |
> |
} catch (NullPointerException success) {} |
239 |
|
} |
240 |
|
|
241 |
|
/** |
242 |
|
* Set contains all elements of successful addAll |
243 |
|
*/ |
244 |
|
public void testAddAll5() { |
245 |
< |
try { |
246 |
< |
Integer[] empty = new Integer[0]; |
247 |
< |
Integer[] ints = new Integer[SIZE]; |
248 |
< |
for (int i = 0; i < SIZE; ++i) |
249 |
< |
ints[i] = new Integer(SIZE-1-i); |
250 |
< |
TreeSet q = new TreeSet(); |
251 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
252 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
253 |
< |
for (int i = 0; i < SIZE; ++i) |
267 |
< |
assertEquals(new Integer(i), q.pollFirst()); |
268 |
< |
} |
269 |
< |
finally {} |
245 |
> |
Integer[] empty = new Integer[0]; |
246 |
> |
Integer[] ints = new Integer[SIZE]; |
247 |
> |
for (int i = 0; i < SIZE; ++i) |
248 |
> |
ints[i] = new Integer(SIZE-1-i); |
249 |
> |
TreeSet q = new TreeSet(); |
250 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
251 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
252 |
> |
for (int i = 0; i < SIZE; ++i) |
253 |
> |
assertEquals(new Integer(i), q.pollFirst()); |
254 |
|
} |
255 |
|
|
256 |
|
/** |
529 |
|
/** |
530 |
|
* A deserialized serialized set has same elements |
531 |
|
*/ |
532 |
< |
public void testSerialization() { |
532 |
> |
public void testSerialization() throws Exception { |
533 |
|
TreeSet q = populatedSet(SIZE); |
534 |
< |
try { |
535 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
536 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
537 |
< |
out.writeObject(q); |
538 |
< |
out.close(); |
539 |
< |
|
540 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
541 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
542 |
< |
TreeSet r = (TreeSet)in.readObject(); |
543 |
< |
assertEquals(q.size(), r.size()); |
544 |
< |
while (!q.isEmpty()) |
561 |
< |
assertEquals(q.pollFirst(), r.pollFirst()); |
562 |
< |
} catch (Exception e) { |
563 |
< |
e.printStackTrace(); |
564 |
< |
unexpectedException(); |
565 |
< |
} |
534 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
535 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
536 |
> |
out.writeObject(q); |
537 |
> |
out.close(); |
538 |
> |
|
539 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
540 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
541 |
> |
TreeSet r = (TreeSet)in.readObject(); |
542 |
> |
assertEquals(q.size(), r.size()); |
543 |
> |
while (!q.isEmpty()) |
544 |
> |
assertEquals(q.pollFirst(), r.pollFirst()); |
545 |
|
} |
546 |
|
|
547 |
|
/** |
669 |
|
/** |
670 |
|
* Subsets of subsets subdivide correctly |
671 |
|
*/ |
672 |
< |
public void testRecursiveSubSets() { |
672 |
> |
public void testRecursiveSubSets() throws Exception { |
673 |
|
int setSize = 1000; |
674 |
|
Class cl = TreeSet.class; |
675 |
|
|
688 |
|
0, setSize - 1, true); |
689 |
|
} |
690 |
|
|
691 |
< |
static NavigableSet<Integer> newSet(Class cl) { |
692 |
< |
NavigableSet<Integer> result = null; |
714 |
< |
try { |
715 |
< |
result = (NavigableSet<Integer>) cl.newInstance(); |
716 |
< |
} catch (Exception e) { |
717 |
< |
fail(); |
718 |
< |
} |
691 |
> |
static NavigableSet<Integer> newSet(Class cl) throws Exception { |
692 |
> |
NavigableSet<Integer> result = (NavigableSet<Integer>) cl.newInstance(); |
693 |
|
assertEquals(result.size(), 0); |
694 |
|
assertFalse(result.iterator().hasNext()); |
695 |
|
return result; |
752 |
|
} else { |
753 |
|
try { |
754 |
|
set.add(element); |
755 |
< |
fail(); |
756 |
< |
} catch (IllegalArgumentException e) { |
783 |
< |
// expected |
784 |
< |
} |
755 |
> |
shouldThrow(); |
756 |
> |
} catch (IllegalArgumentException success) {} |
757 |
|
} |
758 |
|
} |
759 |
|
} |
952 |
|
assertEq(rs.last(), -1); |
953 |
|
try { |
954 |
|
set.first(); |
955 |
< |
fail(); |
956 |
< |
} catch (NoSuchElementException e) { |
985 |
< |
// expected |
986 |
< |
} |
955 |
> |
shouldThrow(); |
956 |
> |
} catch (NoSuchElementException success) {} |
957 |
|
try { |
958 |
|
set.last(); |
959 |
< |
fail(); |
960 |
< |
} catch (NoSuchElementException e) { |
991 |
< |
// expected |
992 |
< |
} |
959 |
> |
shouldThrow(); |
960 |
> |
} catch (NoSuchElementException success) {} |
961 |
|
} |
962 |
|
} |
963 |
|
|