Source Code Cross Referenced for EnumSetTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.luni.tests.java.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /* Licensed to the Apache Software Foundation (ASF) under one or more
0002:         * contributor license agreements.  See the NOTICE file distributed with
0003:         * this work for additional information regarding copyright ownership.
0004:         * The ASF licenses this file to You under the Apache License, Version 2.0
0005:         * (the "License"); you may not use this file except in compliance with
0006:         * the License.  You may obtain a copy of the License at
0007:         * 
0008:         *     http://www.apache.org/licenses/LICENSE-2.0
0009:         * 
0010:         * Unless required by applicable law or agreed to in writing, software
0011:         * distributed under the License is distributed on an "AS IS" BASIS,
0012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013:         * See the License for the specific language governing permissions and
0014:         * limitations under the License.
0015:         */
0016:
0017:        package org.apache.harmony.luni.tests.java.util;
0018:
0019:        import java.util.ArrayList;
0020:        import java.util.Collection;
0021:        import java.util.EnumSet;
0022:        import java.util.Iterator;
0023:        import java.util.NoSuchElementException;
0024:        import java.util.Set;
0025:
0026:        import junit.framework.TestCase;
0027:
0028:        import org.apache.harmony.testframework.serialization.SerializationTest;
0029:
0030:        public class EnumSetTest extends TestCase {
0031:
0032:            static enum EnumWithInnerClass {
0033:                a, b, c, d, e, f {
0034:                },
0035:            }
0036:
0037:            enum EnumWithAllInnerClass {
0038:                a {
0039:                },
0040:                b {
0041:                },
0042:            }
0043:
0044:            static enum EnumFoo {
0045:                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,
0046:            }
0047:
0048:            static enum EmptyEnum {
0049:                // expected
0050:            }
0051:
0052:            static enum HugeEnumWithInnerClass {
0053:                a {
0054:                },
0055:                b {
0056:                },
0057:                c {
0058:                },
0059:                d {
0060:                },
0061:                e {
0062:                },
0063:                f {
0064:                },
0065:                g {
0066:                },
0067:                h {
0068:                },
0069:                i {
0070:                },
0071:                j {
0072:                },
0073:                k {
0074:                },
0075:                l {
0076:                },
0077:                m {
0078:                },
0079:                n {
0080:                },
0081:                o {
0082:                },
0083:                p {
0084:                },
0085:                q {
0086:                },
0087:                r {
0088:                },
0089:                s {
0090:                },
0091:                t {
0092:                },
0093:                u {
0094:                },
0095:                v {
0096:                },
0097:                w {
0098:                },
0099:                x {
0100:                },
0101:                y {
0102:                },
0103:                z {
0104:                },
0105:                A {
0106:                },
0107:                B {
0108:                },
0109:                C {
0110:                },
0111:                D {
0112:                },
0113:                E {
0114:                },
0115:                F {
0116:                },
0117:                G {
0118:                },
0119:                H {
0120:                },
0121:                I {
0122:                },
0123:                J {
0124:                },
0125:                K {
0126:                },
0127:                L {
0128:                },
0129:                M {
0130:                },
0131:                N {
0132:                },
0133:                O {
0134:                },
0135:                P {
0136:                },
0137:                Q {
0138:                },
0139:                R {
0140:                },
0141:                S {
0142:                },
0143:                T {
0144:                },
0145:                U {
0146:                },
0147:                V {
0148:                },
0149:                W {
0150:                },
0151:                X {
0152:                },
0153:                Y {
0154:                },
0155:                Z {
0156:                },
0157:                aa {
0158:                },
0159:                bb {
0160:                },
0161:                cc {
0162:                },
0163:                dd {
0164:                },
0165:                ee {
0166:                },
0167:                ff {
0168:                },
0169:                gg {
0170:                },
0171:                hh {
0172:                },
0173:                ii {
0174:                },
0175:                jj {
0176:                },
0177:                kk {
0178:                },
0179:                ll {
0180:                },
0181:                mm {
0182:                },
0183:            }
0184:
0185:            static enum HugeEnum {
0186:                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,
0187:            }
0188:
0189:            /**
0190:             * @tests java.util.EnumSet#noneOf(java.lang.Class)
0191:             */
0192:            @SuppressWarnings("unchecked")
0193:            public void test_NoneOf_LClass() {
0194:                try {
0195:                    EnumSet.noneOf((Class) null);
0196:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0197:                } catch (NullPointerException e) {
0198:                    // expected
0199:                }
0200:
0201:                try {
0202:                    EnumSet.noneOf(Enum.class);
0203:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0204:                } catch (ClassCastException cce) {
0205:                    // expected
0206:                }
0207:
0208:                Class<EnumWithAllInnerClass> c = (Class<EnumWithAllInnerClass>) EnumWithAllInnerClass.a
0209:                        .getClass();
0210:                try {
0211:                    EnumSet.noneOf(c);
0212:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0213:                } catch (ClassCastException e) {
0214:                    // expected
0215:                }
0216:
0217:                EnumSet<EnumWithAllInnerClass> setWithInnerClass = EnumSet
0218:                        .noneOf(EnumWithAllInnerClass.class);
0219:                assertNotNull(setWithInnerClass);
0220:
0221:                // test enum type with more than 64 elements
0222:                Class<HugeEnumWithInnerClass> hc = (Class<HugeEnumWithInnerClass>) HugeEnumWithInnerClass.a
0223:                        .getClass();
0224:                try {
0225:                    EnumSet.noneOf(hc);
0226:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0227:                } catch (ClassCastException e) {
0228:                    // expected
0229:                }
0230:
0231:                EnumSet<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
0232:                        .noneOf(HugeEnumWithInnerClass.class);
0233:                assertNotNull(hugeSetWithInnerClass);
0234:            }
0235:
0236:            /**
0237:             * @tests java.util.EnumSet#allOf(java.lang.Class)
0238:             */
0239:            @SuppressWarnings("unchecked")
0240:            public void test_AllOf_LClass() {
0241:                try {
0242:                    EnumSet.allOf((Class) null);
0243:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0244:                } catch (NullPointerException e) {
0245:                    // expected
0246:                }
0247:
0248:                try {
0249:                    EnumSet.allOf(Enum.class);
0250:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0251:                } catch (ClassCastException cce) {
0252:                    // expected
0253:                }
0254:
0255:                EnumSet<EnumFoo> enumSet = EnumSet.allOf(EnumFoo.class);
0256:                assertEquals("Size of enumSet should be 64", 64, enumSet.size()); //$NON-NLS-1$
0257:
0258:                assertFalse(
0259:                        "enumSet should not contain null value", enumSet.contains(null)); //$NON-NLS-1$
0260:                assertTrue(
0261:                        "enumSet should contain EnumFoo.a", enumSet.contains(EnumFoo.a)); //$NON-NLS-1$
0262:                assertTrue(
0263:                        "enumSet should contain EnumFoo.b", enumSet.contains(EnumFoo.b)); //$NON-NLS-1$
0264:
0265:                enumSet.add(EnumFoo.a);
0266:                assertEquals("Should be equal", 64, enumSet.size()); //$NON-NLS-1$
0267:
0268:                EnumSet<EnumFoo> anotherSet = EnumSet.allOf(EnumFoo.class);
0269:                assertEquals("Should be equal", enumSet, anotherSet); //$NON-NLS-1$
0270:                assertNotSame("Should not be identical", enumSet, anotherSet); //$NON-NLS-1$
0271:
0272:                // test enum with more than 64 elements
0273:                EnumSet<HugeEnum> hugeEnumSet = EnumSet.allOf(HugeEnum.class);
0274:                assertEquals(65, hugeEnumSet.size());
0275:
0276:                assertFalse(hugeEnumSet.contains(null));
0277:                assertTrue(hugeEnumSet.contains(HugeEnum.a));
0278:                assertTrue(hugeEnumSet.contains(HugeEnum.b));
0279:
0280:                hugeEnumSet.add(HugeEnum.a);
0281:                assertEquals(65, hugeEnumSet.size());
0282:
0283:                EnumSet<HugeEnum> anotherHugeSet = EnumSet
0284:                        .allOf(HugeEnum.class);
0285:                assertEquals(hugeEnumSet, anotherHugeSet);
0286:                assertNotSame(hugeEnumSet, anotherHugeSet);
0287:
0288:            }
0289:
0290:            /**
0291:             * @tests java.util.EnumSet#add(E)
0292:             */
0293:            @SuppressWarnings("unchecked")
0294:            public void test_add_E() {
0295:                Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
0296:                set.add(EnumFoo.a);
0297:                set.add(EnumFoo.b);
0298:
0299:                try {
0300:                    set.add(null);
0301:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0302:                } catch (NullPointerException e) {
0303:                    // expected
0304:                }
0305:
0306:                // test enum type with more than 64 elements
0307:                Set rawSet = set;
0308:                try {
0309:                    rawSet.add(HugeEnumWithInnerClass.b);
0310:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0311:                } catch (ClassCastException e) {
0312:                    // expected
0313:                }
0314:
0315:                set.clear();
0316:                try {
0317:                    set.add(null);
0318:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0319:                } catch (NullPointerException e) {
0320:                    // expected
0321:                }
0322:
0323:                boolean result = set.add(EnumFoo.a);
0324:                assertEquals("Size should be 1:", 1, set.size()); //$NON-NLS-1$
0325:                assertTrue("Return value should be true", result); //$NON-NLS-1$
0326:
0327:                result = set.add(EnumFoo.a);
0328:                assertEquals("Size should be 1:", 1, set.size()); //$NON-NLS-1$
0329:                assertFalse("Return value should be false", result); //$NON-NLS-1$
0330:
0331:                set.add(EnumFoo.b);
0332:                assertEquals("Size should be 2:", 2, set.size()); //$NON-NLS-1$
0333:
0334:                rawSet = set;
0335:                try {
0336:                    rawSet.add(EnumWithAllInnerClass.a);
0337:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0338:                } catch (ClassCastException e) {
0339:                    // expected
0340:                }
0341:
0342:                try {
0343:                    rawSet.add(EnumWithInnerClass.a);
0344:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0345:                } catch (ClassCastException e) {
0346:                    // expected
0347:                }
0348:
0349:                try {
0350:                    rawSet.add(new Object());
0351:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0352:                } catch (ClassCastException e) {
0353:                    // expected
0354:                }
0355:
0356:                // test enum type with more than 64 elements
0357:                Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
0358:                result = hugeSet.add(HugeEnum.a);
0359:                assertTrue(result);
0360:
0361:                result = hugeSet.add(HugeEnum.a);
0362:                assertFalse(result);
0363:
0364:                try {
0365:                    hugeSet.add(null);
0366:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0367:                } catch (NullPointerException e) {
0368:                    // expected
0369:                }
0370:
0371:                rawSet = hugeSet;
0372:                try {
0373:                    rawSet.add(HugeEnumWithInnerClass.b);
0374:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0375:                } catch (ClassCastException e) {
0376:                    // expected
0377:                }
0378:
0379:                try {
0380:                    rawSet.add(new Object());
0381:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0382:                } catch (ClassCastException e) {
0383:                    // expected
0384:                }
0385:
0386:                result = hugeSet.add(HugeEnum.mm);
0387:                assertTrue(result);
0388:                result = hugeSet.add(HugeEnum.mm);
0389:                assertFalse(result);
0390:                assertEquals(2, hugeSet.size());
0391:
0392:            }
0393:
0394:            /**
0395:             * @tests java.util.EnumSet#addAll(Collection)
0396:             */
0397:            @SuppressWarnings({"unchecked","boxing"})
0398:            public void test_addAll_LCollection() {
0399:
0400:                Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
0401:                assertEquals("Size should be 0:", 0, set.size()); //$NON-NLS-1$
0402:
0403:                try {
0404:                    set.addAll(null);
0405:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0406:                } catch (NullPointerException e) {
0407:                    // expected
0408:                }
0409:
0410:                Set emptySet = EnumSet.noneOf(EmptyEnum.class);
0411:                Enum[] elements = EmptyEnum.class.getEnumConstants();
0412:                for (int i = 0; i < elements.length; i++) {
0413:                    emptySet.add(elements[i]);
0414:                }
0415:                boolean result = set.addAll(emptySet);
0416:                assertFalse(result);
0417:
0418:                Collection<EnumFoo> collection = new ArrayList<EnumFoo>();
0419:                collection.add(EnumFoo.a);
0420:                collection.add(EnumFoo.b);
0421:                result = set.addAll(collection);
0422:                assertTrue("addAll should be successful", result); //$NON-NLS-1$
0423:                assertEquals("Size should be 2:", 2, set.size()); //$NON-NLS-1$
0424:
0425:                set = EnumSet.noneOf(EnumFoo.class);
0426:
0427:                Collection rawCollection = new ArrayList<Integer>();
0428:                result = set.addAll(rawCollection);
0429:                assertFalse(result);
0430:                rawCollection.add(1);
0431:                try {
0432:                    set.addAll(rawCollection);
0433:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0434:                } catch (ClassCastException e) {
0435:                    // expected
0436:                }
0437:
0438:                Set<EnumFoo> fullSet = EnumSet.noneOf(EnumFoo.class);
0439:                fullSet.add(EnumFoo.a);
0440:                fullSet.add(EnumFoo.b);
0441:                result = set.addAll(fullSet);
0442:                assertTrue("addAll should be successful", result); //$NON-NLS-1$
0443:                assertEquals("Size of set should be 2", 2, set.size()); //$NON-NLS-1$
0444:
0445:                try {
0446:                    fullSet.addAll(null);
0447:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0448:                } catch (NullPointerException e) {
0449:                    // expected
0450:                }
0451:
0452:                Set fullSetWithSubclass = EnumSet
0453:                        .noneOf(EnumWithInnerClass.class);
0454:                elements = EnumWithInnerClass.class.getEnumConstants();
0455:                for (int i = 0; i < elements.length; i++) {
0456:                    fullSetWithSubclass.add(elements[i]);
0457:                }
0458:                try {
0459:                    set.addAll(fullSetWithSubclass);
0460:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0461:                } catch (ClassCastException e) {
0462:                    // expected
0463:                }
0464:                Set<EnumWithInnerClass> setWithSubclass = fullSetWithSubclass;
0465:                result = setWithSubclass.addAll(setWithSubclass);
0466:                assertFalse("Should return false", result); //$NON-NLS-1$
0467:
0468:                Set<EnumWithInnerClass> anotherSetWithSubclass = EnumSet
0469:                        .noneOf(EnumWithInnerClass.class);
0470:                elements = EnumWithInnerClass.class.getEnumConstants();
0471:                for (int i = 0; i < elements.length; i++) {
0472:                    anotherSetWithSubclass
0473:                            .add((EnumWithInnerClass) elements[i]);
0474:                }
0475:                result = setWithSubclass.addAll(anotherSetWithSubclass);
0476:                assertFalse("Should return false", result); //$NON-NLS-1$
0477:
0478:                anotherSetWithSubclass.remove(EnumWithInnerClass.a);
0479:                result = setWithSubclass.addAll(anotherSetWithSubclass);
0480:                assertFalse("Should return false", result); //$NON-NLS-1$
0481:
0482:                // test enum type with more than 64 elements
0483:                Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
0484:                assertEquals(0, hugeSet.size());
0485:
0486:                try {
0487:                    hugeSet.addAll(null);
0488:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0489:                } catch (NullPointerException e) {
0490:                    // expected
0491:                }
0492:
0493:                hugeSet = EnumSet.allOf(HugeEnum.class);
0494:                result = hugeSet.addAll(hugeSet);
0495:                assertFalse(result);
0496:
0497:                hugeSet = EnumSet.noneOf(HugeEnum.class);
0498:                Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
0499:                hugeCollection.add(HugeEnum.a);
0500:                hugeCollection.add(HugeEnum.b);
0501:                result = hugeSet.addAll(hugeCollection);
0502:                assertTrue(result);
0503:                assertEquals(2, set.size());
0504:
0505:                hugeSet = EnumSet.noneOf(HugeEnum.class);
0506:
0507:                rawCollection = new ArrayList<Integer>();
0508:                result = hugeSet.addAll(rawCollection);
0509:                assertFalse(result);
0510:                rawCollection.add(1);
0511:                try {
0512:                    hugeSet.addAll(rawCollection);
0513:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0514:                } catch (ClassCastException e) {
0515:                    // expected
0516:                }
0517:
0518:                EnumSet<HugeEnum> aHugeSet = EnumSet.noneOf(HugeEnum.class);
0519:                aHugeSet.add(HugeEnum.a);
0520:                aHugeSet.add(HugeEnum.b);
0521:                result = hugeSet.addAll(aHugeSet);
0522:                assertTrue(result);
0523:                assertEquals(2, hugeSet.size());
0524:
0525:                try {
0526:                    aHugeSet.addAll(null);
0527:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0528:                } catch (NullPointerException e) {
0529:                    // expected
0530:                }
0531:
0532:                Set hugeSetWithSubclass = EnumSet
0533:                        .allOf(HugeEnumWithInnerClass.class);
0534:                try {
0535:                    hugeSet.addAll(hugeSetWithSubclass);
0536:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
0537:                } catch (ClassCastException e) {
0538:                    // expected
0539:                }
0540:                Set<HugeEnumWithInnerClass> hugeSetWithInnerSubclass = hugeSetWithSubclass;
0541:                result = hugeSetWithInnerSubclass
0542:                        .addAll(hugeSetWithInnerSubclass);
0543:                assertFalse(result);
0544:
0545:                Set<HugeEnumWithInnerClass> anotherHugeSetWithSubclass = EnumSet
0546:                        .allOf(HugeEnumWithInnerClass.class);
0547:                result = hugeSetWithSubclass.addAll(anotherHugeSetWithSubclass);
0548:                assertFalse(result);
0549:
0550:                anotherHugeSetWithSubclass.remove(HugeEnumWithInnerClass.a);
0551:                result = setWithSubclass.addAll(anotherSetWithSubclass);
0552:                assertFalse(result);
0553:
0554:            }
0555:
0556:            /**
0557:             * @tests java.util.EnumSet#remove(Object)
0558:             */
0559:            public void test_remove_LObject() {
0560:                Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
0561:                Enum[] elements = EnumFoo.class.getEnumConstants();
0562:                for (int i = 0; i < elements.length; i++) {
0563:                    set.add((EnumFoo) elements[i]);
0564:                }
0565:
0566:                boolean result = set.remove(null);
0567:                assertFalse("'set' does not contain null", result); //$NON-NLS-1$
0568:
0569:                result = set.remove(EnumFoo.a);
0570:                assertTrue("Should return true", result); //$NON-NLS-1$
0571:                result = set.remove(EnumFoo.a);
0572:                assertFalse("Should return false", result); //$NON-NLS-1$
0573:
0574:                assertEquals("Size of set should be 63:", 63, set.size()); //$NON-NLS-1$
0575:
0576:                result = set.remove(EnumWithInnerClass.a);
0577:                assertFalse("Should return false", result); //$NON-NLS-1$
0578:                result = set.remove(EnumWithInnerClass.f);
0579:                assertFalse("Should return false", result); //$NON-NLS-1$
0580:
0581:                // test enum with more than 64 elements
0582:                Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
0583:
0584:                result = hugeSet.remove(null);
0585:                assertFalse("'set' does not contain null", result); //$NON-NLS-1$
0586:
0587:                result = hugeSet.remove(HugeEnum.a);
0588:                assertTrue("Should return true", result); //$NON-NLS-1$
0589:                result = hugeSet.remove(HugeEnum.a);
0590:                assertFalse("Should return false", result); //$NON-NLS-1$
0591:
0592:                assertEquals("Size of set should be 64:", 64, hugeSet.size()); //$NON-NLS-1$
0593:
0594:                result = hugeSet.remove(HugeEnumWithInnerClass.a);
0595:                assertFalse("Should return false", result); //$NON-NLS-1$
0596:                result = hugeSet.remove(HugeEnumWithInnerClass.f);
0597:                assertFalse("Should return false", result); //$NON-NLS-1$
0598:            }
0599:
0600:            /**
0601:             * @tests java.util.EnumSet#equals(Object)
0602:             */
0603:            public void test_equals_LObject() {
0604:                Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
0605:                Enum[] elements = EnumFoo.class.getEnumConstants();
0606:                for (int i = 0; i < elements.length; i++) {
0607:                    set.add((EnumFoo) elements[i]);
0608:                }
0609:
0610:                assertFalse("Should return false", set.equals(null)); //$NON-NLS-1$
0611:                assertFalse("Should return false", set.equals(new Object())); //$NON-NLS-1$
0612:
0613:                Set<EnumFoo> anotherSet = EnumSet.noneOf(EnumFoo.class);
0614:                elements = EnumFoo.class.getEnumConstants();
0615:                for (int i = 0; i < elements.length; i++) {
0616:                    anotherSet.add((EnumFoo) elements[i]);
0617:                }
0618:                assertTrue("Should return true", set.equals(anotherSet)); //$NON-NLS-1$
0619:
0620:                anotherSet.remove(EnumFoo.a);
0621:                assertFalse("Should return false", set.equals(anotherSet)); //$NON-NLS-1$
0622:
0623:                Set<EnumWithInnerClass> setWithInnerClass = EnumSet
0624:                        .noneOf(EnumWithInnerClass.class);
0625:                elements = EnumWithInnerClass.class.getEnumConstants();
0626:                for (int i = 0; i < elements.length; i++) {
0627:                    setWithInnerClass.add((EnumWithInnerClass) elements[i]);
0628:                }
0629:
0630:                assertFalse(
0631:                        "Should return false", set.equals(setWithInnerClass)); //$NON-NLS-1$
0632:
0633:                setWithInnerClass.clear();
0634:                set.clear();
0635:                assertTrue("Should be equal", set.equals(setWithInnerClass)); //$NON-NLS-1$
0636:
0637:                // test enum type with more than 64 elements
0638:                Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
0639:                assertTrue(hugeSet.equals(set));
0640:
0641:                hugeSet = EnumSet.allOf(HugeEnum.class);
0642:                assertFalse(hugeSet.equals(null));
0643:                assertFalse(hugeSet.equals(new Object()));
0644:
0645:                Set<HugeEnum> anotherHugeSet = EnumSet.allOf(HugeEnum.class);
0646:                anotherHugeSet.remove(HugeEnum.a);
0647:                assertFalse(hugeSet.equals(anotherHugeSet));
0648:
0649:                Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
0650:                        .allOf(HugeEnumWithInnerClass.class);
0651:                assertFalse(hugeSet.equals(hugeSetWithInnerClass));
0652:                hugeSetWithInnerClass.clear();
0653:                hugeSet.clear();
0654:                assertTrue(hugeSet.equals(hugeSetWithInnerClass));
0655:            }
0656:
0657:            /**
0658:             * @tests java.util.EnumSet#clear()
0659:             */
0660:            public void test_clear() {
0661:                Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
0662:                set.add(EnumFoo.a);
0663:                set.add(EnumFoo.b);
0664:                assertEquals("Size should be 2", 2, set.size()); //$NON-NLS-1$
0665:
0666:                set.clear();
0667:
0668:                assertEquals("Size should be 0", 0, set.size()); //$NON-NLS-1$
0669:
0670:                // test enum type with more than 64 elements
0671:                Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
0672:                assertEquals(65, hugeSet.size());
0673:
0674:                boolean result = hugeSet.contains(HugeEnum.aa);
0675:                assertTrue(result);
0676:
0677:                hugeSet.clear();
0678:                assertEquals(0, hugeSet.size());
0679:                result = hugeSet.contains(HugeEnum.aa);
0680:                assertFalse(result);
0681:            }
0682:
0683:            /**
0684:             * @tests java.util.EnumSet#size()
0685:             */
0686:            public void test_size() {
0687:                Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
0688:                set.add(EnumFoo.a);
0689:                set.add(EnumFoo.b);
0690:                assertEquals("Size should be 2", 2, set.size()); //$NON-NLS-1$
0691:
0692:                // test enum type with more than 64 elements
0693:                Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
0694:                hugeSet.add(HugeEnum.a);
0695:                hugeSet.add(HugeEnum.bb);
0696:                assertEquals("Size should be 2", 2, hugeSet.size()); //$NON-NLS-1$
0697:            }
0698:
0699:            /**
0700:             * @tests java.util.EnumSet#complementOf(java.util.EnumSet)
0701:             */
0702:            public void test_ComplementOf_LEnumSet() {
0703:
0704:                try {
0705:                    EnumSet.complementOf((EnumSet<EnumFoo>) null);
0706:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0707:                } catch (NullPointerException npe) {
0708:                    // expected
0709:                }
0710:
0711:                EnumSet<EnumWithInnerClass> set = EnumSet
0712:                        .noneOf(EnumWithInnerClass.class);
0713:                set.add(EnumWithInnerClass.d);
0714:                set.add(EnumWithInnerClass.e);
0715:                set.add(EnumWithInnerClass.f);
0716:
0717:                assertEquals("Size should be 3:", 3, set.size()); //$NON-NLS-1$
0718:
0719:                EnumSet<EnumWithInnerClass> complementOfE = EnumSet
0720:                        .complementOf(set);
0721:                assertTrue(set.contains(EnumWithInnerClass.d));
0722:                assertEquals(
0723:                        "complementOfE should have size 3", 3, complementOfE.size()); //$NON-NLS-1$
0724:                assertTrue("complementOfE should contain EnumWithSubclass.a:", //$NON-NLS-1$ 
0725:                        complementOfE.contains(EnumWithInnerClass.a));
0726:                assertTrue("complementOfE should contain EnumWithSubclass.b:", //$NON-NLS-1$
0727:                        complementOfE.contains(EnumWithInnerClass.b));
0728:                assertTrue("complementOfE should contain EnumWithSubclass.c:", //$NON-NLS-1$
0729:                        complementOfE.contains(EnumWithInnerClass.c));
0730:
0731:                // test enum type with more than 64 elements
0732:                EnumSet<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
0733:                assertEquals(0, hugeSet.size());
0734:                Set<HugeEnum> complementHugeSet = EnumSet.complementOf(hugeSet);
0735:                assertEquals(65, complementHugeSet.size());
0736:
0737:                hugeSet.add(HugeEnum.A);
0738:                hugeSet.add(HugeEnum.mm);
0739:                complementHugeSet = EnumSet.complementOf(hugeSet);
0740:                assertEquals(63, complementHugeSet.size());
0741:
0742:                try {
0743:                    EnumSet.complementOf((EnumSet<HugeEnum>) null);
0744:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0745:                } catch (NullPointerException npe) {
0746:                    // expected
0747:                }
0748:            }
0749:
0750:            /**
0751:             * @tests java.util.EnumSet#contains(Object)
0752:             */
0753:            public void test_contains_LObject() {
0754:                Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
0755:                Enum[] elements = EnumFoo.class.getEnumConstants();
0756:                for (int i = 0; i < elements.length; i++) {
0757:                    set.add((EnumFoo) elements[i]);
0758:                }
0759:                boolean result = set.contains(null);
0760:                assertFalse("Should not contain null:", result); //$NON-NLS-1$
0761:
0762:                result = set.contains(EnumFoo.a);
0763:                assertTrue("Should contain EnumFoo.a", result); //$NON-NLS-1$
0764:                result = set.contains(EnumFoo.ll);
0765:                assertTrue("Should contain EnumFoo.ll", result); //$NON-NLS-1$
0766:
0767:                result = set.contains(EnumFoo.b);
0768:                assertTrue("Should contain EnumFoo.b", result); //$NON-NLS-1$
0769:
0770:                result = set.contains(new Object());
0771:                assertFalse("Should not contain Object instance", result); //$NON-NLS-1$
0772:
0773:                result = set.contains(EnumWithInnerClass.a);
0774:                assertFalse("Should not contain EnumWithSubclass.a", result); //$NON-NLS-1$
0775:
0776:                set = EnumSet.noneOf(EnumFoo.class);
0777:                set.add(EnumFoo.aa);
0778:                set.add(EnumFoo.bb);
0779:                set.add(EnumFoo.cc);
0780:
0781:                assertEquals("Size of set should be 3", 3, set.size()); //$NON-NLS-1$
0782:                assertTrue(
0783:                        "set should contain EnumFoo.aa", set.contains(EnumFoo.aa)); //$NON-NLS-1$
0784:
0785:                Set<EnumWithInnerClass> setWithSubclass = EnumSet
0786:                        .noneOf(EnumWithInnerClass.class);
0787:                setWithSubclass.add(EnumWithInnerClass.a);
0788:                setWithSubclass.add(EnumWithInnerClass.b);
0789:                setWithSubclass.add(EnumWithInnerClass.c);
0790:                setWithSubclass.add(EnumWithInnerClass.d);
0791:                setWithSubclass.add(EnumWithInnerClass.e);
0792:                setWithSubclass.add(EnumWithInnerClass.f);
0793:                result = setWithSubclass.contains(EnumWithInnerClass.f);
0794:                assertTrue("Should contain EnumWithSubclass.f", result); //$NON-NLS-1$
0795:
0796:                // test enum type with more than 64 elements
0797:                Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
0798:                hugeSet.add(HugeEnum.a);
0799:                result = hugeSet.contains(HugeEnum.a);
0800:                assertTrue(result);
0801:
0802:                result = hugeSet.contains(HugeEnum.b);
0803:                assertTrue(result);
0804:
0805:                result = hugeSet.contains(null);
0806:                assertFalse(result);
0807:
0808:                result = hugeSet.contains(HugeEnum.a);
0809:                assertTrue(result);
0810:
0811:                result = hugeSet.contains(HugeEnum.ll);
0812:                assertTrue(result);
0813:
0814:                result = hugeSet.contains(new Object());
0815:                assertFalse(result);
0816:
0817:                result = hugeSet.contains(Enum.class);
0818:                assertFalse(result);
0819:
0820:            }
0821:
0822:            /**
0823:             * @tests java.util.EnumSet#containsAll(Collection)
0824:             */
0825:            @SuppressWarnings({"unchecked","boxing"})
0826:            public void test_containsAll_LCollection() {
0827:                EnumSet<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
0828:                Enum[] elements = EnumFoo.class.getEnumConstants();
0829:                for (int i = 0; i < elements.length; i++) {
0830:                    set.add((EnumFoo) elements[i]);
0831:                }
0832:                try {
0833:                    set.containsAll(null);
0834:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0835:                } catch (NullPointerException e) {
0836:                    // expected
0837:                }
0838:
0839:                EnumSet<EmptyEnum> emptySet = EnumSet.noneOf(EmptyEnum.class);
0840:                elements = EmptyEnum.class.getEnumConstants();
0841:                for (int i = 0; i < elements.length; i++) {
0842:                    emptySet.add((EmptyEnum) elements[i]);
0843:                }
0844:                boolean result = set.containsAll(emptySet);
0845:                assertTrue("Should return true", result); //$NON-NLS-1$
0846:
0847:                Collection rawCollection = new ArrayList();
0848:                result = set.containsAll(rawCollection);
0849:                assertTrue("Should contain empty collection:", result); //$NON-NLS-1$
0850:
0851:                rawCollection.add(1);
0852:                result = set.containsAll(rawCollection);
0853:                assertFalse("Should return false", result); //$NON-NLS-1$
0854:
0855:                rawCollection.add(EnumWithInnerClass.a);
0856:                result = set.containsAll(rawCollection);
0857:                assertFalse("Should return false", result); //$NON-NLS-1$
0858:
0859:                EnumSet rawSet = EnumSet.noneOf(EnumFoo.class);
0860:                result = set.containsAll(rawSet);
0861:                assertTrue("Should contain empty set", result); //$NON-NLS-1$
0862:
0863:                emptySet = EnumSet.noneOf(EmptyEnum.class);
0864:                result = set.containsAll(emptySet);
0865:                assertTrue(
0866:                        "No class cast should be performed on empty set", result); //$NON-NLS-1$
0867:
0868:                Collection<EnumFoo> collection = new ArrayList<EnumFoo>();
0869:                collection.add(EnumFoo.a);
0870:                result = set.containsAll(collection);
0871:                assertTrue("Should contain all elements in collection", result); //$NON-NLS-1$
0872:
0873:                EnumSet<EnumFoo> fooSet = EnumSet.noneOf(EnumFoo.class);
0874:                fooSet.add(EnumFoo.a);
0875:                result = set.containsAll(fooSet);
0876:                assertTrue("Should return true", result); //$NON-NLS-1$
0877:
0878:                set.clear();
0879:                try {
0880:                    set.containsAll(null);
0881:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0882:                } catch (NullPointerException e) {
0883:                    // expected
0884:                }
0885:
0886:                Collection<EnumWithInnerClass> collectionWithSubclass = new ArrayList<EnumWithInnerClass>();
0887:                collectionWithSubclass.add(EnumWithInnerClass.a);
0888:                result = set.containsAll(collectionWithSubclass);
0889:                assertFalse("Should return false", result); //$NON-NLS-1$
0890:
0891:                EnumSet<EnumWithInnerClass> setWithSubclass = EnumSet
0892:                        .noneOf(EnumWithInnerClass.class);
0893:                setWithSubclass.add(EnumWithInnerClass.a);
0894:                result = set.containsAll(setWithSubclass);
0895:                assertFalse("Should return false", result); //$NON-NLS-1$
0896:
0897:                // test enum type with more than 64 elements
0898:                Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
0899:                hugeSet.add(HugeEnum.a);
0900:                hugeSet.add(HugeEnum.b);
0901:                hugeSet.add(HugeEnum.aa);
0902:                hugeSet.add(HugeEnum.bb);
0903:                hugeSet.add(HugeEnum.cc);
0904:                hugeSet.add(HugeEnum.dd);
0905:
0906:                Set<HugeEnum> anotherHugeSet = EnumSet.noneOf(HugeEnum.class);
0907:                hugeSet.add(HugeEnum.b);
0908:                hugeSet.add(HugeEnum.cc);
0909:                result = hugeSet.containsAll(anotherHugeSet);
0910:                assertTrue(result);
0911:
0912:                try {
0913:                    hugeSet.containsAll(null);
0914:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0915:                } catch (NullPointerException e) {
0916:                    // expected
0917:                }
0918:
0919:                Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
0920:                        .noneOf(HugeEnumWithInnerClass.class);
0921:                hugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
0922:                hugeSetWithInnerClass.add(HugeEnumWithInnerClass.b);
0923:                result = hugeSetWithInnerClass
0924:                        .containsAll(hugeSetWithInnerClass);
0925:                assertTrue(result);
0926:                result = hugeSet.containsAll(hugeSetWithInnerClass);
0927:                assertFalse(result);
0928:
0929:                rawCollection = new ArrayList();
0930:                result = hugeSet.containsAll(rawCollection);
0931:                assertTrue("Should contain empty collection:", result); //$NON-NLS-1$
0932:
0933:                rawCollection.add(1);
0934:                result = hugeSet.containsAll(rawCollection);
0935:                assertFalse("Should return false", result); //$NON-NLS-1$
0936:
0937:                rawCollection.add(EnumWithInnerClass.a);
0938:                result = set.containsAll(rawCollection);
0939:                assertFalse("Should return false", result); //$NON-NLS-1$
0940:
0941:                rawSet = EnumSet.noneOf(HugeEnum.class);
0942:                result = hugeSet.containsAll(rawSet);
0943:                assertTrue("Should contain empty set", result); //$NON-NLS-1$
0944:
0945:                EnumSet<HugeEnumWithInnerClass> emptyHugeSet = EnumSet
0946:                        .noneOf(HugeEnumWithInnerClass.class);
0947:                result = hugeSet.containsAll(emptyHugeSet);
0948:                assertTrue(
0949:                        "No class cast should be performed on empty set", result); //$NON-NLS-1$
0950:
0951:                Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
0952:                hugeCollection.add(HugeEnum.a);
0953:                result = hugeSet.containsAll(hugeCollection);
0954:                assertTrue("Should contain all elements in collection", result); //$NON-NLS-1$
0955:
0956:                hugeSet.clear();
0957:                try {
0958:                    hugeSet.containsAll(null);
0959:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0960:                } catch (NullPointerException e) {
0961:                    // expected
0962:                }
0963:
0964:                Collection<HugeEnumWithInnerClass> hugeCollectionWithSubclass = new ArrayList<HugeEnumWithInnerClass>();
0965:                hugeCollectionWithSubclass.add(HugeEnumWithInnerClass.a);
0966:                result = hugeSet.containsAll(hugeCollectionWithSubclass);
0967:                assertFalse("Should return false", result); //$NON-NLS-1$
0968:
0969:                EnumSet<HugeEnumWithInnerClass> hugeSetWithSubclass = EnumSet
0970:                        .noneOf(HugeEnumWithInnerClass.class);
0971:                hugeSetWithSubclass.add(HugeEnumWithInnerClass.a);
0972:                result = hugeSet.containsAll(hugeSetWithSubclass);
0973:                assertFalse("Should return false", result); //$NON-NLS-1$
0974:            }
0975:
0976:            /**
0977:             * @tests java.util.EnumSet#copyOf(java.util.Collection)
0978:             */
0979:            @SuppressWarnings("unchecked")
0980:            public void test_CopyOf_LCollection() {
0981:                try {
0982:                    EnumSet.copyOf((Collection) null);
0983:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
0984:                } catch (NullPointerException npe) {
0985:                    // expected
0986:                }
0987:
0988:                Collection collection = new ArrayList();
0989:                try {
0990:                    EnumSet.copyOf(collection);
0991:                    fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
0992:                } catch (IllegalArgumentException e) {
0993:                    // expected
0994:                }
0995:
0996:                collection.add(new Object());
0997:                try {
0998:                    EnumSet.copyOf(collection);
0999:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
1000:                } catch (ClassCastException e) {
1001:                    // expected
1002:                }
1003:
1004:                Collection<EnumFoo> enumCollection = new ArrayList<EnumFoo>();
1005:                enumCollection.add(EnumFoo.b);
1006:
1007:                EnumSet<EnumFoo> copyOfEnumCollection = EnumSet
1008:                        .copyOf(enumCollection);
1009:                assertEquals("Size of copyOfEnumCollection should be 1:", //$NON-NLS-1$
1010:                        1, copyOfEnumCollection.size());
1011:                assertTrue("copyOfEnumCollection should contain EnumFoo.b:", //$NON-NLS-1$
1012:                        copyOfEnumCollection.contains(EnumFoo.b));
1013:
1014:                enumCollection.add(null);
1015:                assertEquals("Size of enumCollection should be 2:", //$NON-NLS-1$
1016:                        2, enumCollection.size());
1017:
1018:                try {
1019:                    copyOfEnumCollection = EnumSet.copyOf(enumCollection);
1020:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1021:                } catch (NullPointerException npe) {
1022:                    // expected
1023:                }
1024:
1025:                Collection rawEnumCollection = new ArrayList();
1026:                rawEnumCollection.add(EnumFoo.a);
1027:                rawEnumCollection.add(EnumWithInnerClass.a);
1028:                try {
1029:                    EnumSet.copyOf(rawEnumCollection);
1030:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
1031:                } catch (ClassCastException e) {
1032:                    // expected
1033:                }
1034:
1035:                // test enum type with more than 64 elements
1036:                Collection<HugeEnum> hugeEnumCollection = new ArrayList<HugeEnum>();
1037:                hugeEnumCollection.add(HugeEnum.b);
1038:
1039:                EnumSet<HugeEnum> copyOfHugeEnumCollection = EnumSet
1040:                        .copyOf(hugeEnumCollection);
1041:                assertEquals(1, copyOfHugeEnumCollection.size());
1042:                assertTrue(copyOfHugeEnumCollection.contains(HugeEnum.b));
1043:
1044:                hugeEnumCollection.add(null);
1045:                assertEquals(2, hugeEnumCollection.size());
1046:
1047:                try {
1048:                    copyOfHugeEnumCollection = EnumSet
1049:                            .copyOf(hugeEnumCollection);
1050:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1051:                } catch (NullPointerException npe) {
1052:                    // expected
1053:                }
1054:
1055:                rawEnumCollection = new ArrayList();
1056:                rawEnumCollection.add(HugeEnum.a);
1057:                rawEnumCollection.add(HugeEnumWithInnerClass.a);
1058:                try {
1059:                    EnumSet.copyOf(rawEnumCollection);
1060:                    fail("Should throw ClassCastException"); //$NON-NLS-1$
1061:                } catch (ClassCastException e) {
1062:                    // expected
1063:                }
1064:            }
1065:
1066:            /**
1067:             * @tests java.util.EnumSet#copyOf(java.util.EnumSet)
1068:             */
1069:            @SuppressWarnings("unchecked")
1070:            public void test_CopyOf_LEnumSet() {
1071:                EnumSet<EnumWithInnerClass> enumSet = EnumSet
1072:                        .noneOf(EnumWithInnerClass.class);
1073:                enumSet.add(EnumWithInnerClass.a);
1074:                enumSet.add(EnumWithInnerClass.f);
1075:                EnumSet<EnumWithInnerClass> copyOfE = EnumSet.copyOf(enumSet);
1076:                assertEquals("Size of enumSet and copyOfE should be equal", //$NON-NLS-1$
1077:                        enumSet.size(), copyOfE.size());
1078:
1079:                assertTrue("EnumWithSubclass.a should be contained in copyOfE", //$NON-NLS-1$
1080:                        copyOfE.contains(EnumWithInnerClass.a));
1081:                assertTrue("EnumWithSubclass.f should be contained in copyOfE", //$NON-NLS-1$
1082:                        copyOfE.contains(EnumWithInnerClass.f));
1083:
1084:                Object[] enumValue = copyOfE.toArray();
1085:                assertSame(
1086:                        "enumValue[0] should be identical with EnumWithSubclass.a", //$NON-NLS-1$
1087:                        enumValue[0], EnumWithInnerClass.a);
1088:                assertSame(
1089:                        "enumValue[1] should be identical with EnumWithSubclass.f", //$NON-NLS-1$
1090:                        enumValue[1], EnumWithInnerClass.f);
1091:
1092:                try {
1093:                    EnumSet.copyOf((EnumSet) null);
1094:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1095:                } catch (NullPointerException npe) {
1096:                    // expected
1097:                }
1098:
1099:                // test enum type with more than 64 elements
1100:                EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet
1101:                        .noneOf(HugeEnumWithInnerClass.class);
1102:                hugeEnumSet.add(HugeEnumWithInnerClass.a);
1103:                hugeEnumSet.add(HugeEnumWithInnerClass.f);
1104:                EnumSet<HugeEnumWithInnerClass> copyOfHugeEnum = EnumSet
1105:                        .copyOf(hugeEnumSet);
1106:                assertEquals(enumSet.size(), copyOfE.size());
1107:
1108:                assertTrue(copyOfHugeEnum.contains(HugeEnumWithInnerClass.a));
1109:                assertTrue(copyOfHugeEnum.contains(HugeEnumWithInnerClass.f));
1110:
1111:                Object[] hugeEnumValue = copyOfHugeEnum.toArray();
1112:                assertSame(hugeEnumValue[0], HugeEnumWithInnerClass.a);
1113:                assertSame(hugeEnumValue[1], HugeEnumWithInnerClass.f);
1114:            }
1115:
1116:            /**
1117:             * @tests java.util.EnumSet#removeAll(Collection)
1118:             */
1119:            @SuppressWarnings("unchecked")
1120:            public void test_removeAll_LCollection() {
1121:                Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
1122:                try {
1123:                    set.removeAll(null);
1124:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1125:                } catch (NullPointerException e) {
1126:                    // expected
1127:                }
1128:
1129:                set = EnumSet.allOf(EnumFoo.class);
1130:                assertEquals("Size of set should be 64:", 64, set.size()); //$NON-NLS-1$
1131:
1132:                try {
1133:                    set.removeAll(null);
1134:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1135:                } catch (NullPointerException e) {
1136:                    // expected
1137:                }
1138:
1139:                Collection<EnumFoo> collection = new ArrayList<EnumFoo>();
1140:                collection.add(EnumFoo.a);
1141:
1142:                boolean result = set.removeAll(collection);
1143:                assertTrue("Should return true", result); //$NON-NLS-1$
1144:                assertEquals("Size of set should be 63", 63, set.size()); //$NON-NLS-1$
1145:
1146:                collection = new ArrayList();
1147:                result = set.removeAll(collection);
1148:                assertFalse("Should return false", result); //$NON-NLS-1$
1149:
1150:                Set<EmptyEnum> emptySet = EnumSet.noneOf(EmptyEnum.class);
1151:                result = set.removeAll(emptySet);
1152:                assertFalse("Should return false", result); //$NON-NLS-1$
1153:
1154:                EnumSet<EnumFoo> emptyFooSet = EnumSet.noneOf(EnumFoo.class);
1155:                result = set.removeAll(emptyFooSet);
1156:                assertFalse("Should return false", result); //$NON-NLS-1$
1157:
1158:                emptyFooSet.add(EnumFoo.a);
1159:                result = set.removeAll(emptyFooSet);
1160:                assertFalse("Should return false", result); //$NON-NLS-1$
1161:
1162:                Set<EnumWithInnerClass> setWithSubclass = EnumSet
1163:                        .noneOf(EnumWithInnerClass.class);
1164:                result = set.removeAll(setWithSubclass);
1165:                assertFalse("Should return false", result); //$NON-NLS-1$
1166:
1167:                setWithSubclass.add(EnumWithInnerClass.a);
1168:                result = set.removeAll(setWithSubclass);
1169:                assertFalse("Should return false", result); //$NON-NLS-1$
1170:
1171:                Set<EnumFoo> anotherSet = EnumSet.noneOf(EnumFoo.class);
1172:                anotherSet.add(EnumFoo.a);
1173:
1174:                set = EnumSet.allOf(EnumFoo.class);
1175:                result = set.removeAll(anotherSet);
1176:                assertTrue("Should return true", result); //$NON-NLS-1$
1177:                assertEquals("Size of set should be 63:", 63, set.size()); //$NON-NLS-1$
1178:
1179:                Set<EnumWithInnerClass> setWithInnerClass = EnumSet
1180:                        .noneOf(EnumWithInnerClass.class);
1181:                setWithInnerClass.add(EnumWithInnerClass.a);
1182:                setWithInnerClass.add(EnumWithInnerClass.b);
1183:
1184:                Set<EnumWithInnerClass> anotherSetWithInnerClass = EnumSet
1185:                        .noneOf(EnumWithInnerClass.class);
1186:                anotherSetWithInnerClass.add(EnumWithInnerClass.c);
1187:                anotherSetWithInnerClass.add(EnumWithInnerClass.d);
1188:                result = anotherSetWithInnerClass.removeAll(setWithInnerClass);
1189:                assertFalse("Should return false", result); //$NON-NLS-1$
1190:
1191:                anotherSetWithInnerClass.add(EnumWithInnerClass.a);
1192:                result = anotherSetWithInnerClass.removeAll(setWithInnerClass);
1193:                assertTrue("Should return true", result); //$NON-NLS-1$
1194:                assertEquals(
1195:                        "Size of anotherSetWithInnerClass should remain 2", //$NON-NLS-1$
1196:                        2, anotherSetWithInnerClass.size());
1197:
1198:                anotherSetWithInnerClass.remove(EnumWithInnerClass.c);
1199:                anotherSetWithInnerClass.remove(EnumWithInnerClass.d);
1200:                result = anotherSetWithInnerClass.remove(setWithInnerClass);
1201:                assertFalse("Should return false", result); //$NON-NLS-1$
1202:
1203:                Set rawSet = EnumSet.allOf(EnumWithAllInnerClass.class);
1204:                result = rawSet.removeAll(EnumSet.allOf(EnumFoo.class));
1205:                assertFalse("Should return false", result); //$NON-NLS-1$
1206:
1207:                setWithInnerClass = EnumSet.allOf(EnumWithInnerClass.class);
1208:                anotherSetWithInnerClass = EnumSet
1209:                        .allOf(EnumWithInnerClass.class);
1210:                setWithInnerClass.remove(EnumWithInnerClass.a);
1211:                anotherSetWithInnerClass.remove(EnumWithInnerClass.f);
1212:                result = setWithInnerClass.removeAll(anotherSetWithInnerClass);
1213:                assertTrue("Should return true", result); //$NON-NLS-1$
1214:                assertEquals(
1215:                        "Size of setWithInnerClass should be 1", 1, setWithInnerClass.size()); //$NON-NLS-1$
1216:
1217:                result = setWithInnerClass.contains(EnumWithInnerClass.f);
1218:                assertTrue("Should return true", result); //$NON-NLS-1$
1219:
1220:                // test enum type with more than 64 elements
1221:                Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
1222:
1223:                Collection<HugeEnum> hugeCollection = new ArrayList<HugeEnum>();
1224:                hugeCollection.add(HugeEnum.a);
1225:
1226:                result = hugeSet.removeAll(hugeCollection);
1227:                assertTrue(result);
1228:                assertEquals(64, hugeSet.size());
1229:
1230:                collection = new ArrayList();
1231:                result = hugeSet.removeAll(collection);
1232:                assertFalse(result);
1233:
1234:                Set<HugeEnum> emptyHugeSet = EnumSet.noneOf(HugeEnum.class);
1235:                result = hugeSet.removeAll(emptyHugeSet);
1236:                assertFalse(result);
1237:
1238:                Set<HugeEnumWithInnerClass> hugeSetWithSubclass = EnumSet
1239:                        .noneOf(HugeEnumWithInnerClass.class);
1240:                result = hugeSet.removeAll(hugeSetWithSubclass);
1241:                assertFalse(result);
1242:
1243:                hugeSetWithSubclass.add(HugeEnumWithInnerClass.a);
1244:                result = hugeSet.removeAll(hugeSetWithSubclass);
1245:                assertFalse(result);
1246:
1247:                Set<HugeEnum> anotherHugeSet = EnumSet.noneOf(HugeEnum.class);
1248:                anotherHugeSet.add(HugeEnum.a);
1249:
1250:                hugeSet = EnumSet.allOf(HugeEnum.class);
1251:                result = hugeSet.removeAll(anotherHugeSet);
1252:                assertTrue(result);
1253:                assertEquals(63, set.size());
1254:
1255:                Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
1256:                        .noneOf(HugeEnumWithInnerClass.class);
1257:                hugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
1258:                hugeSetWithInnerClass.add(HugeEnumWithInnerClass.b);
1259:
1260:                Set<HugeEnumWithInnerClass> anotherHugeSetWithInnerClass = EnumSet
1261:                        .noneOf(HugeEnumWithInnerClass.class);
1262:                anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.c);
1263:                anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.d);
1264:                result = anotherHugeSetWithInnerClass
1265:                        .removeAll(setWithInnerClass);
1266:                assertFalse("Should return false", result); //$NON-NLS-1$
1267:
1268:                anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.a);
1269:                result = anotherHugeSetWithInnerClass
1270:                        .removeAll(hugeSetWithInnerClass);
1271:                assertTrue(result);
1272:                assertEquals(2, anotherHugeSetWithInnerClass.size());
1273:
1274:                anotherHugeSetWithInnerClass.remove(HugeEnumWithInnerClass.c);
1275:                anotherHugeSetWithInnerClass.remove(HugeEnumWithInnerClass.d);
1276:                result = anotherHugeSetWithInnerClass
1277:                        .remove(hugeSetWithInnerClass);
1278:                assertFalse(result);
1279:
1280:                rawSet = EnumSet.allOf(HugeEnumWithInnerClass.class);
1281:                result = rawSet.removeAll(EnumSet.allOf(HugeEnum.class));
1282:                assertFalse(result);
1283:
1284:                hugeSetWithInnerClass = EnumSet
1285:                        .allOf(HugeEnumWithInnerClass.class);
1286:                anotherHugeSetWithInnerClass = EnumSet
1287:                        .allOf(HugeEnumWithInnerClass.class);
1288:                hugeSetWithInnerClass.remove(HugeEnumWithInnerClass.a);
1289:                anotherHugeSetWithInnerClass.remove(HugeEnumWithInnerClass.f);
1290:                result = hugeSetWithInnerClass
1291:                        .removeAll(anotherHugeSetWithInnerClass);
1292:                assertTrue(result);
1293:                assertEquals(1, hugeSetWithInnerClass.size());
1294:
1295:                result = hugeSetWithInnerClass
1296:                        .contains(HugeEnumWithInnerClass.f);
1297:                assertTrue(result);
1298:            }
1299:
1300:            /**
1301:             * @tests java.util.EnumSet#retainAll(Collection)
1302:             */
1303:            @SuppressWarnings("unchecked")
1304:            public void test_retainAll_LCollection() {
1305:                Set<EnumFoo> set = EnumSet.allOf(EnumFoo.class);
1306:
1307:                try {
1308:                    set.retainAll(null);
1309:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1310:                } catch (NullPointerException e) {
1311:                    // expected
1312:                }
1313:
1314:                set.clear();
1315:                boolean result = set.retainAll(null);
1316:                assertFalse("Should return false", result); //$NON-NLS-1$
1317:
1318:                Collection rawCollection = new ArrayList();
1319:                result = set.retainAll(rawCollection);
1320:                assertFalse("Should return false", result); //$NON-NLS-1$
1321:
1322:                rawCollection.add(EnumFoo.a);
1323:                result = set.retainAll(rawCollection);
1324:                assertFalse("Should return false", result); //$NON-NLS-1$
1325:
1326:                rawCollection.add(EnumWithInnerClass.a);
1327:                result = set.retainAll(rawCollection);
1328:                assertFalse("Should return false", result); //$NON-NLS-1$
1329:                assertEquals("Size of set should be 0:", 0, set.size()); //$NON-NLS-1$
1330:
1331:                rawCollection.remove(EnumFoo.a);
1332:                result = set.retainAll(rawCollection);
1333:                assertFalse("Should return false", result); //$NON-NLS-1$
1334:
1335:                Set<EnumFoo> anotherSet = EnumSet.allOf(EnumFoo.class);
1336:                result = set.retainAll(anotherSet);
1337:                assertFalse("Should return false", result); //$NON-NLS-1$
1338:                assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
1339:
1340:                Set<EnumWithInnerClass> setWithInnerClass = EnumSet
1341:                        .allOf(EnumWithInnerClass.class);
1342:                result = set.retainAll(setWithInnerClass);
1343:                assertTrue("Should return true", result); //$NON-NLS-1$
1344:                assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
1345:
1346:                setWithInnerClass = EnumSet.noneOf(EnumWithInnerClass.class);
1347:                result = set.retainAll(setWithInnerClass);
1348:                assertTrue("Should return true", result); //$NON-NLS-1$
1349:
1350:                Set<EmptyEnum> emptySet = EnumSet.allOf(EmptyEnum.class);
1351:                result = set.retainAll(emptySet);
1352:                assertTrue("Should return true", result); //$NON-NLS-1$
1353:
1354:                Set<EnumWithAllInnerClass> setWithAllInnerClass = EnumSet
1355:                        .allOf(EnumWithAllInnerClass.class);
1356:                result = set.retainAll(setWithAllInnerClass);
1357:                assertTrue("Should return true", result); //$NON-NLS-1$
1358:
1359:                set.add(EnumFoo.a);
1360:                result = set.retainAll(setWithInnerClass);
1361:                assertTrue("Should return true", result); //$NON-NLS-1$
1362:                assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
1363:
1364:                setWithInnerClass = EnumSet.allOf(EnumWithInnerClass.class);
1365:                setWithInnerClass.remove(EnumWithInnerClass.f);
1366:                Set<EnumWithInnerClass> anotherSetWithInnerClass = EnumSet
1367:                        .noneOf(EnumWithInnerClass.class);
1368:                anotherSetWithInnerClass.add(EnumWithInnerClass.e);
1369:                anotherSetWithInnerClass.add(EnumWithInnerClass.f);
1370:
1371:                result = setWithInnerClass.retainAll(anotherSetWithInnerClass);
1372:                assertTrue("Should return true", result); //$NON-NLS-1$
1373:                result = setWithInnerClass.contains(EnumWithInnerClass.e);
1374:                assertTrue("Should contain EnumWithInnerClass.e", result); //$NON-NLS-1$
1375:                result = setWithInnerClass.contains(EnumWithInnerClass.b);
1376:                assertFalse("Should not contain EnumWithInnerClass.b", result); //$NON-NLS-1$
1377:                assertEquals(
1378:                        "Size of set should be 1:", 1, setWithInnerClass.size()); //$NON-NLS-1$
1379:
1380:                anotherSetWithInnerClass = EnumSet
1381:                        .allOf(EnumWithInnerClass.class);
1382:                result = setWithInnerClass.retainAll(anotherSetWithInnerClass);
1383:
1384:                assertFalse("Return value should be false", result); //$NON-NLS-1$
1385:
1386:                rawCollection = new ArrayList();
1387:                rawCollection.add(EnumWithInnerClass.e);
1388:                rawCollection.add(EnumWithInnerClass.f);
1389:                result = setWithInnerClass.retainAll(rawCollection);
1390:                assertFalse("Should return false", result); //$NON-NLS-1$
1391:
1392:                set = EnumSet.allOf(EnumFoo.class);
1393:                set.remove(EnumFoo.a);
1394:                anotherSet = EnumSet.noneOf(EnumFoo.class);
1395:                anotherSet.add(EnumFoo.a);
1396:                result = set.retainAll(anotherSet);
1397:                assertTrue("Should return true", result); //$NON-NLS-1$
1398:                assertEquals("size should be 0", 0, set.size()); //$NON-NLS-1$
1399:
1400:                // test enum type with more than 64 elements
1401:                Set<HugeEnum> hugeSet = EnumSet.allOf(HugeEnum.class);
1402:
1403:                try {
1404:                    hugeSet.retainAll(null);
1405:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1406:                } catch (NullPointerException e) {
1407:                    // expected
1408:                }
1409:
1410:                hugeSet.clear();
1411:                result = hugeSet.retainAll(null);
1412:                assertFalse(result);
1413:
1414:                rawCollection = new ArrayList();
1415:                result = hugeSet.retainAll(rawCollection);
1416:                assertFalse(result);
1417:
1418:                rawCollection.add(HugeEnum.a);
1419:                result = hugeSet.retainAll(rawCollection);
1420:                assertFalse(result);
1421:
1422:                rawCollection.add(HugeEnumWithInnerClass.a);
1423:                result = hugeSet.retainAll(rawCollection);
1424:                assertFalse(result);
1425:                assertEquals(0, set.size());
1426:
1427:                rawCollection.remove(HugeEnum.a);
1428:                result = set.retainAll(rawCollection);
1429:                assertFalse(result);
1430:
1431:                Set<HugeEnum> anotherHugeSet = EnumSet.allOf(HugeEnum.class);
1432:                result = hugeSet.retainAll(anotherHugeSet);
1433:                assertFalse(result);
1434:                assertEquals(0, hugeSet.size());
1435:
1436:                Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
1437:                        .allOf(HugeEnumWithInnerClass.class);
1438:                result = hugeSet.retainAll(hugeSetWithInnerClass);
1439:                assertTrue(result);
1440:                assertEquals(0, hugeSet.size());
1441:
1442:                hugeSetWithInnerClass = EnumSet
1443:                        .noneOf(HugeEnumWithInnerClass.class);
1444:                result = hugeSet.retainAll(hugeSetWithInnerClass);
1445:                assertTrue(result);
1446:
1447:                Set<HugeEnumWithInnerClass> hugeSetWithAllInnerClass = EnumSet
1448:                        .allOf(HugeEnumWithInnerClass.class);
1449:                result = hugeSet.retainAll(hugeSetWithAllInnerClass);
1450:                assertTrue(result);
1451:
1452:                hugeSet.add(HugeEnum.a);
1453:                result = hugeSet.retainAll(hugeSetWithInnerClass);
1454:                assertTrue(result);
1455:                assertEquals(0, hugeSet.size());
1456:
1457:                hugeSetWithInnerClass = EnumSet
1458:                        .allOf(HugeEnumWithInnerClass.class);
1459:                hugeSetWithInnerClass.remove(HugeEnumWithInnerClass.f);
1460:                Set<HugeEnumWithInnerClass> anotherHugeSetWithInnerClass = EnumSet
1461:                        .noneOf(HugeEnumWithInnerClass.class);
1462:                anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.e);
1463:                anotherHugeSetWithInnerClass.add(HugeEnumWithInnerClass.f);
1464:
1465:                result = hugeSetWithInnerClass
1466:                        .retainAll(anotherHugeSetWithInnerClass);
1467:                assertTrue(result);
1468:                result = hugeSetWithInnerClass
1469:                        .contains(HugeEnumWithInnerClass.e);
1470:                assertTrue("Should contain HugeEnumWithInnerClass.e", result); //$NON-NLS-1$
1471:                result = hugeSetWithInnerClass
1472:                        .contains(HugeEnumWithInnerClass.b);
1473:                assertFalse(
1474:                        "Should not contain HugeEnumWithInnerClass.b", result); //$NON-NLS-1$
1475:                assertEquals(
1476:                        "Size of hugeSet should be 1:", 1, hugeSetWithInnerClass.size()); //$NON-NLS-1$
1477:
1478:                anotherHugeSetWithInnerClass = EnumSet
1479:                        .allOf(HugeEnumWithInnerClass.class);
1480:                result = hugeSetWithInnerClass
1481:                        .retainAll(anotherHugeSetWithInnerClass);
1482:
1483:                assertFalse("Return value should be false", result); //$NON-NLS-1$
1484:
1485:                rawCollection = new ArrayList();
1486:                rawCollection.add(HugeEnumWithInnerClass.e);
1487:                rawCollection.add(HugeEnumWithInnerClass.f);
1488:                result = hugeSetWithInnerClass.retainAll(rawCollection);
1489:                assertFalse(result);
1490:
1491:                hugeSet = EnumSet.allOf(HugeEnum.class);
1492:                hugeSet.remove(HugeEnum.a);
1493:                anotherHugeSet = EnumSet.noneOf(HugeEnum.class);
1494:                anotherHugeSet.add(HugeEnum.a);
1495:                result = hugeSet.retainAll(anotherHugeSet);
1496:                assertTrue(result);
1497:                assertEquals(0, hugeSet.size());
1498:            }
1499:
1500:            /**
1501:             * @tests java.util.EnumSet#iterator()
1502:             */
1503:            public void test_iterator() {
1504:                Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class);
1505:                set.add(EnumFoo.a);
1506:                set.add(EnumFoo.b);
1507:
1508:                Iterator<EnumFoo> iterator = set.iterator();
1509:                Iterator<EnumFoo> anotherIterator = set.iterator();
1510:                assertNotSame("Should not be same", iterator, anotherIterator); //$NON-NLS-1$
1511:                try {
1512:                    iterator.remove();
1513:                    fail("Should throw IllegalStateException"); //$NON-NLS-1$
1514:                } catch (IllegalStateException e) {
1515:                    // expectedd
1516:                }
1517:
1518:                assertTrue("Should has next element:", iterator.hasNext()); //$NON-NLS-1$
1519:                assertSame("Should be identical", EnumFoo.a, iterator.next()); //$NON-NLS-1$
1520:                iterator.remove();
1521:                assertTrue("Should has next element:", iterator.hasNext()); //$NON-NLS-1$
1522:                assertSame("Should be identical", EnumFoo.b, iterator.next()); //$NON-NLS-1$
1523:                assertFalse("Should not has next element:", iterator.hasNext()); //$NON-NLS-1$
1524:                assertFalse("Should not has next element:", iterator.hasNext()); //$NON-NLS-1$
1525:
1526:                assertEquals("Size should be 1:", 1, set.size()); //$NON-NLS-1$
1527:
1528:                try {
1529:                    iterator.next();
1530:                    fail("Should throw NoSuchElementException"); //$NON-NLS-1$
1531:                } catch (NoSuchElementException e) {
1532:                    // expected
1533:                }
1534:                set = EnumSet.noneOf(EnumFoo.class);
1535:                set.add(EnumFoo.a);
1536:                iterator = set.iterator();
1537:                assertEquals("Should be equal", EnumFoo.a, iterator.next()); //$NON-NLS-1$
1538:                iterator.remove();
1539:                try {
1540:                    iterator.remove();
1541:                    fail("Should throw IllegalStateException"); //$NON-NLS-1$
1542:                } catch (IllegalStateException e) {
1543:                    // expected
1544:                }
1545:
1546:                Set<EmptyEnum> emptySet = EnumSet.allOf(EmptyEnum.class);
1547:                Iterator<EmptyEnum> emptyIterator = emptySet.iterator();
1548:                try {
1549:                    emptyIterator.next();
1550:                    fail("Should throw NoSuchElementException"); //$NON-NLS-1$
1551:                } catch (NoSuchElementException e) {
1552:                    // expected
1553:                }
1554:
1555:                Set<EnumWithInnerClass> setWithSubclass = EnumSet
1556:                        .allOf(EnumWithInnerClass.class);
1557:                setWithSubclass.remove(EnumWithInnerClass.e);
1558:                Iterator<EnumWithInnerClass> iteratorWithSubclass = setWithSubclass
1559:                        .iterator();
1560:                assertSame(
1561:                        "Should be same", EnumWithInnerClass.a, iteratorWithSubclass.next()); //$NON-NLS-1$
1562:
1563:                assertTrue("Should return true", iteratorWithSubclass.hasNext()); //$NON-NLS-1$
1564:                assertSame(
1565:                        "Should be same", EnumWithInnerClass.b, iteratorWithSubclass.next()); //$NON-NLS-1$
1566:
1567:                setWithSubclass.remove(EnumWithInnerClass.c);
1568:                assertTrue("Should return true", iteratorWithSubclass.hasNext()); //$NON-NLS-1$
1569:                assertSame(
1570:                        "Should be same", EnumWithInnerClass.c, iteratorWithSubclass.next()); //$NON-NLS-1$
1571:
1572:                assertTrue("Should return true", iteratorWithSubclass.hasNext()); //$NON-NLS-1$
1573:                assertSame(
1574:                        "Should be same", EnumWithInnerClass.d, iteratorWithSubclass.next()); //$NON-NLS-1$
1575:
1576:                setWithSubclass.add(EnumWithInnerClass.e);
1577:                assertTrue("Should return true", iteratorWithSubclass.hasNext()); //$NON-NLS-1$
1578:                assertSame(
1579:                        "Should be same", EnumWithInnerClass.f, iteratorWithSubclass.next()); //$NON-NLS-1$
1580:
1581:                set = EnumSet.noneOf(EnumFoo.class);
1582:                iterator = set.iterator();
1583:                try {
1584:                    iterator.next();
1585:                    fail("Should throw NoSuchElementException"); //$NON-NLS-1$
1586:                } catch (NoSuchElementException e) {
1587:                    // expected
1588:                }
1589:
1590:                set.add(EnumFoo.a);
1591:                iterator = set.iterator();
1592:                assertEquals(
1593:                        "Should return EnumFoo.a", EnumFoo.a, iterator.next()); //$NON-NLS-1$
1594:                assertEquals("Size of set should be 1", 1, set.size()); //$NON-NLS-1$
1595:                iterator.remove();
1596:                assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
1597:                assertFalse("Should return false", set.contains(EnumFoo.a)); //$NON-NLS-1$
1598:
1599:                set.add(EnumFoo.a);
1600:                set.add(EnumFoo.b);
1601:                iterator = set.iterator();
1602:                assertEquals("Should be equals", EnumFoo.a, iterator.next()); //$NON-NLS-1$
1603:                iterator.remove();
1604:                try {
1605:                    iterator.remove();
1606:                    fail("Should throw IllegalStateException"); //$NON-NLS-1$
1607:                } catch (IllegalStateException e) {
1608:                    // expected
1609:                }
1610:
1611:                assertTrue("Should have next element", iterator.hasNext()); //$NON-NLS-1$
1612:                try {
1613:                    iterator.remove();
1614:                    fail("Should throw IllegalStateException"); //$NON-NLS-1$
1615:                } catch (IllegalStateException e) {
1616:                    // expected
1617:                }
1618:                assertEquals("Size of set should be 1", 1, set.size()); //$NON-NLS-1$
1619:                assertTrue("Should have next element", iterator.hasNext()); //$NON-NLS-1$
1620:                assertEquals(
1621:                        "Should return EnumFoo.b", EnumFoo.b, iterator.next()); //$NON-NLS-1$
1622:                set.remove(EnumFoo.b);
1623:                assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
1624:                iterator.remove();
1625:                assertFalse("Should return false", set.contains(EnumFoo.a)); //$NON-NLS-1$
1626:
1627:                // RI's bug, EnumFoo.b should not exist at the moment.
1628:                assertFalse("Should return false", set.contains(EnumFoo.b)); //$NON-NLS-1$
1629:
1630:                // test enum type with more than 64 elements
1631:                Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class);
1632:                hugeSet.add(HugeEnum.a);
1633:                hugeSet.add(HugeEnum.b);
1634:
1635:                Iterator<HugeEnum> hIterator = hugeSet.iterator();
1636:                Iterator<HugeEnum> anotherHugeIterator = hugeSet.iterator();
1637:                assertNotSame(hIterator, anotherHugeIterator);
1638:                try {
1639:                    hIterator.remove();
1640:                    fail("Should throw IllegalStateException"); //$NON-NLS-1$
1641:                } catch (IllegalStateException e) {
1642:                    // expectedd
1643:                }
1644:
1645:                assertTrue(hIterator.hasNext());
1646:                assertSame(HugeEnum.a, hIterator.next());
1647:                hIterator.remove();
1648:                assertTrue(hIterator.hasNext());
1649:                assertSame(HugeEnum.b, hIterator.next());
1650:                assertFalse(hIterator.hasNext());
1651:                assertFalse(hIterator.hasNext());
1652:
1653:                assertEquals(1, hugeSet.size());
1654:
1655:                try {
1656:                    hIterator.next();
1657:                    fail("Should throw NoSuchElementException"); //$NON-NLS-1$
1658:                } catch (NoSuchElementException e) {
1659:                    // expected
1660:                }
1661:
1662:                Set<HugeEnumWithInnerClass> hugeSetWithSubclass = EnumSet
1663:                        .allOf(HugeEnumWithInnerClass.class);
1664:                hugeSetWithSubclass.remove(HugeEnumWithInnerClass.e);
1665:                Iterator<HugeEnumWithInnerClass> hugeIteratorWithSubclass = hugeSetWithSubclass
1666:                        .iterator();
1667:                assertSame(HugeEnumWithInnerClass.a, hugeIteratorWithSubclass
1668:                        .next());
1669:
1670:                assertTrue(hugeIteratorWithSubclass.hasNext());
1671:                assertSame(HugeEnumWithInnerClass.b, hugeIteratorWithSubclass
1672:                        .next());
1673:
1674:                setWithSubclass.remove(HugeEnumWithInnerClass.c);
1675:                assertTrue(hugeIteratorWithSubclass.hasNext());
1676:                assertSame(HugeEnumWithInnerClass.c, hugeIteratorWithSubclass
1677:                        .next());
1678:
1679:                assertTrue(hugeIteratorWithSubclass.hasNext());
1680:                assertSame(HugeEnumWithInnerClass.d, hugeIteratorWithSubclass
1681:                        .next());
1682:
1683:                hugeSetWithSubclass.add(HugeEnumWithInnerClass.e);
1684:                assertTrue(hugeIteratorWithSubclass.hasNext());
1685:                assertSame(HugeEnumWithInnerClass.f, hugeIteratorWithSubclass
1686:                        .next());
1687:
1688:                hugeSet = EnumSet.noneOf(HugeEnum.class);
1689:                hIterator = hugeSet.iterator();
1690:                try {
1691:                    hIterator.next();
1692:                    fail("Should throw NoSuchElementException"); //$NON-NLS-1$
1693:                } catch (NoSuchElementException e) {
1694:                    // expected
1695:                }
1696:
1697:                hugeSet.add(HugeEnum.a);
1698:                hIterator = hugeSet.iterator();
1699:                assertEquals(HugeEnum.a, hIterator.next());
1700:                assertEquals(1, hugeSet.size());
1701:                hIterator.remove();
1702:                assertEquals(0, hugeSet.size());
1703:                assertFalse(hugeSet.contains(HugeEnum.a));
1704:
1705:                hugeSet.add(HugeEnum.a);
1706:                hugeSet.add(HugeEnum.b);
1707:                hIterator = hugeSet.iterator();
1708:                hIterator.next();
1709:                hIterator.remove();
1710:
1711:                assertTrue(hIterator.hasNext());
1712:                try {
1713:                    hIterator.remove();
1714:                    fail("Should throw IllegalStateException"); //$NON-NLS-1$
1715:                } catch (IllegalStateException e) {
1716:                    // expected
1717:                }
1718:                assertEquals(1, hugeSet.size());
1719:                assertTrue(hIterator.hasNext());
1720:                assertEquals(HugeEnum.b, hIterator.next());
1721:                hugeSet.remove(HugeEnum.b);
1722:                assertEquals(0, hugeSet.size());
1723:                hIterator.remove();
1724:                assertFalse(hugeSet.contains(HugeEnum.a));
1725:                // RI's bug, EnumFoo.b should not exist at the moment.
1726:                assertFalse("Should return false", set.contains(EnumFoo.b)); //$NON-NLS-1$
1727:
1728:                // Regression for HARMONY-4728
1729:                hugeSet = EnumSet.allOf(HugeEnum.class);
1730:                hIterator = hugeSet.iterator();
1731:                for (int i = 0; i < 63; i++) {
1732:                    hIterator.next();
1733:                }
1734:                assertSame(HugeEnum.ll, hIterator.next());
1735:            }
1736:
1737:            /**
1738:             * @tests java.util.EnumSet#of(E)
1739:             */
1740:            public void test_Of_E() {
1741:                EnumSet<EnumWithInnerClass> enumSet = EnumSet
1742:                        .of(EnumWithInnerClass.a);
1743:                assertEquals("enumSet should have length 1:", 1, enumSet.size()); //$NON-NLS-1$
1744:
1745:                assertTrue("enumSet should contain EnumWithSubclass.a:", //$NON-NLS-1$
1746:                        enumSet.contains(EnumWithInnerClass.a));
1747:
1748:                try {
1749:                    EnumSet.of((EnumWithInnerClass) null);
1750:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1751:                } catch (NullPointerException npe) {
1752:                    // expected
1753:                }
1754:
1755:                // test enum type with more than 64 elements
1756:                EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet
1757:                        .of(HugeEnumWithInnerClass.a);
1758:                assertEquals(1, hugeEnumSet.size());
1759:
1760:                assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
1761:            }
1762:
1763:            /**
1764:             * @tests java.util.EnumSet#of(E, E)
1765:             */
1766:            public void test_Of_EE() {
1767:                EnumSet<EnumWithInnerClass> enumSet = EnumSet.of(
1768:                        EnumWithInnerClass.a, EnumWithInnerClass.b);
1769:                assertEquals("enumSet should have length 2:", 2, enumSet.size()); //$NON-NLS-1$
1770:
1771:                assertTrue("enumSet should contain EnumWithSubclass.a:", //$NON-NLS-1$
1772:                        enumSet.contains(EnumWithInnerClass.a));
1773:                assertTrue("enumSet should contain EnumWithSubclass.b:", //$NON-NLS-1$
1774:                        enumSet.contains(EnumWithInnerClass.b));
1775:
1776:                try {
1777:                    EnumSet.of((EnumWithInnerClass) null, EnumWithInnerClass.a);
1778:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1779:                } catch (NullPointerException npe) {
1780:                    // expected
1781:                }
1782:
1783:                try {
1784:                    EnumSet.of(EnumWithInnerClass.a, (EnumWithInnerClass) null);
1785:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1786:                } catch (NullPointerException npe) {
1787:                    // expected
1788:                }
1789:
1790:                try {
1791:                    EnumSet.of((EnumWithInnerClass) null,
1792:                            (EnumWithInnerClass) null);
1793:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1794:                } catch (NullPointerException npe) {
1795:                    // expected
1796:                }
1797:
1798:                enumSet = EnumSet
1799:                        .of(EnumWithInnerClass.a, EnumWithInnerClass.a);
1800:                assertEquals("Size of enumSet should be 1", //$NON-NLS-1$
1801:                        1, enumSet.size());
1802:
1803:                // test enum type with more than 64 elements
1804:                EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(
1805:                        HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.b);
1806:                assertEquals(2, hugeEnumSet.size());
1807:
1808:                assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
1809:                assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.b));
1810:
1811:                try {
1812:                    EnumSet.of((HugeEnumWithInnerClass) null,
1813:                            HugeEnumWithInnerClass.a);
1814:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1815:                } catch (NullPointerException npe) {
1816:                    // expected
1817:                }
1818:
1819:                try {
1820:                    EnumSet.of(HugeEnumWithInnerClass.a,
1821:                            (HugeEnumWithInnerClass) null);
1822:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1823:                } catch (NullPointerException npe) {
1824:                    // expected
1825:                }
1826:
1827:                try {
1828:                    EnumSet.of((HugeEnumWithInnerClass) null,
1829:                            (HugeEnumWithInnerClass) null);
1830:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1831:                } catch (NullPointerException npe) {
1832:                    // expected
1833:                }
1834:
1835:                hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a,
1836:                        HugeEnumWithInnerClass.a);
1837:                assertEquals(1, hugeEnumSet.size());
1838:            }
1839:
1840:            /**
1841:             * @tests java.util.EnumSet#of(E, E, E)
1842:             */
1843:            public void test_Of_EEE() {
1844:                EnumSet<EnumWithInnerClass> enumSet = EnumSet.of(
1845:                        EnumWithInnerClass.a, EnumWithInnerClass.b,
1846:                        EnumWithInnerClass.c);
1847:                assertEquals("Size of enumSet should be 3:", 3, enumSet.size()); //$NON-NLS-1$
1848:
1849:                assertTrue(
1850:                        "enumSet should contain EnumWithSubclass.a:", enumSet.contains(EnumWithInnerClass.a)); //$NON-NLS-1$
1851:                assertTrue(
1852:                        "Should return true", enumSet.contains(EnumWithInnerClass.c)); //$NON-NLS-1$
1853:
1854:                try {
1855:                    EnumSet.of((EnumWithInnerClass) null, null, null);
1856:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1857:                } catch (NullPointerException npe) {
1858:                    // expected
1859:                }
1860:
1861:                enumSet = EnumSet.of(EnumWithInnerClass.a,
1862:                        EnumWithInnerClass.b, EnumWithInnerClass.b);
1863:                assertEquals(
1864:                        "enumSet should contain 2 elements:", 2, enumSet.size()); //$NON-NLS-1$
1865:
1866:                // test enum type with more than 64 elements
1867:                EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(
1868:                        HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.b,
1869:                        HugeEnumWithInnerClass.c);
1870:                assertEquals(3, hugeEnumSet.size());
1871:
1872:                assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
1873:                assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.c));
1874:
1875:                try {
1876:                    EnumSet.of((HugeEnumWithInnerClass) null, null, null);
1877:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1878:                } catch (NullPointerException npe) {
1879:                    // expected
1880:                }
1881:
1882:                hugeEnumSet = EnumSet.of(HugeEnumWithInnerClass.a,
1883:                        HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.b);
1884:                assertEquals(2, hugeEnumSet.size());
1885:            }
1886:
1887:            /**
1888:             * @tests java.util.EnumSet#of(E, E, E, E)
1889:             */
1890:            public void test_Of_EEEE() {
1891:                EnumSet<EnumWithInnerClass> enumSet = EnumSet.of(
1892:                        EnumWithInnerClass.a, EnumWithInnerClass.b,
1893:                        EnumWithInnerClass.c, EnumWithInnerClass.d);
1894:                assertEquals("Size of enumSet should be 4", 4, enumSet.size()); //$NON-NLS-1$
1895:
1896:                assertTrue(
1897:                        "enumSet should contain EnumWithSubclass.a:", enumSet.contains(EnumWithInnerClass.a)); //$NON-NLS-1$
1898:                assertTrue(
1899:                        "enumSet should contain EnumWithSubclass.d:", enumSet //$NON-NLS-1$
1900:                                .contains(EnumWithInnerClass.d));
1901:
1902:                try {
1903:                    EnumSet.of((EnumWithInnerClass) null, null, null, null);
1904:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1905:                } catch (NullPointerException npe) {
1906:                    // expected
1907:                }
1908:
1909:                // test enum type with more than 64 elements
1910:                EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(
1911:                        HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.b,
1912:                        HugeEnumWithInnerClass.c, HugeEnumWithInnerClass.d);
1913:                assertEquals(4, hugeEnumSet.size());
1914:
1915:                assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
1916:                assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.d));
1917:
1918:                try {
1919:                    EnumSet.of((HugeEnumWithInnerClass) null, null, null, null);
1920:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1921:                } catch (NullPointerException npe) {
1922:                    // expected
1923:                }
1924:            }
1925:
1926:            /**
1927:             * @tests java.util.EnumSet#of(E, E, E, E, E)
1928:             */
1929:            public void test_Of_EEEEE() {
1930:                EnumSet<EnumWithInnerClass> enumSet = EnumSet.of(
1931:                        EnumWithInnerClass.a, EnumWithInnerClass.b,
1932:                        EnumWithInnerClass.c, EnumWithInnerClass.d,
1933:                        EnumWithInnerClass.e);
1934:                assertEquals("Size of enumSet should be 5:", 5, enumSet.size()); //$NON-NLS-1$
1935:
1936:                assertTrue(
1937:                        "Should return true", enumSet.contains(EnumWithInnerClass.a)); //$NON-NLS-1$
1938:                assertTrue(
1939:                        "Should return true", enumSet.contains(EnumWithInnerClass.e)); //$NON-NLS-1$
1940:
1941:                try {
1942:                    EnumSet.of((EnumWithInnerClass) null, null, null, null,
1943:                            null);
1944:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1945:                } catch (NullPointerException npe) {
1946:                    // expected
1947:                }
1948:
1949:                // test enum with more than 64 elements
1950:                EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(
1951:                        HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.b,
1952:                        HugeEnumWithInnerClass.c, HugeEnumWithInnerClass.d,
1953:                        HugeEnumWithInnerClass.e);
1954:                assertEquals(5, hugeEnumSet.size());
1955:
1956:                assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
1957:                assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.e));
1958:
1959:                try {
1960:                    EnumSet.of((HugeEnumWithInnerClass) null, null, null, null,
1961:                            null);
1962:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1963:                } catch (NullPointerException npe) {
1964:                    // expected
1965:                }
1966:            }
1967:
1968:            /**
1969:             * @tests java.util.EnumSet#of(E, E...)
1970:             */
1971:            public void test_Of_EEArray() {
1972:                EnumWithInnerClass[] enumArray = new EnumWithInnerClass[] {
1973:                        EnumWithInnerClass.b, EnumWithInnerClass.c };
1974:                EnumSet<EnumWithInnerClass> enumSet = EnumSet.of(
1975:                        EnumWithInnerClass.a, enumArray);
1976:                assertEquals("Should be equal", 3, enumSet.size()); //$NON-NLS-1$
1977:
1978:                assertTrue(
1979:                        "Should return true", enumSet.contains(EnumWithInnerClass.a)); //$NON-NLS-1$
1980:                assertTrue(
1981:                        "Should return true", enumSet.contains(EnumWithInnerClass.c)); //$NON-NLS-1$
1982:
1983:                try {
1984:                    EnumSet.of(EnumWithInnerClass.a,
1985:                            (EnumWithInnerClass[]) null);
1986:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
1987:                } catch (NullPointerException npe) {
1988:                    // expected
1989:                }
1990:
1991:                EnumFoo[] foos = { EnumFoo.a, EnumFoo.c, EnumFoo.d };
1992:                EnumSet<EnumFoo> set = EnumSet.of(EnumFoo.c, foos);
1993:                assertEquals("size of set should be 1", 3, set.size()); //$NON-NLS-1$
1994:                assertTrue("Should contain EnumFoo.a", set.contains(EnumFoo.a)); //$NON-NLS-1$
1995:                assertTrue("Should contain EnumFoo.c", set.contains(EnumFoo.c)); //$NON-NLS-1$
1996:                assertTrue("Should contain EnumFoo.d", set.contains(EnumFoo.d)); //$NON-NLS-1$
1997:
1998:                // test enum type with more than 64 elements
1999:                HugeEnumWithInnerClass[] hugeEnumArray = new HugeEnumWithInnerClass[] {
2000:                        HugeEnumWithInnerClass.b, HugeEnumWithInnerClass.c };
2001:                EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.of(
2002:                        HugeEnumWithInnerClass.a, hugeEnumArray);
2003:                assertEquals(3, hugeEnumSet.size());
2004:
2005:                assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.a));
2006:                assertTrue(hugeEnumSet.contains(HugeEnumWithInnerClass.c));
2007:
2008:                try {
2009:                    EnumSet.of(HugeEnumWithInnerClass.a,
2010:                            (HugeEnumWithInnerClass[]) null);
2011:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
2012:                } catch (NullPointerException npe) {
2013:                    // expected
2014:                }
2015:
2016:                HugeEnumWithInnerClass[] huges = { HugeEnumWithInnerClass.a,
2017:                        HugeEnumWithInnerClass.c, HugeEnumWithInnerClass.d };
2018:                EnumSet<HugeEnumWithInnerClass> hugeSet = EnumSet.of(
2019:                        HugeEnumWithInnerClass.c, huges);
2020:                assertEquals(3, hugeSet.size());
2021:                assertTrue(hugeSet.contains(HugeEnumWithInnerClass.a));
2022:                assertTrue(hugeSet.contains(HugeEnumWithInnerClass.c));
2023:                assertTrue(hugeSet.contains(HugeEnumWithInnerClass.d));
2024:            }
2025:
2026:            /**
2027:             * @tests java.util.EnumSet#range(E, E)
2028:             */
2029:            public void test_Range_EE() {
2030:                try {
2031:                    EnumSet.range(EnumWithInnerClass.c, null);
2032:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
2033:                } catch (NullPointerException e) {
2034:                    // expected
2035:                }
2036:
2037:                try {
2038:                    EnumSet.range(null, EnumWithInnerClass.c);
2039:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
2040:                } catch (NullPointerException e) {
2041:                    // expected
2042:                }
2043:
2044:                try {
2045:                    EnumSet.range(null, (EnumWithInnerClass) null);
2046:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
2047:                } catch (NullPointerException e) {
2048:                    // expected
2049:                }
2050:
2051:                try {
2052:                    EnumSet.range(EnumWithInnerClass.b, EnumWithInnerClass.a);
2053:                    fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
2054:                } catch (IllegalArgumentException e) {
2055:                    // expected
2056:                }
2057:
2058:                EnumSet<EnumWithInnerClass> enumSet = EnumSet.range(
2059:                        EnumWithInnerClass.a, EnumWithInnerClass.a);
2060:                assertEquals("Size of enumSet should be 1", 1, enumSet.size()); //$NON-NLS-1$
2061:
2062:                enumSet = EnumSet.range(EnumWithInnerClass.a,
2063:                        EnumWithInnerClass.c);
2064:                assertEquals("Size of enumSet should be 3", 3, enumSet.size()); //$NON-NLS-1$
2065:
2066:                // test enum with more than 64 elements
2067:                try {
2068:                    EnumSet.range(HugeEnumWithInnerClass.c, null);
2069:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
2070:                } catch (NullPointerException e) {
2071:                    // expected
2072:                }
2073:
2074:                try {
2075:                    EnumSet.range(null, HugeEnumWithInnerClass.c);
2076:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
2077:                } catch (NullPointerException e) {
2078:                    // expected
2079:                }
2080:
2081:                try {
2082:                    EnumSet.range(null, (HugeEnumWithInnerClass) null);
2083:                    fail("Should throw NullPointerException"); //$NON-NLS-1$
2084:                } catch (NullPointerException e) {
2085:                    // expected
2086:                }
2087:
2088:                try {
2089:                    EnumSet.range(HugeEnumWithInnerClass.b,
2090:                            HugeEnumWithInnerClass.a);
2091:                    fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
2092:                } catch (IllegalArgumentException e) {
2093:                    // expected
2094:                }
2095:
2096:                EnumSet<HugeEnumWithInnerClass> hugeEnumSet = EnumSet.range(
2097:                        HugeEnumWithInnerClass.a, HugeEnumWithInnerClass.a);
2098:                assertEquals(1, hugeEnumSet.size());
2099:
2100:                hugeEnumSet = EnumSet.range(HugeEnumWithInnerClass.c,
2101:                        HugeEnumWithInnerClass.aa);
2102:                assertEquals(51, hugeEnumSet.size());
2103:
2104:                hugeEnumSet = EnumSet.range(HugeEnumWithInnerClass.a,
2105:                        HugeEnumWithInnerClass.mm);
2106:                assertEquals(65, hugeEnumSet.size());
2107:
2108:                hugeEnumSet = EnumSet.range(HugeEnumWithInnerClass.b,
2109:                        HugeEnumWithInnerClass.mm);
2110:                assertEquals(64, hugeEnumSet.size());
2111:            }
2112:
2113:            /**
2114:             * @tests java.util.EnumSet#clone()
2115:             */
2116:            public void test_Clone() {
2117:                EnumSet<EnumFoo> enumSet = EnumSet.allOf(EnumFoo.class);
2118:                EnumSet<EnumFoo> clonedEnumSet = enumSet.clone();
2119:                assertEquals(enumSet, clonedEnumSet);
2120:                assertNotSame(enumSet, clonedEnumSet);
2121:                assertTrue(clonedEnumSet.contains(EnumFoo.a));
2122:                assertTrue(clonedEnumSet.contains(EnumFoo.b));
2123:                assertEquals(64, clonedEnumSet.size());
2124:
2125:                // test enum type with more than 64 elements
2126:                EnumSet<HugeEnum> hugeEnumSet = EnumSet.allOf(HugeEnum.class);
2127:                EnumSet<HugeEnum> hugeClonedEnumSet = hugeEnumSet.clone();
2128:                assertEquals(hugeEnumSet, hugeClonedEnumSet);
2129:                assertNotSame(hugeEnumSet, hugeClonedEnumSet);
2130:                assertTrue(hugeClonedEnumSet.contains(HugeEnum.a));
2131:                assertTrue(hugeClonedEnumSet.contains(HugeEnum.b));
2132:                assertEquals(65, hugeClonedEnumSet.size());
2133:
2134:                hugeClonedEnumSet.remove(HugeEnum.a);
2135:                assertEquals(64, hugeClonedEnumSet.size());
2136:                assertFalse(hugeClonedEnumSet.contains(HugeEnum.a));
2137:                assertEquals(65, hugeEnumSet.size());
2138:                assertTrue(hugeEnumSet.contains(HugeEnum.a));
2139:            }
2140:
2141:            /**
2142:             * @tests java.util.EnumSet#Serialization()
2143:             */
2144:            public void test_serialization() throws Exception {
2145:                EnumSet<EnumFoo> set = EnumSet.allOf(EnumFoo.class);
2146:                SerializationTest.verifySelf(set);
2147:            }
2148:
2149:            /**
2150:             * @tests serialization/deserialization compatibility with RI.
2151:             */
2152:            @SuppressWarnings({"unchecked","boxing"})
2153:            public void testSerializationCompatibility() throws Exception {
2154:                EnumSet<EnumFoo> set = EnumSet.allOf(EnumFoo.class);
2155:                SerializationTest.verifyGolden(this, set);
2156:            }
2157:        }
w___w__w.___jav_a__2__s.c_o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.