EnumSetTest.java revision 72e7c5a8d32494c81206971d4c1077e3f2b88f00
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package tests.api.java.util;
18
19import dalvik.annotation.TestTargetNew;
20import dalvik.annotation.TestTargets;
21import dalvik.annotation.TestLevel;
22import dalvik.annotation.TestTargetClass;
23
24import java.util.ArrayList;
25import java.util.Collection;
26import java.util.EnumSet;
27import java.util.Iterator;
28import java.util.NoSuchElementException;
29import java.util.Set;
30
31import junit.framework.TestCase;
32
33import org.apache.harmony.testframework.serialization.SerializationTest;
34
35@TestTargetClass(EnumSet.class)
36public class EnumSetTest extends TestCase {
37    static final boolean disableRIBugs = true;
38
39    static enum EnumWithInnerClass {
40        a, b, c, d, e, f {
41        },
42    }
43
44    enum EnumWithAllInnerClass {
45        a {},
46        b {},
47    }
48
49    static enum EnumFoo {
50        a, b,c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, ll,
51    }
52
53    static enum EmptyEnum {
54        // expected
55    }
56
57    static enum HugeEnumWithInnerClass {
58        a{}, b{}, c{}, d{}, e{}, f{}, g{}, h{}, i{}, j{}, k{}, l{}, m{}, n{}, o{}, p{}, q{}, r{}, s{}, t{}, u{}, v{}, w{}, x{}, y{}, z{}, A{}, B{}, C{}, D{}, E{}, F{}, G{}, H{}, I{}, J{}, K{}, L{}, M{}, N{}, O{}, P{}, Q{}, R{}, S{}, T{}, U{}, V{}, W{}, X{}, Y{}, Z{}, aa{}, bb{}, cc{}, dd{}, ee{}, ff{}, gg{}, hh{}, ii{}, jj{}, kk{}, ll{}, mm{},
59    }
60
61    static enum HugeEnum {
62        a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, ll, mm,
63    }
64
65    static enum HugeEnumCount {
66        NO1, NO2, NO3, NO4, NO5, NO6, NO7, NO8, NO9, NO10, NO11, NO12, NO13, NO14, NO15, NO16, NO17, NO18, NO19, NO20,
67        NO21, NO22, NO23, NO24, NO25, NO26, NO27, NO28, NO29, NO30, NO31, NO32, NO33, NO34, NO35, NO36, NO37, NO38, NO39, NO40,
68        NO41, NO42, NO43, NO44, NO45, NO46, NO47, NO48, NO49, NO50, NO51, NO52, NO53, NO54, NO55, NO56, NO57, NO58, NO59, NO60,
69        NO61, NO62, NO63, NO64, NO65, NO66, NO67, NO68, NO69, NO70, NO71, NO72, NO73, NO74, NO75, NO76, NO77, NO78, NO79, NO80,
70        NO81, NO82, NO83, NO84, NO85, NO86, NO87, NO88, NO89, NO90, NO91, NO92, NO93, NO94, NO95, NO96, NO97, NO98, NO99, NO100,
71        NO101, NO102, NO103, NO104, NO105, NO106, NO107, NO108, NO109, NO110, NO111, NO112, NO113, NO114, NO115, NO116, NO117, NO118, NO119, NO120,
72        NO121, NO122, NO123, NO124, NO125, NO126, NO127, NO128, NO129, NO130,
73    }
74
75    /**
76     * @tests java.util.EnumSet#noneOf(java.lang.Class)
77     */
78    @TestTargetNew(
79        level = TestLevel.COMPLETE,
80        notes = "",
81        method = "noneOf",
82        args = {java.lang.Class.class}
83    )
84    @SuppressWarnings("unchecked")
85    public void test_NoneOf_LClass() {
86        try {
87            EnumSet.noneOf((Class) null);
88            fail("Should throw NullPointerException"); //$NON-NLS-1$
89        } catch (NullPointerException e) {
90            // expected
91        }
92
93        try {
94            EnumSet.noneOf(Enum.class);
95            fail("Should throw ClassCastException"); //$NON-NLS-1$
96        } catch (ClassCastException cce) {
97            // expected
98        }
99
100        Class<EnumWithAllInnerClass> c = (Class<EnumWithAllInnerClass>) EnumWithAllInnerClass.a
101                .getClass();
102        try {
103            EnumSet.noneOf(c);
104            fail("Should throw ClassCastException"); //$NON-NLS-1$
105        } catch (ClassCastException e) {
106            // expected
107        }
108
109        EnumSet<EnumWithAllInnerClass> setWithInnerClass = EnumSet
110                .noneOf(EnumWithAllInnerClass.class);
111        assertNotNull(setWithInnerClass);
112
113        // test enum type with more than 64 elements
114        Class<HugeEnumWithInnerClass> hc = (Class<HugeEnumWithInnerClass>) HugeEnumWithInnerClass.a
115            .getClass();
116        try {
117            EnumSet.noneOf(hc);
118            fail("Should throw ClassCastException"); //$NON-NLS-1$
119        } catch (ClassCastException e) {
120            // expected
121        }
122
123        EnumSet<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
124            .noneOf(HugeEnumWithInnerClass.class);
125        assertNotNull(hugeSetWithInnerClass);
126    }
127
128    /**
129     * @tests java.util.HugeEnumSet#iterator()
130     */
131    public void test_iterator_HugeEnumSet() {
132        EnumSet<HugeEnumCount> set;
133        Object[] array;
134
135        // Test HugeEnumSet with 65 elements
136        // which is more than the bits of Long
137        set = EnumSet.range(HugeEnumCount.NO1, HugeEnumCount.NO65);
138        array = set.toArray();
139        for (HugeEnumCount count : set) {
140            assertEquals(count, (HugeEnumCount) array[count.ordinal()]);
141        }
142
143        // Test HugeEnumSet with 130 elements
144        // which is more than twice of the bits of Long
145        set = EnumSet.range(HugeEnumCount.NO1, HugeEnumCount.NO130);
146        array = set.toArray();
147        for (HugeEnumCount count : set) {
148            assertEquals(count, (HugeEnumCount) array[count.ordinal()]);
149        }
150    }
151
152    public void testRemoveIteratorRemoveFromHugeEnumSet() {
153        EnumSet<HugeEnumCount> set = EnumSet.noneOf(HugeEnumCount.class);
154        set.add(HugeEnumCount.NO64);
155        set.add(HugeEnumCount.NO65);
156        set.add(HugeEnumCount.NO128);
157        Iterator<HugeEnumCount> iterator = set.iterator();
158        assertTrue(iterator.hasNext());
159        assertEquals(HugeEnumCount.NO64, iterator.next());
160        assertTrue(iterator.hasNext());
161        iterator.remove();
162        assertEquals(HugeEnumCount.NO65, iterator.next());
163        assertTrue(iterator.hasNext());
164        assertEquals(HugeEnumCount.NO128, iterator.next());
165        assertFalse(iterator.hasNext());
166        assertEquals(EnumSet.of(HugeEnumCount.NO65, HugeEnumCount.NO128), set);
167        iterator.remove();
168        assertEquals(EnumSet.of(HugeEnumCount.NO65), set);
169    }
170
171    /**
172     * @tests java.util.EnumSet#allOf(java.lang.Class)
173     */
174    @TestTargetNew(
175        level = TestLevel.COMPLETE,
176        notes = "",
177        method = "allOf",
178        args = {java.lang.Class.class}
179    )
180    @SuppressWarnings("unchecked")
181    public void test_AllOf_LClass() {
182        try {
183            EnumSet.allOf((Class) null);
184            fail("Should throw NullPointerException"); //$NON-NLS-1$
185        } catch (NullPointerException e) {
186            // expected
187        }
188
189        try {
190            EnumSet.allOf(Enum.class);
191            fail("Should throw ClassCastException"); //$NON-NLS-1$
192        } catch (ClassCastException cce) {
193            // expected
194        }
195
196        EnumSet<EnumFoo> enumSet = EnumSet.allOf(EnumFoo.class);
197        assertEquals("Size of enumSet should be 64", 64, enumSet.size()); //$NON-NLS-1$
198
199        assertFalse(
200                "enumSet should not contain null value", enumSet.contains(null)); //$NON-NLS-1$
201        assertTrue(
202                "enumSet should contain EnumFoo.a", enumSet.contains(EnumFoo.a)); //$NON-NLS-1$
203        assertTrue(
204                "enumSet should contain EnumFoo.b", enumSet.contains(EnumFoo.b)); //$NON-NLS-1$
205
206        enumSet.add(EnumFoo.a);
207        assertEquals("Should be equal", 64, enumSet.size()); //$NON-NLS-1$
208
209        EnumSet<EnumFoo> anotherSet = EnumSet.allOf(EnumFoo.class);
210        assertEquals("Should be equal", enumSet, anotherSet); //$NON-NLS-1$
211        assertNotSame("Should not be identical", enumSet, anotherSet); //$NON-NLS-1$
212
213        // test enum with more than 64 elements
214        EnumSet<HugeEnum> hugeEnumSet = EnumSet.allOf(HugeEnum.class);
215        assertEquals(65, hugeEnumSet.size());
216
217        assertFalse(hugeEnumSet.contains(null));
218        assertTrue(hugeEnumSet.contains(HugeEnum.a));
219        assertTrue(hugeEnumSet.contains(HugeEnum.b));
220
221        hugeEnumSet.add(HugeEnum.a);
222        assertEquals(65, hugeEnumSet.size());
223
224        EnumSet<HugeEnum> anotherHugeSet = EnumSet.allOf(HugeEnum.class);
225        assertEquals(hugeEnumSet, anotherHugeSet);
226        assertNotSame(hugeEnumSet, anotherHugeSet);
227
228    }
229
230    /**
231     * @tests java.util.EnumSet#add(E)
232     */
233    @TestTargetNew(
234        level = TestLevel.COMPLETE,
235        notes = "",
236        method = "add",
237        args = {java.lang.Object.class}
238    )
239    @SuppressWarnings("unchecked")
240    public void test_add_E() {
241        Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
242        set.add(EnumFoo.a);
243        set.add(EnumFoo.b);
244
245        try {
246            set.add(null);
247            fail("Should throw NullPointerException"); //$NON-NLS-1$
248        } catch (NullPointerException e) {
249            // expected
250        }
251
252        // test enum type with more than 64 elements
253        Set rawSet = set;
254        try {
255            rawSet.add(HugeEnumWithInnerClass.b);
256            fail("Should throw ClassCastException"); //$NON-NLS-1$
257        } catch (ClassCastException e) {
258            // expected
259        }
260
261        set.clear();
262        try {
263            set.add(null);
264            fail("Should throw NullPointerException"); //$NON-NLS-1$
265        } catch (NullPointerException e) {
266            // expected
267        }
268
269        boolean result = set.add(EnumFoo.a);
270        assertEquals("Size should be 1:", 1, set.size()); //$NON-NLS-1$
271        assertTrue("Return value should be true", result); //$NON-NLS-1$
272
273        result = set.add(EnumFoo.a);
274        assertEquals("Size should be 1:", 1, set.size()); //$NON-NLS-1$
275        assertFalse("Return value should be false", result); //$NON-NLS-1$
276
277        set.add(EnumFoo.b);
278        assertEquals("Size should be 2:", 2, set.size()); //$NON-NLS-1$
279
280        rawSet = set;
281        try {
282            rawSet.add(EnumWithAllInnerClass.a);
283            fail("Should throw ClassCastException"); //$NON-NLS-1$
284        } catch(ClassCastException e) {
285            // expected
286        }
287
288        try {
289            rawSet.add(EnumWithInnerClass.a);
290            fail("Should throw ClassCastException"); //$NON-NLS-1$
291        } catch(ClassCastException e) {
292            // expected
293        }
294
295        try {
296            rawSet.add(new Object());
297            fail("Should throw ClassCastException"); //$NON-NLS-1$
298        } catch(ClassCastException e) {
299            // expected
300        }
301
302        // test enum type with more than 64 elements
303        Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
304        result = hugeSet.add(HugeEnum.a);
305        assertTrue(result);
306
307        result = hugeSet.add(HugeEnum.a);
308        assertFalse(result);
309
310        try {
311            hugeSet.add(null);
312            fail("Should throw NullPointerException"); //$NON-NLS-1$
313        } catch (NullPointerException e) {
314            // expected
315        }
316
317        rawSet = hugeSet;
318        try {
319            rawSet.add(HugeEnumWithInnerClass.b);
320            fail("Should throw ClassCastException"); //$NON-NLS-1$
321        } catch (ClassCastException e) {
322            // expected
323        }
324
325        try {
326            rawSet.add(new Object());
327            fail("Should throw ClassCastException"); //$NON-NLS-1$
328        } catch (ClassCastException e) {
329            // expected
330        }
331
332        result = hugeSet.add(HugeEnum.mm);
333        assertTrue(result);
334        result = hugeSet.add(HugeEnum.mm);
335        assertFalse(result);
336        assertEquals(2, hugeSet.size());
337
338    }
339
340    /**
341     * @tests java.util.EnumSet#addAll(Collection)
342     */
343    @TestTargetNew(
344        level = TestLevel.COMPLETE,
345        notes = "",
346        method = "addAll",
347        args = {java.util.Collection.class}
348    )
349    @SuppressWarnings( { "unchecked", "boxing" })
350    public void test_addAll_LCollection() {
351
352        Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
353        assertEquals("Size should be 0:", 0, set.size()); //$NON-NLS-1$
354
355        try {
356            set.addAll(null);
357            fail("Should throw NullPointerException"); //$NON-NLS-1$
358        } catch (NullPointerException e) {
359            // expected
360        }
361
362        Set emptySet = EnumSet.noneOf(EmptyEnum.class);
363        Enum[] elements = EmptyEnum.class.getEnumConstants();
364        for(int i = 0; i < elements.length; i++) {
365            emptySet.add(elements[i]);
366        }
367        boolean result = set.addAll(emptySet);
368        assertFalse(result);
369
370        Collection<EnumFoo> collection = new ArrayList<EnumFoo>();
371        collection.add(EnumFoo.a);
372        collection.add(EnumFoo.b);
373        result = set.addAll(collection);
374        assertTrue("addAll should be successful", result); //$NON-NLS-1$
375        assertEquals("Size should be 2:", 2, set.size()); //$NON-NLS-1$
376
377        set = EnumSet.noneOf(EnumFoo.class);
378
379        Collection rawCollection = new ArrayList<Integer>();
380        result = set.addAll(rawCollection);
381        assertFalse(result);
382        rawCollection.add(1);
383        try {
384            set.addAll(rawCollection);
385            fail("Should throw ClassCastException"); //$NON-NLS-1$
386        } catch (ClassCastException e) {
387            // expected
388        }
389
390        Set<EnumFoo> fullSet = EnumSet.noneOf(EnumFoo.class);
391        fullSet.add(EnumFoo.a);
392        fullSet.add(EnumFoo.b);
393        result = set.addAll(fullSet);
394        assertTrue("addAll should be successful", result); //$NON-NLS-1$
395        assertEquals("Size of set should be 2", 2, set.size()); //$NON-NLS-1$
396
397        try {
398            fullSet.addAll(null);
399            fail("Should throw NullPointerException"); //$NON-NLS-1$
400        } catch (NullPointerException e) {
401            // expected
402        }
403
404        Set fullSetWithSubclass = EnumSet.noneOf(EnumWithInnerClass.class);
405        elements = EnumWithInnerClass.class.getEnumConstants();
406        for(int i = 0; i < elements.length; i++) {
407            fullSetWithSubclass.add(elements[i]);
408        }
409        try {
410            set.addAll(fullSetWithSubclass);
411            fail("Should throw ClassCastException"); //$NON-NLS-1$
412        } catch (ClassCastException e) {
413            // expected
414        }
415        Set<EnumWithInnerClass> setWithSubclass = fullSetWithSubclass;
416        result = setWithSubclass.addAll(setWithSubclass);
417        assertFalse("Should return false", result); //$NON-NLS-1$
418
419        Set<EnumWithInnerClass> anotherSetWithSubclass = EnumSet
420                .noneOf(EnumWithInnerClass.class);
421        elements = EnumWithInnerClass.class.getEnumConstants();
422        for(int i = 0; i < elements.length; i++) {
423            anotherSetWithSubclass.add((EnumWithInnerClass) elements[i]);
424        }
425        result = setWithSubclass.addAll(anotherSetWithSubclass);
426        assertFalse("Should return false", result); //$NON-NLS-1$
427
428        anotherSetWithSubclass.remove(EnumWithInnerClass.a);
429        result = setWithSubclass.addAll(anotherSetWithSubclass);
430        assertFalse("Should return false", result); //$NON-NLS-1$
431
432        // test enum type with more than 64 elements
433        Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
434        assertEquals(0, hugeSet.size());
435
436        try {
437            hugeSet.addAll(null);
438            fail("Should throw NullPointerException"); //$NON-NLS-1$
439        } catch (NullPointerException e) {
440            // expected
441        }
442
443        hugeSet = EnumSet.allOf(HugeEnum.class);
444        result = hugeSet.addAll(hugeSet);
445        assertFalse(result);
446
447        hugeSet = EnumSet.noneOf(HugeEnum.class);
448        Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
449        hugeCollection.add(HugeEnum.a);
450        hugeCollection.add(HugeEnum.b);
451        result = hugeSet.addAll(hugeCollection);
452        assertTrue(result);
453        assertEquals(2, set.size());
454
455        hugeSet = EnumSet.noneOf(HugeEnum.class);
456
457        rawCollection = new ArrayList<Integer>();
458        result = hugeSet.addAll(rawCollection);
459        assertFalse(result);
460        rawCollection.add(1);
461        try {
462            hugeSet.addAll(rawCollection);
463            fail("Should throw ClassCastException"); //$NON-NLS-1$
464        } catch (ClassCastException e) {
465            // expected
466        }
467
468        EnumSet<HugeEnum> aHugeSet = EnumSet.noneOf(HugeEnum.class);
469        aHugeSet.add(HugeEnum.a);
470        aHugeSet.add(HugeEnum.b);
471        result = hugeSet.addAll(aHugeSet);
472        assertTrue(result);
473        assertEquals(2, hugeSet.size());
474
475        try {
476            aHugeSet.addAll(null);
477            fail("Should throw NullPointerException"); //$NON-NLS-1$
478        } catch (NullPointerException e) {
479            // expected
480        }
481
482        Set hugeSetWithSubclass = EnumSet.allOf(HugeEnumWithInnerClass.class);
483        try {
484            hugeSet.addAll(hugeSetWithSubclass);
485            fail("Should throw ClassCastException"); //$NON-NLS-1$
486        } catch (ClassCastException e) {
487            // expected
488        }
489        Set<HugeEnumWithInnerClass> hugeSetWithInnerSubclass = hugeSetWithSubclass;
490        result = hugeSetWithInnerSubclass.addAll(hugeSetWithInnerSubclass);
491        assertFalse(result);
492
493        Set<HugeEnumWithInnerClass> anotherHugeSetWithSubclass = EnumSet
494                .allOf(HugeEnumWithInnerClass.class);
495        result = hugeSetWithSubclass.addAll(anotherHugeSetWithSubclass);
496        assertFalse(result);
497
498        anotherHugeSetWithSubclass.remove(HugeEnumWithInnerClass.a);
499        result = setWithSubclass.addAll(anotherSetWithSubclass);
500        assertFalse(result);
501
502    }
503
504    /**
505     * @tests java.util.EnumSet#remove(Object)
506     */
507    @TestTargetNew(
508        level = TestLevel.PARTIAL_COMPLETE,
509        notes = "Doesn't verify exceptions.",
510        method = "remove",
511        args = {java.lang.Object.class}
512    )
513    public void test_remove_LOject() {
514        Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
515        Enum[] elements = EnumFoo.class.getEnumConstants();
516        for(int i = 0; i < elements.length; i++) {
517            set.add((EnumFoo) elements[i]);
518        }
519
520        boolean result = set.remove(null);
521        assertFalse("'set' does not contain null", result); //$NON-NLS-1$
522
523        result = set.remove(EnumFoo.a);
524        assertTrue("Should return true", result); //$NON-NLS-1$
525        result = set.remove(EnumFoo.a);
526        assertFalse("Should return false", result); //$NON-NLS-1$
527
528        assertEquals("Size of set should be 63:", 63, set.size()); //$NON-NLS-1$
529
530        result = set.remove(EnumWithInnerClass.a);
531        assertFalse("Should return false", result); //$NON-NLS-1$
532        result = set.remove(EnumWithInnerClass.f);
533        assertFalse("Should return false", result); //$NON-NLS-1$
534
535        // test enum with more than 64 elements
536        Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
537
538        result = hugeSet.remove(null);
539        assertFalse("'set' does not contain null", result); //$NON-NLS-1$
540
541        result = hugeSet.remove(HugeEnum.a);
542        assertTrue("Should return true", result); //$NON-NLS-1$
543        result = hugeSet.remove(HugeEnum.a);
544        assertFalse("Should return false", result); //$NON-NLS-1$
545
546        assertEquals("Size of set should be 64:", 64, hugeSet.size()); //$NON-NLS-1$
547
548        result = hugeSet.remove(HugeEnumWithInnerClass.a);
549        assertFalse("Should return false", result); //$NON-NLS-1$
550        result = hugeSet.remove(HugeEnumWithInnerClass.f);
551        assertFalse("Should return false", result); //$NON-NLS-1$
552    }
553
554    /**
555     * @tests java.util.EnumSet#equals(Object)
556     */
557    @TestTargetNew(
558        level = TestLevel.COMPLETE,
559        notes = "",
560        method = "equals",
561        args = {java.lang.Object.class}
562    )
563    public void test_equals_LObject() {
564        Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
565        Enum[] elements = EnumFoo.class.getEnumConstants();
566        for(int i = 0; i < elements.length; i++) {
567            set.add((EnumFoo) elements[i]);
568        }
569
570        assertFalse("Should return false", set.equals(null)); //$NON-NLS-1$
571        assertFalse(
572                "Should return false", set.equals(new Object())); //$NON-NLS-1$
573
574        Set<EnumFoo> anotherSet = EnumSet.noneOf(EnumFoo.class);
575        elements = EnumFoo.class.getEnumConstants();
576        for(int i = 0; i < elements.length; i++) {
577            anotherSet.add((EnumFoo) elements[i]);
578        }
579        assertTrue("Should return true", set.equals(anotherSet)); //$NON-NLS-1$
580
581        anotherSet.remove(EnumFoo.a);
582        assertFalse(
583                "Should return false", set.equals(anotherSet)); //$NON-NLS-1$
584
585        Set<EnumWithInnerClass> setWithInnerClass = EnumSet
586                .noneOf(EnumWithInnerClass.class);
587        elements = EnumWithInnerClass.class.getEnumConstants();
588        for(int i = 0; i < elements.length; i++) {
589            setWithInnerClass.add((EnumWithInnerClass) elements[i]);
590        }
591
592        assertFalse(
593                "Should return false", set.equals(setWithInnerClass)); //$NON-NLS-1$
594
595        setWithInnerClass.clear();
596        set.clear();
597        assertTrue("Should be equal", set.equals(setWithInnerClass)); //$NON-NLS-1$
598
599        // test enum type with more than 64 elements
600        Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
601        assertTrue(hugeSet.equals(set));
602
603        hugeSet = EnumSet.allOf(HugeEnum.class);
604        assertFalse(hugeSet.equals(null));
605        assertFalse(hugeSet.equals(new Object()));
606
607        Set<HugeEnum> anotherHugeSet = EnumSet.allOf(HugeEnum.class);
608        anotherHugeSet.remove(HugeEnum.a);
609        assertFalse(hugeSet.equals(anotherHugeSet));
610
611        Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
612                .allOf(HugeEnumWithInnerClass.class);
613        assertFalse(hugeSet.equals(hugeSetWithInnerClass));
614        hugeSetWithInnerClass.clear();
615        hugeSet.clear();
616        assertTrue(hugeSet.equals(hugeSetWithInnerClass));
617    }
618
619    /**
620     * @tests java.util.EnumSet#clear()
621     */
622    @TestTargetNew(
623        level = TestLevel.COMPLETE,
624        notes = "",
625        method = "clear",
626        args = {}
627    )
628    public void test_clear() {
629        Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
630        set.add(EnumFoo.a);
631        set.add(EnumFoo.b);
632        assertEquals("Size should be 2", 2, set.size()); //$NON-NLS-1$
633
634        set.clear();
635
636        assertEquals("Size should be 0", 0, set.size()); //$NON-NLS-1$
637
638        // test enum type with more than 64 elements
639        Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
640        assertEquals(65, hugeSet.size());
641
642        boolean result = hugeSet.contains(HugeEnum.aa);
643        assertTrue(result);
644
645        hugeSet.clear();
646        assertEquals(0, hugeSet.size());
647        result = hugeSet.contains(HugeEnum.aa);
648        assertFalse(result);
649    }
650
651    /**
652     * @tests java.util.EnumSet#size()
653     */
654    @TestTargetNew(
655        level = TestLevel.COMPLETE,
656        notes = "",
657        method = "size",
658        args = {}
659    )
660    public void test_size() {
661        Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
662        set.add(EnumFoo.a);
663        set.add(EnumFoo.b);
664        assertEquals("Size should be 2", 2, set.size()); //$NON-NLS-1$
665
666        // test enum type with more than 64 elements
667        Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
668        hugeSet.add(HugeEnum.a);
669        hugeSet.add(HugeEnum.bb);
670        assertEquals("Size should be 2", 2, hugeSet.size()); //$NON-NLS-1$
671    }
672
673    /**
674     * @tests java.util.EnumSet#complementOf(java.util.EnumSet)
675     */
676    @TestTargetNew(
677        level = TestLevel.COMPLETE,
678        notes = "",
679        method = "complementOf",
680        args = {java.util.EnumSet.class}
681    )
682    public void test_ComplementOf_LEnumSet() {
683
684        try {
685            EnumSet.complementOf((EnumSet<EnumFoo>) null);
686            fail("Should throw NullPointerException"); //$NON-NLS-1$
687        } catch (NullPointerException npe) {
688            // expected
689        }
690
691        EnumSet<EnumWithInnerClass> set = EnumSet
692                .noneOf(EnumWithInnerClass.class);
693        set.add(EnumWithInnerClass.d);
694        set.add(EnumWithInnerClass.e);
695        set.add(EnumWithInnerClass.f);
696
697        assertEquals("Size should be 3:", 3, set.size()); //$NON-NLS-1$
698
699        EnumSet<EnumWithInnerClass> complementOfE = EnumSet.complementOf(set);
700        assertTrue(set.contains(EnumWithInnerClass.d));
701        assertEquals(
702                "complementOfE should have size 3", 3, complementOfE.size()); //$NON-NLS-1$
703        assertTrue("complementOfE should contain EnumWithSubclass.a:", //$NON-NLS-1$
704                complementOfE.contains(EnumWithInnerClass.a));
705        assertTrue("complementOfE should contain EnumWithSubclass.b:", //$NON-NLS-1$
706                complementOfE.contains(EnumWithInnerClass.b));
707        assertTrue("complementOfE should contain EnumWithSubclass.c:", //$NON-NLS-1$
708                complementOfE.contains(EnumWithInnerClass.c));
709
710        // test enum type with more than 64 elements
711        EnumSet<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
712        assertEquals(0, hugeSet.size());
713        Set<HugeEnum> complementHugeSet = EnumSet.complementOf(hugeSet);
714        assertEquals(65, complementHugeSet.size());
715
716        hugeSet.add(HugeEnum.A);
717        hugeSet.add(HugeEnum.mm);
718        complementHugeSet = EnumSet.complementOf(hugeSet);
719        assertEquals(63, complementHugeSet.size());
720
721        try {
722            EnumSet.complementOf((EnumSet<HugeEnum>) null);
723            fail("Should throw NullPointerException"); //$NON-NLS-1$
724        } catch (NullPointerException npe) {
725            // expected
726        }
727    }
728
729    /**
730     * @tests java.util.EnumSet#contains(Object)
731     */
732    @TestTargetNew(
733        level = TestLevel.PARTIAL_COMPLETE,
734        notes = "Doesn't verify ClassCastException, and NullPointerException.",
735        method = "contains",
736        args = {java.lang.Object.class}
737    )
738    public void test_contains_LObject() {
739        Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
740        Enum[] elements = EnumFoo.class.getEnumConstants();
741        for(int i = 0; i < elements.length; i++) {
742            set.add((EnumFoo)elements[i]);
743        }
744        boolean result = set.contains(null);
745        assertFalse("Should not contain null:", result); //$NON-NLS-1$
746
747        result = set.contains(EnumFoo.a);
748        assertTrue("Should contain EnumFoo.a", result); //$NON-NLS-1$
749        result = set.contains(EnumFoo.ll);
750        assertTrue("Should contain EnumFoo.ll", result); //$NON-NLS-1$
751
752        result = set.contains(EnumFoo.b);
753        assertTrue("Should contain EnumFoo.b", result); //$NON-NLS-1$
754
755        result = set.contains(new Object());
756        assertFalse("Should not contain Object instance", result); //$NON-NLS-1$
757
758        result = set.contains(EnumWithInnerClass.a);
759        assertFalse("Should not contain EnumWithSubclass.a", result); //$NON-NLS-1$
760
761        set = EnumSet.noneOf(EnumFoo.class);
762        set.add(EnumFoo.aa);
763        set.add(EnumFoo.bb);
764        set.add(EnumFoo.cc);
765
766        assertEquals("Size of set should be 3", 3, set.size()); //$NON-NLS-1$
767        assertTrue("set should contain EnumFoo.aa", set.contains(EnumFoo.aa)); //$NON-NLS-1$
768
769        Set<EnumWithInnerClass> setWithSubclass = EnumSet
770                .noneOf(EnumWithInnerClass.class);
771        setWithSubclass.add(EnumWithInnerClass.a);
772        setWithSubclass.add(EnumWithInnerClass.b);
773        setWithSubclass.add(EnumWithInnerClass.c);
774        setWithSubclass.add(EnumWithInnerClass.d);
775        setWithSubclass.add(EnumWithInnerClass.e);
776        setWithSubclass.add(EnumWithInnerClass.f);
777        result = setWithSubclass.contains(EnumWithInnerClass.f);
778        assertTrue("Should contain EnumWithSubclass.f", result); //$NON-NLS-1$
779
780        // test enum type with more than 64 elements
781        Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
782        hugeSet.add(HugeEnum.a);
783        result = hugeSet.contains(HugeEnum.a);
784        assertTrue(result);
785
786        result = hugeSet.contains(HugeEnum.b);
787        assertTrue(result);
788
789        result = hugeSet.contains(null);
790        assertFalse(result);
791
792        result = hugeSet.contains(HugeEnum.a);
793        assertTrue(result);
794
795        result = hugeSet.contains(HugeEnum.ll);
796        assertTrue(result);
797
798        result = hugeSet.contains(new Object());
799        assertFalse(result);
800
801        result = hugeSet.contains(Enum.class);
802        assertFalse(result);
803
804    }
805
806    /**
807     * @tests java.util.EnumSet#containsAll(Collection)
808     */
809    @TestTargetNew(
810        level = TestLevel.COMPLETE,
811        notes = "",
812        method = "containsAll",
813        args = {java.util.Collection.class}
814    )
815    @SuppressWarnings( { "unchecked", "boxing" })
816    public void test_containsAll_LCollection() {
817        EnumSet<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
818        Enum[] elements = EnumFoo.class.getEnumConstants();
819        for(int i = 0; i < elements.length; i++) {
820            set.add((EnumFoo)elements[i]);
821        }
822        try {
823            set.containsAll(null);
824            fail("Should throw NullPointerException"); //$NON-NLS-1$
825        } catch (NullPointerException e) {
826            // expected
827        }
828
829        EnumSet<EmptyEnum> emptySet = EnumSet.noneOf(EmptyEnum.class);
830        elements = EmptyEnum.class.getEnumConstants();
831        for(int i = 0; i < elements.length; i++) {
832            emptySet.add((EmptyEnum)elements[i]);
833        }
834        boolean result = set.containsAll(emptySet);
835        assertTrue("Should return true", result); //$NON-NLS-1$
836
837        Collection rawCollection = new ArrayList();
838        result = set.containsAll(rawCollection);
839        assertTrue("Should contain empty collection:", result); //$NON-NLS-1$
840
841        rawCollection.add(1);
842        result = set.containsAll(rawCollection);
843        assertFalse("Should return false", result); //$NON-NLS-1$
844
845        rawCollection.add(EnumWithInnerClass.a);
846        result = set.containsAll(rawCollection);
847        assertFalse("Should return false", result); //$NON-NLS-1$
848
849        EnumSet rawSet = EnumSet.noneOf(EnumFoo.class);
850        result = set.containsAll(rawSet);
851        assertTrue("Should contain empty set", result); //$NON-NLS-1$
852
853        emptySet = EnumSet.noneOf(EmptyEnum.class);
854        result = set.containsAll(emptySet);
855        assertTrue("No class cast should be performed on empty set", result); //$NON-NLS-1$
856
857        Collection<EnumFoo> collection = new ArrayList<EnumFoo>();
858        collection.add(EnumFoo.a);
859        result = set.containsAll(collection);
860        assertTrue("Should contain all elements in collection", result); //$NON-NLS-1$
861
862        EnumSet<EnumFoo> fooSet = EnumSet.noneOf(EnumFoo.class);
863        fooSet.add(EnumFoo.a);
864        result = set.containsAll(fooSet);
865        assertTrue("Should return true", result); //$NON-NLS-1$
866
867        set.clear();
868        try {
869            set.containsAll(null);
870            fail("Should throw NullPointerException"); //$NON-NLS-1$
871        } catch (NullPointerException e) {
872            // expected
873        }
874
875        Collection<EnumWithInnerClass> collectionWithSubclass = new ArrayList<EnumWithInnerClass>();
876        collectionWithSubclass.add(EnumWithInnerClass.a);
877        result = set.containsAll(collectionWithSubclass);
878        assertFalse("Should return false", result); //$NON-NLS-1$
879
880        EnumSet<EnumWithInnerClass> setWithSubclass = EnumSet
881                .noneOf(EnumWithInnerClass.class);
882        setWithSubclass.add(EnumWithInnerClass.a);
883        result = set.containsAll(setWithSubclass);
884        assertFalse("Should return false", result); //$NON-NLS-1$
885
886        // test enum type with more than 64 elements
887        Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
888        hugeSet.add(HugeEnum.a);
889        hugeSet.add(HugeEnum.b);
890        hugeSet.add(HugeEnum.aa);
891        hugeSet.add(HugeEnum.bb);
892        hugeSet.add(HugeEnum.cc);
893        hugeSet.add(HugeEnum.dd);
894
895        Set<HugeEnum> anotherHugeSet = EnumSet.noneOf(HugeEnum.class);
896        hugeSet.add(HugeEnum.b);
897        hugeSet.add(HugeEnum.cc);
898        result = hugeSet.containsAll(anotherHugeSet);
899        assertTrue(result);
900
901        try {
902            hugeSet.containsAll(null);
903            fail("Should throw NullPointerException"); //$NON-NLS-1$
904        } catch(NullPointerException e) {
905            // expected
906        }
907
908        Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
909                .noneOf(HugeEnumWithInnerClass.class);
910        hugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
911        hugeSetWithInnerClass.add(HugeEnumWithInnerClass.b);
912        result = hugeSetWithInnerClass.containsAll(hugeSetWithInnerClass);
913        assertTrue(result);
914        result = hugeSet.containsAll(hugeSetWithInnerClass);
915        assertFalse(result);
916
917        rawCollection = new ArrayList();
918        result = hugeSet.containsAll(rawCollection);
919        assertTrue("Should contain empty collection:", result); //$NON-NLS-1$
920
921        rawCollection.add(1);
922        result = hugeSet.containsAll(rawCollection);
923        assertFalse("Should return false", result); //$NON-NLS-1$
924
925        rawCollection.add(EnumWithInnerClass.a);
926        result = set.containsAll(rawCollection);
927        assertFalse("Should return false", result); //$NON-NLS-1$
928
929        rawSet = EnumSet.noneOf(HugeEnum.class);
930        result = hugeSet.containsAll(rawSet);
931        assertTrue("Should contain empty set", result); //$NON-NLS-1$
932
933        EnumSet<HugeEnumWithInnerClass> emptyHugeSet
934            = EnumSet.noneOf(HugeEnumWithInnerClass.class);
935        result = hugeSet.containsAll(emptyHugeSet);
936        assertTrue("No class cast should be performed on empty set", result); //$NON-NLS-1$
937
938        Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
939        hugeCollection.add(HugeEnum.a);
940        result = hugeSet.containsAll(hugeCollection);
941        assertTrue("Should contain all elements in collection", result); //$NON-NLS-1$
942
943        hugeSet.clear();
944        try {
945            hugeSet.containsAll(null);
946            fail("Should throw NullPointerException"); //$NON-NLS-1$
947        } catch (NullPointerException e) {
948            // expected
949        }
950
951        Collection<HugeEnumWithInnerClass> hugeCollectionWithSubclass = new ArrayList<HugeEnumWithInnerClass>();
952        hugeCollectionWithSubclass.add(HugeEnumWithInnerClass.a);
953        result = hugeSet.containsAll(hugeCollectionWithSubclass);
954        assertFalse("Should return false", result); //$NON-NLS-1$
955
956        EnumSet<HugeEnumWithInnerClass> hugeSetWithSubclass = EnumSet
957                .noneOf(HugeEnumWithInnerClass.class);
958        hugeSetWithSubclass.add(HugeEnumWithInnerClass.a);
959        result = hugeSet.containsAll(hugeSetWithSubclass);
960        assertFalse("Should return false", result); //$NON-NLS-1$
961    }
962
963    /**
964     * @tests java.util.EnumSet#copyOf(java.util.Collection)
965     */
966    @TestTargetNew(
967        level = TestLevel.COMPLETE,
968        notes = "",
969        method = "copyOf",
970        args = {java.util.Collection.class}
971    )
972    @SuppressWarnings("unchecked")
973    public void test_CopyOf_LCollection() {
974        try {
975            EnumSet.copyOf((Collection) null);
976            fail("Should throw NullPointerException"); //$NON-NLS-1$
977        } catch (NullPointerException npe) {
978            // expected
979        }
980
981        Collection collection = new ArrayList();
982        try {
983            EnumSet.copyOf(collection);
984            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
985        } catch (IllegalArgumentException e) {
986            // expected
987        }
988
989        collection.add(new Object());
990        try {
991            EnumSet.copyOf(collection);
992            fail("Should throw ClassCastException"); //$NON-NLS-1$
993        } catch (ClassCastException e) {
994            // expected
995        }
996
997        Collection<EnumFoo> enumCollection = new ArrayList<EnumFoo>();
998        enumCollection.add(EnumFoo.b);
999
1000        EnumSet<EnumFoo> copyOfEnumCollection = EnumSet.copyOf(enumCollection);
1001        assertEquals("Size of copyOfEnumCollection should be 1:", //$NON-NLS-1$
1002                1, copyOfEnumCollection.size());
1003        assertTrue("copyOfEnumCollection should contain EnumFoo.b:", //$NON-NLS-1$
1004                copyOfEnumCollection.contains(EnumFoo.b));
1005
1006        enumCollection.add(null);
1007        assertEquals("Size of enumCollection should be 2:", //$NON-NLS-1$
1008                2, enumCollection.size());
1009
1010        try {
1011            copyOfEnumCollection = EnumSet.copyOf(enumCollection);
1012            fail("Should throw NullPointerException"); //$NON-NLS-1$
1013        } catch (NullPointerException npe) {
1014            // expected
1015        }
1016
1017        Collection rawEnumCollection = new ArrayList();
1018        rawEnumCollection.add(EnumFoo.a);
1019        rawEnumCollection.add(EnumWithInnerClass.a);
1020        try {
1021            EnumSet.copyOf(rawEnumCollection);
1022            fail("Should throw ClassCastException"); //$NON-NLS-1$
1023        } catch(ClassCastException e) {
1024            // expected
1025        }
1026
1027        // test enum type with more than 64 elements
1028        Collection<HugeEnum> hugeEnumCollection = new ArrayList<HugeEnum>();
1029        hugeEnumCollection.add(HugeEnum.b);
1030
1031        EnumSet<HugeEnum> copyOfHugeEnumCollection = EnumSet.copyOf(hugeEnumCollection);
1032        assertEquals(1, copyOfHugeEnumCollection.size());
1033        assertTrue(copyOfHugeEnumCollection.contains(HugeEnum.b));
1034
1035        hugeEnumCollection.add(null);
1036        assertEquals(2, hugeEnumCollection.size());
1037
1038        try {
1039            copyOfHugeEnumCollection = EnumSet.copyOf(hugeEnumCollection);
1040            fail("Should throw NullPointerException"); //$NON-NLS-1$
1041        } catch (NullPointerException npe) {
1042            // expected
1043        }
1044
1045        rawEnumCollection = new ArrayList();
1046        rawEnumCollection.add(HugeEnum.a);
1047        rawEnumCollection.add(HugeEnumWithInnerClass.a);
1048        try {
1049            EnumSet.copyOf(rawEnumCollection);
1050            fail("Should throw ClassCastException"); //$NON-NLS-1$
1051        } catch(ClassCastException e) {
1052            // expected
1053        }
1054    }
1055
1056    /**
1057     * @tests java.util.EnumSet#copyOf(java.util.EnumSet)
1058     */
1059    @TestTargetNew(
1060        level = TestLevel.COMPLETE,
1061        notes = "",
1062        method = "copyOf",
1063        args = {java.util.EnumSet.class}
1064    )
1065    @SuppressWarnings("unchecked")
1066    public void test_CopyOf_LEnumSet() {
1067        EnumSet<EnumWithInnerClass> enumSet = EnumSet
1068                .noneOf(EnumWithInnerClass.class);
1069        enumSet.add(EnumWithInnerClass.a);
1070        enumSet.add(EnumWithInnerClass.f);
1071        EnumSet<EnumWithInnerClass> copyOfE = EnumSet.copyOf(enumSet);
1072        assertEquals("Size of enumSet and copyOfE should be equal", //$NON-NLS-1$
1073                enumSet.size(), copyOfE.size());
1074
1075        assertTrue("EnumWithSubclass.a should be contained in copyOfE", //$NON-NLS-1$
1076                copyOfE.contains(EnumWithInnerClass.a));
1077        assertTrue("EnumWithSubclass.f should be contained in copyOfE", //$NON-NLS-1$
1078                copyOfE.contains(EnumWithInnerClass.f));
1079
1080        Object[] enumValue = copyOfE.toArray();
1081        assertSame("enumValue[0] should be identical with EnumWithSubclass.a", //$NON-NLS-1$
1082                enumValue[0], EnumWithInnerClass.a);
1083        assertSame("enumValue[1] should be identical with EnumWithSubclass.f", //$NON-NLS-1$
1084                enumValue[1], EnumWithInnerClass.f);
1085
1086        try {
1087            EnumSet.copyOf((EnumSet) null);
1088            fail("Should throw NullPointerException"); //$NON-NLS-1$
1089        } catch (NullPointerException npe) {
1090            // expected
1091        }
1092
1093        // test enum type with more than 64 elements
1094        EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet
1095            .noneOf(HugeEnumWithInnerClass.class);
1096        hugeEnumSet.add(HugeEnumWithInnerClass.a);
1097        hugeEnumSet.add(HugeEnumWithInnerClass.f);
1098        EnumSet<HugeEnumWithInnerClass> copyOfHugeEnum = EnumSet.copyOf(hugeEnumSet);
1099        assertEquals(enumSet.size(), copyOfE.size());
1100
1101        assertTrue(copyOfHugeEnum.contains(HugeEnumWithInnerClass.a));
1102        assertTrue(copyOfHugeEnum.contains(HugeEnumWithInnerClass.f));
1103
1104        Object[] hugeEnumValue = copyOfHugeEnum.toArray();
1105        assertSame(hugeEnumValue[0], HugeEnumWithInnerClass.a);
1106        assertSame(hugeEnumValue[1], HugeEnumWithInnerClass.f);
1107    }
1108
1109    /**
1110     * @tests java.util.EnumSet#removeAll(Collection)
1111     */
1112    @TestTargetNew(
1113        level = TestLevel.PARTIAL_COMPLETE,
1114        notes = "Doesn't verify UnsupportedOperationException, ClassCastException.",
1115        method = "removeAll",
1116        args = {java.util.Collection.class}
1117    )
1118    @SuppressWarnings("unchecked")
1119    public void test_removeAll_LCollection() {
1120        Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
1121        try {
1122            set.removeAll(null);
1123            fail("Should throw NullPointerException"); //$NON-NLS-1$
1124        } catch (NullPointerException e) {
1125            // expected
1126        }
1127
1128        set = EnumSet.allOf(EnumFoo.class);
1129        assertEquals("Size of set should be 64:", 64, set.size()); //$NON-NLS-1$
1130
1131        try {
1132            set.removeAll(null);
1133            fail("Should throw NullPointerException"); //$NON-NLS-1$
1134        } catch (NullPointerException e) {
1135            // expected
1136        }
1137
1138        Collection<EnumFoo> collection = new ArrayList<EnumFoo>();
1139        collection.add(EnumFoo.a);
1140
1141        boolean result = set.removeAll(collection);
1142        assertTrue("Should return true", result); //$NON-NLS-1$
1143        assertEquals("Size of set should be 63", 63, set.size()); //$NON-NLS-1$
1144
1145        collection = new ArrayList();
1146        result = set.removeAll(collection);
1147        assertFalse("Should return false", result); //$NON-NLS-1$
1148
1149        Set<EmptyEnum> emptySet = EnumSet.noneOf(EmptyEnum.class);
1150        result = set.removeAll(emptySet);
1151        assertFalse("Should return false", result); //$NON-NLS-1$
1152
1153        EnumSet<EnumFoo> emptyFooSet = EnumSet.noneOf(EnumFoo.class);
1154        result = set.removeAll(emptyFooSet);
1155        assertFalse("Should return false", result); //$NON-NLS-1$
1156
1157        emptyFooSet.add(EnumFoo.a);
1158        result = set.removeAll(emptyFooSet);
1159        assertFalse("Should return false", result); //$NON-NLS-1$
1160
1161        Set<EnumWithInnerClass> setWithSubclass = EnumSet
1162                .noneOf(EnumWithInnerClass.class);
1163        result = set.removeAll(setWithSubclass);
1164        assertFalse("Should return false", result); //$NON-NLS-1$
1165
1166        setWithSubclass.add(EnumWithInnerClass.a);
1167        result = set.removeAll(setWithSubclass);
1168        assertFalse("Should return false", result); //$NON-NLS-1$
1169
1170        Set<EnumFoo> anotherSet = EnumSet.noneOf(EnumFoo.class);
1171        anotherSet.add(EnumFoo.a);
1172
1173        set = EnumSet.allOf(EnumFoo.class);
1174        result = set.removeAll(anotherSet);
1175        assertTrue("Should return true", result); //$NON-NLS-1$
1176        assertEquals("Size of set should be 63:", 63, set.size()); //$NON-NLS-1$
1177
1178        Set<EnumWithInnerClass> setWithInnerClass = EnumSet
1179                .noneOf(EnumWithInnerClass.class);
1180        setWithInnerClass.add(EnumWithInnerClass.a);
1181        setWithInnerClass.add(EnumWithInnerClass.b);
1182
1183        Set<EnumWithInnerClass> anotherSetWithInnerClass = EnumSet
1184                .noneOf(EnumWithInnerClass.class);
1185        anotherSetWithInnerClass.add(EnumWithInnerClass.c);
1186        anotherSetWithInnerClass.add(EnumWithInnerClass.d);
1187        result = anotherSetWithInnerClass.removeAll(setWithInnerClass);
1188        assertFalse("Should return false", result); //$NON-NLS-1$
1189
1190        anotherSetWithInnerClass.add(EnumWithInnerClass.a);
1191        result = anotherSetWithInnerClass.removeAll(setWithInnerClass);
1192        assertTrue("Should return true", result); //$NON-NLS-1$
1193        assertEquals("Size of anotherSetWithInnerClass should remain 2", //$NON-NLS-1$
1194                2, anotherSetWithInnerClass.size());
1195
1196        anotherSetWithInnerClass.remove(EnumWithInnerClass.c);
1197        anotherSetWithInnerClass.remove(EnumWithInnerClass.d);
1198        result = anotherSetWithInnerClass.remove(setWithInnerClass);
1199        assertFalse("Should return false", result); //$NON-NLS-1$
1200
1201        Set rawSet = EnumSet.allOf(EnumWithAllInnerClass.class);
1202        result = rawSet.removeAll(EnumSet.allOf(EnumFoo.class));
1203        assertFalse("Should return false", result); //$NON-NLS-1$
1204
1205        setWithInnerClass = EnumSet.allOf(EnumWithInnerClass.class);
1206        anotherSetWithInnerClass = EnumSet.allOf(EnumWithInnerClass.class);
1207        setWithInnerClass.remove(EnumWithInnerClass.a);
1208        anotherSetWithInnerClass.remove(EnumWithInnerClass.f);
1209        result = setWithInnerClass.removeAll(anotherSetWithInnerClass);
1210        assertTrue("Should return true", result); //$NON-NLS-1$
1211        assertEquals("Size of setWithInnerClass should be 1", 1, setWithInnerClass.size()); //$NON-NLS-1$
1212
1213        result = setWithInnerClass.contains(EnumWithInnerClass.f);
1214        assertTrue("Should return true", result); //$NON-NLS-1$
1215
1216        // test enum type with more than 64 elements
1217        Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
1218
1219        Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
1220        hugeCollection.add(HugeEnum.a);
1221
1222        result = hugeSet.removeAll(hugeCollection);
1223        assertTrue(result);
1224        assertEquals(64, hugeSet.size());
1225
1226        collection = new ArrayList();
1227        result = hugeSet.removeAll(collection);
1228        assertFalse(result);
1229
1230        Set<HugeEnum> emptyHugeSet = EnumSet.noneOf(HugeEnum.class);
1231        result = hugeSet.removeAll(emptyHugeSet);
1232        assertFalse(result);
1233
1234        Set<HugeEnumWithInnerClass> hugeSetWithSubclass = EnumSet
1235                .noneOf(HugeEnumWithInnerClass.class);
1236        result = hugeSet.removeAll(hugeSetWithSubclass);
1237        assertFalse(result);
1238
1239        hugeSetWithSubclass.add(HugeEnumWithInnerClass.a);
1240        result = hugeSet.removeAll(hugeSetWithSubclass);
1241        assertFalse(result);
1242
1243        Set<HugeEnum> anotherHugeSet = EnumSet.noneOf(HugeEnum.class);
1244        anotherHugeSet.add(HugeEnum.a);
1245
1246        hugeSet = EnumSet.allOf(HugeEnum.class);
1247        result = hugeSet.removeAll(anotherHugeSet);
1248        assertTrue(result);
1249        assertEquals(63, set.size());
1250
1251        Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
1252                .noneOf(HugeEnumWithInnerClass.class);
1253        hugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
1254        hugeSetWithInnerClass.add(HugeEnumWithInnerClass.b);
1255
1256        Set<HugeEnumWithInnerClass> anotherHugeSetWithInnerClass = EnumSet
1257                .noneOf(HugeEnumWithInnerClass.class);
1258        anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.c);
1259        anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.d);
1260        result = anotherHugeSetWithInnerClass.removeAll(setWithInnerClass);
1261        assertFalse("Should return false", result); //$NON-NLS-1$
1262
1263        anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
1264        result = anotherHugeSetWithInnerClass.removeAll(hugeSetWithInnerClass);
1265        assertTrue(result);
1266        assertEquals(2, anotherHugeSetWithInnerClass.size());
1267
1268        anotherHugeSetWithInnerClass.remove(HugeEnumWithInnerClass.c);
1269        anotherHugeSetWithInnerClass.remove(HugeEnumWithInnerClass.d);
1270        result = anotherHugeSetWithInnerClass.remove(hugeSetWithInnerClass);
1271        assertFalse(result);
1272
1273        rawSet = EnumSet.allOf(HugeEnumWithInnerClass.class);
1274        result = rawSet.removeAll(EnumSet.allOf(HugeEnum.class));
1275        assertFalse(result);
1276
1277        hugeSetWithInnerClass = EnumSet.allOf(HugeEnumWithInnerClass.class);
1278        anotherHugeSetWithInnerClass = EnumSet.allOf(HugeEnumWithInnerClass.class);
1279        hugeSetWithInnerClass.remove(HugeEnumWithInnerClass.a);
1280        anotherHugeSetWithInnerClass.remove(HugeEnumWithInnerClass.f);
1281        result = hugeSetWithInnerClass.removeAll(anotherHugeSetWithInnerClass);
1282        assertTrue(result);
1283        assertEquals(1, hugeSetWithInnerClass.size());
1284
1285        result = hugeSetWithInnerClass.contains(HugeEnumWithInnerClass.f);
1286        assertTrue(result);
1287    }
1288
1289    /**
1290     * @tests java.util.EnumSet#retainAll(Collection)
1291     */
1292    @TestTargetNew(
1293        level = TestLevel.PARTIAL_COMPLETE,
1294        notes = "Doesn't verify UnsupportedOperationException, ClassCastException.",
1295        method = "retainAll",
1296        args = {java.util.Collection.class}
1297    )
1298    @SuppressWarnings("unchecked")
1299    public void test_retainAll_LCollection() {
1300        Set<EnumFoo> set = EnumSet.allOf(EnumFoo.class);
1301
1302        try {
1303            set.retainAll(null);
1304            fail("Should throw NullPointerException"); //$NON-NLS-1$
1305        } catch (NullPointerException e) {
1306            // expected
1307        }
1308
1309        set.clear();
1310        boolean result = set.retainAll(null);
1311        assertFalse("Should return false", result); //$NON-NLS-1$
1312
1313        Collection rawCollection = new ArrayList();
1314        result = set.retainAll(rawCollection);
1315        assertFalse("Should return false", result); //$NON-NLS-1$
1316
1317        rawCollection.add(EnumFoo.a);
1318        result = set.retainAll(rawCollection);
1319        assertFalse("Should return false", result); //$NON-NLS-1$
1320
1321        rawCollection.add(EnumWithInnerClass.a);
1322        result = set.retainAll(rawCollection);
1323        assertFalse("Should return false", result); //$NON-NLS-1$
1324        assertEquals("Size of set should be 0:", 0, set.size()); //$NON-NLS-1$
1325
1326        rawCollection.remove(EnumFoo.a);
1327        result = set.retainAll(rawCollection);
1328        assertFalse("Should return false", result); //$NON-NLS-1$
1329
1330        Set<EnumFoo> anotherSet = EnumSet.allOf(EnumFoo.class);
1331        result = set.retainAll(anotherSet);
1332        assertFalse("Should return false", result); //$NON-NLS-1$
1333        assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
1334
1335        Set<EnumWithInnerClass> setWithInnerClass = EnumSet
1336                .allOf(EnumWithInnerClass.class);
1337        result = set.retainAll(setWithInnerClass);
1338        assertFalse("Should return false", result); //$NON-NLS-1$
1339        assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
1340
1341        setWithInnerClass = EnumSet.noneOf(EnumWithInnerClass.class);
1342        result = set.retainAll(setWithInnerClass);
1343        assertFalse("Should return false", result); //$NON-NLS-1$
1344
1345        Set<EmptyEnum> emptySet = EnumSet.allOf(EmptyEnum.class);
1346        result = set.retainAll(emptySet);
1347        assertFalse("Should return false", result); //$NON-NLS-1$
1348
1349        Set<EnumWithAllInnerClass> setWithAllInnerClass = EnumSet
1350                .allOf(EnumWithAllInnerClass.class);
1351        result = set.retainAll(setWithAllInnerClass);
1352        assertFalse("Should return false", result); //$NON-NLS-1$
1353
1354        set.add(EnumFoo.a);
1355        result = set.retainAll(setWithInnerClass);
1356        assertTrue("Should return true", result); //$NON-NLS-1$
1357        assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
1358
1359        setWithInnerClass = EnumSet.allOf(EnumWithInnerClass.class);
1360        setWithInnerClass.remove(EnumWithInnerClass.f);
1361        Set<EnumWithInnerClass> anotherSetWithInnerClass = EnumSet
1362                .noneOf(EnumWithInnerClass.class);
1363        anotherSetWithInnerClass.add(EnumWithInnerClass.e);
1364        anotherSetWithInnerClass.add(EnumWithInnerClass.f);
1365
1366        result = setWithInnerClass.retainAll(anotherSetWithInnerClass);
1367        assertTrue("Should return true", result); //$NON-NLS-1$
1368        result = setWithInnerClass.contains(EnumWithInnerClass.e);
1369        assertTrue("Should contain EnumWithInnerClass.e", result); //$NON-NLS-1$
1370        result = setWithInnerClass.contains(EnumWithInnerClass.b);
1371        assertFalse("Should not contain EnumWithInnerClass.b", result); //$NON-NLS-1$
1372        assertEquals("Size of set should be 1:", 1, setWithInnerClass.size()); //$NON-NLS-1$
1373
1374        anotherSetWithInnerClass = EnumSet.allOf(EnumWithInnerClass.class);
1375        result = setWithInnerClass.retainAll(anotherSetWithInnerClass);
1376
1377        assertFalse("Return value should be false", result); //$NON-NLS-1$
1378
1379        rawCollection = new ArrayList();
1380        rawCollection.add(EnumWithInnerClass.e);
1381        rawCollection.add(EnumWithInnerClass.f);
1382        result = setWithInnerClass.retainAll(rawCollection);
1383        assertFalse("Should return false", result); //$NON-NLS-1$
1384
1385        set = EnumSet.allOf(EnumFoo.class);
1386        set.remove(EnumFoo.a);
1387        anotherSet = EnumSet.noneOf(EnumFoo.class);
1388        anotherSet.add(EnumFoo.a);
1389        result = set.retainAll(anotherSet);
1390        assertTrue("Should return true", result); //$NON-NLS-1$
1391        assertEquals("size should be 0", 0, set.size()); //$NON-NLS-1$
1392
1393        // test enum type with more than 64 elements
1394        Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
1395
1396        try {
1397            hugeSet.retainAll(null);
1398            fail("Should throw NullPointerException"); //$NON-NLS-1$
1399        } catch (NullPointerException e) {
1400            // expected
1401        }
1402
1403        hugeSet.clear();
1404        result = hugeSet.retainAll(null);
1405        assertFalse(result);
1406
1407        rawCollection = new ArrayList();
1408        result = hugeSet.retainAll(rawCollection);
1409        assertFalse(result);
1410
1411        rawCollection.add(HugeEnum.a);
1412        result = hugeSet.retainAll(rawCollection);
1413        assertFalse(result);
1414
1415        rawCollection.add(HugeEnumWithInnerClass.a);
1416        result = hugeSet.retainAll(rawCollection);
1417        assertFalse(result);
1418        assertEquals(0, set.size());
1419
1420        rawCollection.remove(HugeEnum.a);
1421        result = set.retainAll(rawCollection);
1422        assertFalse(result);
1423
1424        Set<HugeEnum> anotherHugeSet = EnumSet.allOf(HugeEnum.class);
1425        result = hugeSet.retainAll(anotherHugeSet);
1426        assertFalse(result);
1427        assertEquals(0, hugeSet.size());
1428
1429        Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
1430                .allOf(HugeEnumWithInnerClass.class);
1431        result = hugeSet.retainAll(hugeSetWithInnerClass);
1432        assertFalse(result);
1433        assertEquals(0, hugeSet.size());
1434
1435        hugeSetWithInnerClass = EnumSet.noneOf(HugeEnumWithInnerClass.class);
1436        result = hugeSet.retainAll(hugeSetWithInnerClass);
1437        assertFalse(result);
1438
1439        Set<HugeEnumWithInnerClass> hugeSetWithAllInnerClass = EnumSet
1440                .allOf(HugeEnumWithInnerClass.class);
1441        result = hugeSet.retainAll(hugeSetWithAllInnerClass);
1442        assertFalse(result);
1443
1444        hugeSet.add(HugeEnum.a);
1445        result = hugeSet.retainAll(hugeSetWithInnerClass);
1446        assertTrue(result);
1447        assertEquals(0, hugeSet.size());
1448
1449        hugeSetWithInnerClass = EnumSet.allOf(HugeEnumWithInnerClass.class);
1450        hugeSetWithInnerClass.remove(HugeEnumWithInnerClass.f);
1451        Set<HugeEnumWithInnerClass> anotherHugeSetWithInnerClass = EnumSet
1452                .noneOf(HugeEnumWithInnerClass.class);
1453        anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.e);
1454        anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.f);
1455
1456        result = hugeSetWithInnerClass.retainAll(anotherHugeSetWithInnerClass);
1457        assertTrue(result);
1458        result = hugeSetWithInnerClass.contains(HugeEnumWithInnerClass.e);
1459        assertTrue("Should contain HugeEnumWithInnerClass.e", result); //$NON-NLS-1$
1460        result = hugeSetWithInnerClass.contains(HugeEnumWithInnerClass.b);
1461        assertFalse("Should not contain HugeEnumWithInnerClass.b", result); //$NON-NLS-1$
1462        assertEquals("Size of hugeSet should be 1:", 1, hugeSetWithInnerClass.size()); //$NON-NLS-1$
1463
1464        anotherHugeSetWithInnerClass = EnumSet.allOf(HugeEnumWithInnerClass.class);
1465        result = hugeSetWithInnerClass.retainAll(anotherHugeSetWithInnerClass);
1466
1467        assertFalse("Return value should be false", result); //$NON-NLS-1$
1468
1469        rawCollection = new ArrayList();
1470        rawCollection.add(HugeEnumWithInnerClass.e);
1471        rawCollection.add(HugeEnumWithInnerClass.f);
1472        result = hugeSetWithInnerClass.retainAll(rawCollection);
1473        assertFalse(result);
1474
1475        hugeSet = EnumSet.allOf(HugeEnum.class);
1476        hugeSet.remove(HugeEnum.a);
1477        anotherHugeSet = EnumSet.noneOf(HugeEnum.class);
1478        anotherHugeSet.add(HugeEnum.a);
1479        result = hugeSet.retainAll(anotherHugeSet);
1480        assertTrue(result);
1481        assertEquals(0, hugeSet.size());
1482    }
1483
1484    /**
1485     * @tests java.util.EnumSet#iterator()
1486     */
1487    @TestTargetNew(
1488        level = TestLevel.COMPLETE,
1489        notes = "",
1490        method = "iterator",
1491        args = {}
1492    )
1493    public void test_iterator() {
1494        Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
1495        set.add(EnumFoo.a);
1496        set.add(EnumFoo.b);
1497
1498        Iterator<EnumFoo> iterator = set.iterator();
1499        Iterator<EnumFoo> anotherIterator = set.iterator();
1500        assertNotSame("Should not be same", iterator, anotherIterator); //$NON-NLS-1$
1501        try {
1502            iterator.remove();
1503            fail("Should throw IllegalStateException"); //$NON-NLS-1$
1504        } catch (IllegalStateException e) {
1505            // expectedd
1506        }
1507
1508        assertTrue("Should has next element:", iterator.hasNext()); //$NON-NLS-1$
1509        assertSame("Should be identical", EnumFoo.a, iterator.next()); //$NON-NLS-1$
1510        iterator.remove();
1511        assertTrue("Should has next element:", iterator.hasNext()); //$NON-NLS-1$
1512        assertSame("Should be identical", EnumFoo.b, iterator.next()); //$NON-NLS-1$
1513        assertFalse("Should not has next element:", iterator.hasNext()); //$NON-NLS-1$
1514        assertFalse("Should not has next element:", iterator.hasNext()); //$NON-NLS-1$
1515
1516        assertEquals("Size should be 1:", 1, set.size()); //$NON-NLS-1$
1517
1518        try {
1519            iterator.next();
1520            fail("Should throw NoSuchElementException"); //$NON-NLS-1$
1521        } catch (NoSuchElementException e) {
1522            // expected
1523        }
1524        set = EnumSet.noneOf(EnumFoo.class);
1525        set.add(EnumFoo.a);
1526        iterator = set.iterator();
1527        assertEquals("Should be equal", EnumFoo.a, iterator.next()); //$NON-NLS-1$
1528        iterator.remove();
1529        try {
1530            iterator.remove();
1531            fail("Should throw IllegalStateException"); //$NON-NLS-1$
1532        } catch(IllegalStateException e) {
1533            // expected
1534        }
1535
1536        Set<EmptyEnum> emptySet = EnumSet.allOf(EmptyEnum.class);
1537        Iterator<EmptyEnum> emptyIterator = emptySet.iterator();
1538        try {
1539            emptyIterator.next();
1540            fail("Should throw NoSuchElementException"); //$NON-NLS-1$
1541        } catch (NoSuchElementException e) {
1542            // expected
1543        }
1544
1545        Set<EnumWithInnerClass> setWithSubclass = EnumSet
1546                .allOf(EnumWithInnerClass.class);
1547        setWithSubclass.remove(EnumWithInnerClass.e);
1548        Iterator<EnumWithInnerClass> iteratorWithSubclass = setWithSubclass
1549                .iterator();
1550        assertSame("Should be same", EnumWithInnerClass.a, iteratorWithSubclass.next()); //$NON-NLS-1$
1551
1552        assertTrue("Should return true", iteratorWithSubclass.hasNext()); //$NON-NLS-1$
1553        assertSame("Should be same", EnumWithInnerClass.b, iteratorWithSubclass.next()); //$NON-NLS-1$
1554
1555        setWithSubclass.remove(EnumWithInnerClass.c);
1556        assertTrue("Should return true", iteratorWithSubclass.hasNext()); //$NON-NLS-1$
1557        assertSame("Should be same", EnumWithInnerClass.c, iteratorWithSubclass.next()); //$NON-NLS-1$
1558
1559        assertTrue("Should return true", iteratorWithSubclass.hasNext()); //$NON-NLS-1$
1560        assertSame("Should be same", EnumWithInnerClass.d, iteratorWithSubclass.next()); //$NON-NLS-1$
1561
1562        setWithSubclass.add(EnumWithInnerClass.e);
1563        assertTrue("Should return true", iteratorWithSubclass.hasNext()); //$NON-NLS-1$
1564        assertSame("Should be same", EnumWithInnerClass.f, iteratorWithSubclass.next()); //$NON-NLS-1$
1565
1566        set = EnumSet.noneOf(EnumFoo.class);
1567        iterator = set.iterator();
1568        try {
1569            iterator.next();
1570            fail("Should throw NoSuchElementException"); //$NON-NLS-1$
1571        } catch (NoSuchElementException e) {
1572            // expected
1573        }
1574
1575        set.add(EnumFoo.a);
1576        iterator = set.iterator();
1577        assertEquals("Should return EnumFoo.a", EnumFoo.a, iterator.next()); //$NON-NLS-1$
1578        assertEquals("Size of set should be 1", 1, set.size()); //$NON-NLS-1$
1579        iterator.remove();
1580        assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
1581        assertFalse("Should return false", set.contains(EnumFoo.a)); //$NON-NLS-1$
1582
1583        set.add(EnumFoo.a);
1584        set.add(EnumFoo.b);
1585        iterator = set.iterator();
1586        assertEquals("Should be equals", EnumFoo.a, iterator.next()); //$NON-NLS-1$
1587        iterator.remove();
1588        try {
1589            iterator.remove();
1590            fail("Should throw IllegalStateException"); //$NON-NLS-1$
1591        } catch(IllegalStateException e) {
1592            // expected
1593        }
1594
1595        assertTrue("Should have next element", iterator.hasNext()); //$NON-NLS-1$
1596        try {
1597            iterator.remove();
1598            fail("Should throw IllegalStateException"); //$NON-NLS-1$
1599        } catch (IllegalStateException e) {
1600            // expected
1601        }
1602        assertEquals("Size of set should be 1", 1, set.size()); //$NON-NLS-1$
1603        assertTrue("Should have next element", iterator.hasNext()); //$NON-NLS-1$
1604        assertEquals("Should return EnumFoo.b", EnumFoo.b, iterator.next()); //$NON-NLS-1$
1605        set.remove(EnumFoo.b);
1606        assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
1607        iterator.remove();
1608        assertFalse("Should return false", set.contains(EnumFoo.a)); //$NON-NLS-1$
1609
1610        // RI's bug, EnumFoo.b should not exist at the moment.
1611        if (!disableRIBugs) {
1612            assertFalse("Should return false", set.contains(EnumFoo.b)); //$NON-NLS-1$
1613        }
1614
1615        // test enum type with more than 64 elements
1616        Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
1617        hugeSet.add(HugeEnum.a);
1618        hugeSet.add(HugeEnum.b);
1619
1620        Iterator<HugeEnum> hIterator = hugeSet.iterator();
1621        Iterator<HugeEnum> anotherHugeIterator = hugeSet.iterator();
1622        assertNotSame(hIterator, anotherHugeIterator);
1623        try {
1624            hIterator.remove();
1625            fail("Should throw IllegalStateException"); //$NON-NLS-1$
1626        } catch (IllegalStateException e) {
1627            // expectedd
1628        }
1629
1630        assertTrue(hIterator.hasNext());
1631        assertSame(HugeEnum.a, hIterator.next());
1632        hIterator.remove();
1633        assertTrue(hIterator.hasNext());
1634        assertSame(HugeEnum.b, hIterator.next());
1635        assertFalse(hIterator.hasNext());
1636        assertFalse(hIterator.hasNext());
1637
1638        assertEquals(1, hugeSet.size());
1639
1640        try {
1641            hIterator.next();
1642            fail("Should throw NoSuchElementException"); //$NON-NLS-1$
1643        } catch (NoSuchElementException e) {
1644            // expected
1645        }
1646
1647        Set<HugeEnumWithInnerClass> hugeSetWithSubclass = EnumSet
1648                .allOf(HugeEnumWithInnerClass.class);
1649        hugeSetWithSubclass.remove(HugeEnumWithInnerClass.e);
1650        Iterator<HugeEnumWithInnerClass> hugeIteratorWithSubclass = hugeSetWithSubclass
1651                .iterator();
1652        assertSame(HugeEnumWithInnerClass.a, hugeIteratorWithSubclass.next());
1653
1654        assertTrue(hugeIteratorWithSubclass.hasNext());
1655        assertSame(HugeEnumWithInnerClass.b, hugeIteratorWithSubclass.next());
1656
1657        setWithSubclass.remove(HugeEnumWithInnerClass.c);
1658        assertTrue(hugeIteratorWithSubclass.hasNext());
1659        assertSame(HugeEnumWithInnerClass.c, hugeIteratorWithSubclass.next());
1660
1661        assertTrue(hugeIteratorWithSubclass.hasNext());
1662        assertSame(HugeEnumWithInnerClass.d, hugeIteratorWithSubclass.next());
1663
1664        hugeSetWithSubclass.add(HugeEnumWithInnerClass.e);
1665        assertTrue(hugeIteratorWithSubclass.hasNext());
1666        assertSame(HugeEnumWithInnerClass.f, hugeIteratorWithSubclass.next());
1667
1668        hugeSet = EnumSet.noneOf(HugeEnum.class);
1669        hIterator = hugeSet.iterator();
1670        try {
1671            hIterator.next();
1672            fail("Should throw NoSuchElementException"); //$NON-NLS-1$
1673        } catch (NoSuchElementException e) {
1674            // expected
1675        }
1676
1677        hugeSet.add(HugeEnum.a);
1678        hIterator = hugeSet.iterator();
1679        assertEquals(HugeEnum.a, hIterator.next());
1680        assertEquals(1, hugeSet.size());
1681        hIterator.remove();
1682        assertEquals(0, hugeSet.size());
1683        assertFalse(hugeSet.contains(HugeEnum.a));
1684
1685        hugeSet.add(HugeEnum.a);
1686        hugeSet.add(HugeEnum.b);
1687        hIterator = hugeSet.iterator();
1688        hIterator.next();
1689        hIterator.remove();
1690
1691        assertTrue(hIterator.hasNext());
1692        try {
1693            hIterator.remove();
1694            fail("Should throw IllegalStateException"); //$NON-NLS-1$
1695        } catch (IllegalStateException e) {
1696            // expected
1697        }
1698        assertEquals(1, hugeSet.size());
1699        assertTrue(hIterator.hasNext());
1700        assertEquals(HugeEnum.b, hIterator.next());
1701        hugeSet.remove(HugeEnum.b);
1702        assertEquals(0, hugeSet.size());
1703        hIterator.remove();
1704        assertFalse(hugeSet.contains(HugeEnum.a));
1705        // RI's bug, EnumFoo.b should not exist at the moment.
1706        if(!disableRIBugs) {
1707            assertFalse("Should return false", set.contains(EnumFoo.b)); //$NON-NLS-1$
1708        }
1709    }
1710
1711    /**
1712     * @tests java.util.EnumSet#of(E)
1713     */
1714    @TestTargetNew(
1715        level = TestLevel.COMPLETE,
1716        notes = "",
1717        method = "of",
1718        args = {java.lang.Enum.class}
1719    )
1720    public void test_Of_E() {
1721        EnumSet<EnumWithInnerClass> enumSet = EnumSet.of(EnumWithInnerClass.a);
1722        assertEquals("enumSet should have length 1:", 1, enumSet.size()); //$NON-NLS-1$
1723
1724        assertTrue("enumSet should contain EnumWithSubclass.a:", //$NON-NLS-1$
1725                enumSet.contains(EnumWithInnerClass.a));
1726
1727        try {
1728            EnumSet.of((EnumWithInnerClass) null);
1729            fail("Should throw NullPointerException"); //$NON-NLS-1$
1730        } catch (NullPointerException npe) {
1731            // expected
1732        }
1733
1734        // test enum type with more than 64 elements
1735        EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a);
1736        assertEquals(1, hugeEnumSet.size());
1737
1738        assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
1739    }
1740
1741    /**
1742     * @tests java.util.EnumSet#of(E, E)
1743     */
1744    @TestTargetNew(
1745        level = TestLevel.COMPLETE,
1746        notes = "",
1747        method = "of",
1748        args = {java.lang.Enum.class, java.lang.Enum.class}
1749    )
1750    public void test_Of_EE() {
1751        EnumSet<EnumWithInnerClass> enumSet = EnumSet.of(EnumWithInnerClass.a,
1752                EnumWithInnerClass.b);
1753        assertEquals("enumSet should have length 2:", 2, enumSet.size()); //$NON-NLS-1$
1754
1755        assertTrue("enumSet should contain EnumWithSubclass.a:", //$NON-NLS-1$
1756                enumSet.contains(EnumWithInnerClass.a));
1757        assertTrue("enumSet should contain EnumWithSubclass.b:", //$NON-NLS-1$
1758                enumSet.contains(EnumWithInnerClass.b));
1759
1760        try {
1761            EnumSet.of((EnumWithInnerClass) null, EnumWithInnerClass.a);
1762            fail("Should throw NullPointerException"); //$NON-NLS-1$
1763        } catch (NullPointerException npe) {
1764            // expected
1765        }
1766
1767        try {
1768            EnumSet.of( EnumWithInnerClass.a, (EnumWithInnerClass) null);
1769            fail("Should throw NullPointerException"); //$NON-NLS-1$
1770        } catch (NullPointerException npe) {
1771            // expected
1772        }
1773
1774        try {
1775            EnumSet.of( (EnumWithInnerClass) null, (EnumWithInnerClass) null);
1776            fail("Should throw NullPointerException"); //$NON-NLS-1$
1777        } catch (NullPointerException npe) {
1778            // expected
1779        }
1780
1781        enumSet = EnumSet.of(EnumWithInnerClass.a, EnumWithInnerClass.a);
1782        assertEquals("Size of enumSet should be 1", //$NON-NLS-1$
1783                1, enumSet.size());
1784
1785        // test enum type with more than 64 elements
1786        EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a,
1787                HugeEnumWithInnerClass.b);
1788        assertEquals(2, hugeEnumSet.size());
1789
1790        assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
1791        assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.b));
1792
1793        try {
1794            EnumSet.of((HugeEnumWithInnerClass) null, HugeEnumWithInnerClass.a);
1795            fail("Should throw NullPointerException"); //$NON-NLS-1$
1796        } catch (NullPointerException npe) {
1797            // expected
1798        }
1799
1800        try {
1801            EnumSet.of( HugeEnumWithInnerClass.a, (HugeEnumWithInnerClass) null);
1802            fail("Should throw NullPointerException"); //$NON-NLS-1$
1803        } catch (NullPointerException npe) {
1804            // expected
1805        }
1806
1807        try {
1808            EnumSet.of( (HugeEnumWithInnerClass) null, (HugeEnumWithInnerClass) null);
1809            fail("Should throw NullPointerException"); //$NON-NLS-1$
1810        } catch (NullPointerException npe) {
1811            // expected
1812        }
1813
1814        hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.a);
1815        assertEquals(1, hugeEnumSet.size());
1816    }
1817
1818    /**
1819     * @tests java.util.EnumSet#of(E, E, E)
1820     */
1821    @TestTargetNew(
1822        level = TestLevel.COMPLETE,
1823        notes = "",
1824        method = "of",
1825        args = {java.lang.Enum.class, java.lang.Enum.class, java.lang.Enum.class}
1826    )
1827    public void test_Of_EEE() {
1828        EnumSet<EnumWithInnerClass> enumSet = EnumSet.of(EnumWithInnerClass.a,
1829                EnumWithInnerClass.b, EnumWithInnerClass.c);
1830        assertEquals("Size of enumSet should be 3:", 3, enumSet.size()); //$NON-NLS-1$
1831
1832        assertTrue(
1833                "enumSet should contain EnumWithSubclass.a:", enumSet.contains(EnumWithInnerClass.a)); //$NON-NLS-1$
1834        assertTrue("Should return true", enumSet.contains(EnumWithInnerClass.c)); //$NON-NLS-1$
1835
1836        try {
1837            EnumSet.of((EnumWithInnerClass) null, null, null);
1838            fail("Should throw NullPointerException"); //$NON-NLS-1$
1839        } catch (NullPointerException npe) {
1840            // expected
1841        }
1842
1843        enumSet = EnumSet.of(EnumWithInnerClass.a, EnumWithInnerClass.b,
1844                EnumWithInnerClass.b);
1845        assertEquals("enumSet should contain 2 elements:", 2, enumSet.size()); //$NON-NLS-1$
1846
1847        // test enum type with more than 64 elements
1848        EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a,
1849                HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.c);
1850        assertEquals(3, hugeEnumSet.size());
1851
1852        assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
1853        assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.c));
1854
1855        try {
1856            EnumSet.of((HugeEnumWithInnerClass) null, null, null);
1857            fail("Should throw NullPointerException"); //$NON-NLS-1$
1858        } catch (NullPointerException npe) {
1859            // expected
1860        }
1861
1862        hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.b,
1863                HugeEnumWithInnerClass.b);
1864        assertEquals(2, hugeEnumSet.size());
1865    }
1866
1867    /**
1868     * @tests java.util.EnumSet#of(E, E, E, E)
1869     */
1870    @TestTargetNew(
1871        level = TestLevel.COMPLETE,
1872        notes = "",
1873        method = "of",
1874        args = {java.lang.Enum.class, java.lang.Enum.class, java.lang.Enum.class, java.lang.Enum.class}
1875    )
1876    public void test_Of_EEEE() {
1877        EnumSet<EnumWithInnerClass> enumSet = EnumSet.of(EnumWithInnerClass.a,
1878                EnumWithInnerClass.b, EnumWithInnerClass.c,
1879                EnumWithInnerClass.d);
1880        assertEquals("Size of enumSet should be 4", 4, enumSet.size()); //$NON-NLS-1$
1881
1882        assertTrue(
1883                "enumSet should contain EnumWithSubclass.a:", enumSet.contains(EnumWithInnerClass.a)); //$NON-NLS-1$
1884        assertTrue("enumSet should contain EnumWithSubclass.d:", enumSet //$NON-NLS-1$
1885                .contains(EnumWithInnerClass.d));
1886
1887        try {
1888            EnumSet.of((EnumWithInnerClass) null, null, null, null);
1889            fail("Should throw NullPointerException"); //$NON-NLS-1$
1890        } catch (NullPointerException npe) {
1891            // expected
1892        }
1893
1894        // test enum type with more than 64 elements
1895        EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a,
1896                HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.c,
1897                HugeEnumWithInnerClass.d);
1898        assertEquals(4, hugeEnumSet.size());
1899
1900        assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
1901        assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.d));
1902
1903        try {
1904            EnumSet.of((HugeEnumWithInnerClass) null, null, null, null);
1905            fail("Should throw NullPointerException"); //$NON-NLS-1$
1906        } catch (NullPointerException npe) {
1907            // expected
1908        }
1909    }
1910
1911    /**
1912     * @tests java.util.EnumSet#of(E, E, E, E, E)
1913     */
1914    @TestTargetNew(
1915        level = TestLevel.COMPLETE,
1916        notes = "",
1917        method = "of",
1918        args = {java.lang.Enum.class, java.lang.Enum.class, java.lang.Enum.class, java.lang.Enum.class, java.lang.Enum.class}
1919    )
1920    public void test_Of_EEEEE() {
1921        EnumSet<EnumWithInnerClass> enumSet = EnumSet.of(EnumWithInnerClass.a,
1922                EnumWithInnerClass.b, EnumWithInnerClass.c,
1923                EnumWithInnerClass.d, EnumWithInnerClass.e);
1924        assertEquals("Size of enumSet should be 5:", 5, enumSet.size()); //$NON-NLS-1$
1925
1926        assertTrue("Should return true", enumSet.contains(EnumWithInnerClass.a)); //$NON-NLS-1$
1927        assertTrue("Should return true", enumSet.contains(EnumWithInnerClass.e)); //$NON-NLS-1$
1928
1929        try {
1930            EnumSet.of((EnumWithInnerClass) null, null, null, null, null);
1931            fail("Should throw NullPointerException"); //$NON-NLS-1$
1932        } catch (NullPointerException npe) {
1933            // expected
1934        }
1935
1936        // test enum with more than 64 elements
1937        EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a,
1938                HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.c,
1939                HugeEnumWithInnerClass.d, HugeEnumWithInnerClass.e);
1940        assertEquals(5, hugeEnumSet.size());
1941
1942        assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
1943        assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.e));
1944
1945        try {
1946            EnumSet.of((HugeEnumWithInnerClass) null, null, null, null, null);
1947            fail("Should throw NullPointerException"); //$NON-NLS-1$
1948        } catch (NullPointerException npe) {
1949            // expected
1950        }
1951    }
1952
1953    /**
1954     * @tests java.util.EnumSet#of(E, E...)
1955     */
1956    @TestTargetNew(
1957        level = TestLevel.COMPLETE,
1958        notes = "",
1959        method = "of",
1960        args = {java.lang.Enum.class, java.lang.Enum[].class}
1961    )
1962    public void test_Of_EEArray() {
1963        EnumWithInnerClass[] enumArray = new EnumWithInnerClass[] {
1964                EnumWithInnerClass.b, EnumWithInnerClass.c };
1965        EnumSet<EnumWithInnerClass> enumSet = EnumSet.of(EnumWithInnerClass.a,
1966                enumArray);
1967        assertEquals("Should be equal", 3, enumSet.size()); //$NON-NLS-1$
1968
1969        assertTrue("Should return true", enumSet.contains(EnumWithInnerClass.a)); //$NON-NLS-1$
1970        assertTrue("Should return true", enumSet.contains(EnumWithInnerClass.c)); //$NON-NLS-1$
1971
1972        try {
1973            EnumSet.of(EnumWithInnerClass.a, (EnumWithInnerClass[])null);
1974            fail("Should throw NullPointerException"); //$NON-NLS-1$
1975        } catch (NullPointerException npe) {
1976            // expected
1977        }
1978
1979        EnumFoo[] foos = {EnumFoo.a, EnumFoo.c, EnumFoo.d};
1980        EnumSet<EnumFoo> set = EnumSet.of(EnumFoo.c, foos);
1981        assertEquals("size of set should be 1", 3, set.size()); //$NON-NLS-1$
1982        assertTrue("Should contain EnumFoo.a", set.contains(EnumFoo.a)); //$NON-NLS-1$
1983        assertTrue("Should contain EnumFoo.c", set.contains(EnumFoo.c)); //$NON-NLS-1$
1984        assertTrue("Should contain EnumFoo.d", set.contains(EnumFoo.d)); //$NON-NLS-1$
1985
1986        // test enum type with more than 64 elements
1987        HugeEnumWithInnerClass[] hugeEnumArray = new HugeEnumWithInnerClass[] {
1988                HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.c };
1989        EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a,
1990                hugeEnumArray);
1991        assertEquals(3, hugeEnumSet.size());
1992
1993        assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
1994        assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.c));
1995
1996        try {
1997            EnumSet.of(HugeEnumWithInnerClass.a, (HugeEnumWithInnerClass[])null);
1998            fail("Should throw NullPointerException"); //$NON-NLS-1$
1999        } catch (NullPointerException npe) {
2000            // expected
2001        }
2002
2003        HugeEnumWithInnerClass[] huges = {HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.c, HugeEnumWithInnerClass.d};
2004        EnumSet<HugeEnumWithInnerClass> hugeSet = EnumSet.of(HugeEnumWithInnerClass.c, huges);
2005        assertEquals(3, hugeSet.size());
2006        assertTrue(hugeSet.contains(HugeEnumWithInnerClass.a));
2007        assertTrue(hugeSet.contains(HugeEnumWithInnerClass.c));
2008        assertTrue(hugeSet.contains(HugeEnumWithInnerClass.d));
2009    }
2010
2011    /**
2012     * @tests java.util.EnumSet#range(E, E)
2013     */
2014    @TestTargetNew(
2015        level = TestLevel.COMPLETE,
2016        notes = "",
2017        method = "range",
2018        args = {java.lang.Enum.class, java.lang.Enum.class}
2019    )
2020    public void test_Range_EE() {
2021        try {
2022            EnumSet.range(EnumWithInnerClass.c, null);
2023            fail("Should throw NullPointerException"); //$NON-NLS-1$
2024        } catch (NullPointerException e) {
2025            // expected
2026        }
2027
2028        try {
2029            EnumSet.range(null, EnumWithInnerClass.c);
2030            fail("Should throw NullPointerException"); //$NON-NLS-1$
2031        } catch (NullPointerException e) {
2032            // expected
2033        }
2034
2035        try {
2036            EnumSet.range(null, (EnumWithInnerClass) null);
2037            fail("Should throw NullPointerException"); //$NON-NLS-1$
2038        } catch (NullPointerException e) {
2039            // expected
2040        }
2041
2042        try {
2043            EnumSet.range(EnumWithInnerClass.b, EnumWithInnerClass.a);
2044            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
2045        } catch (IllegalArgumentException e) {
2046            // expected
2047        }
2048
2049        EnumSet<EnumWithInnerClass> enumSet = EnumSet.range(
2050                EnumWithInnerClass.a, EnumWithInnerClass.a);
2051        assertEquals("Size of enumSet should be 1", 1, enumSet.size()); //$NON-NLS-1$
2052
2053        enumSet = EnumSet.range(
2054                EnumWithInnerClass.a, EnumWithInnerClass.c);
2055        assertEquals("Size of enumSet should be 3", 3, enumSet.size()); //$NON-NLS-1$
2056
2057        // test enum with more than 64 elements
2058        try {
2059            EnumSet.range(HugeEnumWithInnerClass.c, null);
2060            fail("Should throw NullPointerException"); //$NON-NLS-1$
2061        } catch (NullPointerException e) {
2062            // expected
2063        }
2064
2065        try {
2066            EnumSet.range(null, HugeEnumWithInnerClass.c);
2067            fail("Should throw NullPointerException"); //$NON-NLS-1$
2068        } catch (NullPointerException e) {
2069            // expected
2070        }
2071
2072        try {
2073            EnumSet.range(null, (HugeEnumWithInnerClass) null);
2074            fail("Should throw NullPointerException"); //$NON-NLS-1$
2075        } catch (NullPointerException e) {
2076            // expected
2077        }
2078
2079        try {
2080            EnumSet.range(HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.a);
2081            fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
2082        } catch (IllegalArgumentException e) {
2083            // expected
2084        }
2085
2086        EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.range(
2087                HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.a);
2088        assertEquals(1, hugeEnumSet.size());
2089
2090        hugeEnumSet = EnumSet.range(
2091                HugeEnumWithInnerClass.c, HugeEnumWithInnerClass.aa);
2092        assertEquals(51, hugeEnumSet.size());
2093
2094        hugeEnumSet = EnumSet.range(
2095                HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.mm);
2096        assertEquals(65, hugeEnumSet.size());
2097
2098        hugeEnumSet = EnumSet.range(
2099                HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.mm);
2100        assertEquals(64, hugeEnumSet.size());
2101    }
2102
2103    /**
2104     * @tests java.util.EnumSet#clone()
2105     */
2106    @TestTargetNew(
2107        level = TestLevel.COMPLETE,
2108        notes = "",
2109        method = "clone",
2110        args = {}
2111    )
2112    public void test_Clone() {
2113        EnumSet<EnumFoo> enumSet = EnumSet.allOf(EnumFoo.class);
2114        EnumSet<EnumFoo> clonedEnumSet = enumSet.clone();
2115        assertEquals(enumSet, clonedEnumSet);
2116        assertNotSame(enumSet, clonedEnumSet);
2117        assertTrue(clonedEnumSet.contains(EnumFoo.a));
2118        assertTrue(clonedEnumSet.contains(EnumFoo.b));
2119        assertEquals(64, clonedEnumSet.size());
2120
2121        // test enum type with more than 64 elements
2122        EnumSet<HugeEnum> hugeEnumSet = EnumSet.allOf(HugeEnum.class);
2123        EnumSet<HugeEnum> hugeClonedEnumSet = hugeEnumSet.clone();
2124        assertEquals(hugeEnumSet, hugeClonedEnumSet);
2125        assertNotSame(hugeEnumSet, hugeClonedEnumSet);
2126        assertTrue(hugeClonedEnumSet.contains(HugeEnum.a));
2127        assertTrue(hugeClonedEnumSet.contains(HugeEnum.b));
2128        assertEquals(65, hugeClonedEnumSet.size());
2129
2130        hugeClonedEnumSet.remove(HugeEnum.a);
2131        assertEquals(64, hugeClonedEnumSet.size());
2132        assertFalse(hugeClonedEnumSet.contains(HugeEnum.a));
2133        assertEquals(65, hugeEnumSet.size());
2134        assertTrue(hugeEnumSet.contains(HugeEnum.a));
2135    }
2136
2137    /**
2138     * @tests java.util.EnumSet#Serialization()
2139     */
2140    @TestTargetNew(
2141        level = TestLevel.COMPLETE,
2142        notes = "Verifies serialization/deserialization compatibility.",
2143        method = "!SerializationSelf",
2144        args = {}
2145    )
2146    public void test_serialization() throws Exception {
2147        EnumSet<EnumFoo> set = EnumSet.allOf(EnumFoo.class);
2148        SerializationTest.verifySelf(set);
2149    }
2150
2151    /**
2152     * @tests serialization/deserialization compatibility with RI.
2153     */
2154    @TestTargetNew(
2155        level = TestLevel.COMPLETE,
2156        notes = "Verifies serialization/deserialization compatibility.",
2157        method = "!SerializationGolden",
2158        args = {}
2159    )
2160    @SuppressWarnings( { "unchecked", "boxing" })
2161    public void testSerializationCompatibility() throws Exception {
2162        EnumSet<EnumFoo> set = EnumSet.allOf(EnumFoo.class);
2163        SerializationTest.verifyGolden(this, set);
2164    }
2165}
2166