Source Code Cross Referenced for EnumTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » lang » 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.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Licensed to the Apache Software Foundation (ASF) under one or more
002:         * contributor license agreements.  See the NOTICE file distributed with
003:         * this work for additional information regarding copyright ownership.
004:         * The ASF licenses this file to You under the Apache License, Version 2.0
005:         * (the "License"); you may not use this file except in compliance with
006:         * the License.  You may obtain a copy of the License at
007:         * 
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.apache.harmony.luni.tests.java.lang;
018:
019:        import java.util.HashMap;
020:
021:        import junit.framework.TestCase;
022:
023:        import org.apache.harmony.testframework.serialization.SerializationTest;
024:
025:        import tests.util.SerializationTester;
026:
027:        public class EnumTest extends TestCase {
028:
029:            enum Sample {
030:                LARRY, MOE, CURLY
031:            }
032:
033:            Sample larry = Sample.LARRY;
034:
035:            Sample moe = Sample.MOE;
036:
037:            enum Empty {
038:            }
039:
040:            enum Bogus {
041:                UNUSED
042:            }
043:
044:            enum Color {
045:                Red, Green, Blue {
046:                };
047:            }
048:
049:            /**
050:             * @tests java.lang.Enum#compareTo(java.lang.Enum) 
051:             */
052:            public void test_compareToLjava_lang_Enum() {
053:                assertTrue(0 < Sample.MOE.compareTo(Sample.LARRY));
054:                assertEquals(0, Sample.MOE.compareTo(Sample.MOE));
055:                assertTrue(0 > Sample.MOE.compareTo(Sample.CURLY));
056:                try {
057:                    Sample.MOE.compareTo((Sample) null);
058:                    fail("Should throw NullPointerException");
059:                } catch (NullPointerException e) {
060:                    // Expected
061:                }
062:            }
063:
064:            /**
065:             * @tests java.lang.Enum#equals(Object)
066:             */
067:            public void test_equalsLjava_lang_Object() {
068:                assertFalse(moe.equals("bob"));
069:                assertTrue(moe.equals(Sample.MOE));
070:                assertFalse(Sample.LARRY.equals(Sample.CURLY));
071:                assertTrue(Sample.LARRY.equals(larry));
072:                assertFalse(Sample.CURLY.equals(null));
073:            }
074:
075:            /**
076:             * @tests java.lang.Enum#getDeclaringClass()
077:             */
078:            public void test_getDeclaringClass() {
079:                assertEquals(Sample.class, moe.getDeclaringClass());
080:            }
081:
082:            /**
083:             * @tests java.lang.Enum#hashCode()
084:             */
085:            public void test_hashCode() {
086:                assertEquals(moe.hashCode(), moe.hashCode());
087:            }
088:
089:            /**
090:             * @tests java.lang.Enum#name()
091:             */
092:            public void test_name() {
093:                assertEquals("MOE", moe.name());
094:            }
095:
096:            /**
097:             * @tests java.lang.Enum#ordinal()
098:             */
099:            public void test_ordinal() {
100:                assertEquals(0, larry.ordinal());
101:                assertEquals(1, moe.ordinal());
102:                assertEquals(2, Sample.CURLY.ordinal());
103:            }
104:
105:            /**
106:             * @tests java.lang.Enum#toString()
107:             */
108:            public void test_toString() {
109:                assertTrue(moe.toString().equals("MOE"));
110:            }
111:
112:            /**
113:             * @tests java.lang.Enum#valueOf(Class, String)
114:             */
115:            public void test_valueOfLjava_lang_String() {
116:                assertSame(Sample.CURLY, Sample.valueOf("CURLY"));
117:                assertSame(Sample.LARRY, Sample.valueOf("LARRY"));
118:                assertSame(moe, Sample.valueOf("MOE"));
119:                try {
120:                    Sample.valueOf("non-existant");
121:                    fail("Expected an exception");
122:                } catch (IllegalArgumentException e) {
123:                    // Expected
124:                }
125:                try {
126:                    Sample.valueOf(null);
127:                    fail("Should throw NullPointerException");
128:                } catch (NullPointerException e) {
129:                    // May be caused by some compilers' code
130:                } catch (IllegalArgumentException e) {
131:                    // other compilers will throw this
132:                }
133:
134:                Sample s = Enum.valueOf(Sample.class, "CURLY");
135:                assertSame(s, Sample.CURLY);
136:                s = Enum.valueOf(Sample.class, "LARRY");
137:                assertSame(larry, s);
138:                s = Enum.valueOf(Sample.class, "MOE");
139:                assertSame(s, moe);
140:                try {
141:                    Enum.valueOf(Bogus.class, "MOE");
142:                    fail("Expected IllegalArgumentException");
143:                } catch (IllegalArgumentException e) {
144:                    // Expected
145:                }
146:                try {
147:                    Enum.valueOf((Class<Sample>) null, "a string");
148:                    fail("Expected an exception");
149:                } catch (NullPointerException e) {
150:                    // May be caused by some compilers' code
151:                } catch (IllegalArgumentException e) {
152:                    // other compilers will throw this
153:                }
154:                try {
155:                    Enum.valueOf(Sample.class, null);
156:                    fail("Expected an exception");
157:                } catch (NullPointerException e) {
158:                    // May be caused by some compilers' code
159:                } catch (IllegalArgumentException e) {
160:                    // other compilers will throw this
161:                }
162:                try {
163:                    Enum.valueOf((Class<Sample>) null, (String) null);
164:                    fail("Expected an exception");
165:                } catch (NullPointerException e) {
166:                    // May be caused by some compilers' code
167:                } catch (IllegalArgumentException e) {
168:                    // other compilers will throw this
169:                }
170:            }
171:
172:            /**
173:             * @tests java.lang.Enum#values
174:             */
175:            public void test_values() {
176:                Sample[] myValues = Sample.values();
177:                assertEquals(3, myValues.length);
178:
179:                assertEquals(Sample.LARRY, myValues[0]);
180:                assertEquals(Sample.MOE, myValues[1]);
181:                assertEquals(Sample.CURLY, myValues[2]);
182:
183:                assertEquals(0, Empty.values().length);
184:            }
185:
186:            /**
187:             * @test Serialization/deserilazation compatibility with Harmony.
188:             */
189:            public void test_compatibilitySerialization_inClass_Complex_Harmony()
190:                    throws Exception {
191:                // TODO migrate to the new testing framework 
192:                assertTrue(SerializationTester
193:                        .assertCompabilityEquals(new MockEnum2(),
194:                                "serialization/org/apache/harmony/luni/tests/java/lang/EnumTest.harmony.ser"));
195:            }
196:
197:            /**
198:             * @tests serialization/deserialization compatibility.
199:             */
200:            public void testSerializationSelf() throws Exception {
201:
202:                // test a map class that has enums.
203:                // regression test for Harmony-1163
204:                HashMap<Color, Integer> enumColorMap = new HashMap<Color, Integer>();
205:                enumColorMap.put(Color.Red, 1);
206:                enumColorMap.put(Color.Blue, 3);
207:
208:                Object[] testCases = { enumColorMap, Sample.CURLY };
209:
210:                SerializationTest.verifySelf(testCases);
211:
212:                // test a class that has enums as its fields.
213:                MockEnum mock = new MockEnum();
214:                MockEnum test = (MockEnum) SerializationTest
215:                        .copySerializable(mock);
216:                assertEquals(mock.i, test.i);
217:                assertEquals(mock.str, test.str);
218:                assertEquals(mock.samEnum, test.samEnum);
219:
220:                // test a class that has enums and a string of same name as its fields.
221:                MockEnum2 mock2 = new MockEnum2();
222:                MockEnum2 test2 = (MockEnum2) SerializationTest
223:                        .copySerializable(mock2);
224:                assertEquals(mock2.i, test2.i);
225:                assertEquals(mock2.str, test2.str);
226:                assertEquals(mock2.samEnum, test2.samEnum);
227:            }
228:
229:            /**
230:             * @tests serialization/deserialization compatibility with RI.
231:             */
232:            public void testSerializationCompatibility() throws Exception {
233:
234:                // regression test for Harmony-1163
235:                HashMap<Color, Integer> enumColorMap = new HashMap<Color, Integer>();
236:                enumColorMap.put(Color.Red, 1);
237:                enumColorMap.put(Color.Blue, 3);
238:
239:                Object[] testCases = { Sample.CURLY, new MockEnum(),
240:                // test a class that has enums and a string of same name as its fields.
241:                        new MockEnum2(),
242:                        // test a map class that has enums.
243:                        enumColorMap, };
244:
245:                SerializationTest.verifyGolden(this, testCases);
246:            }
247:        }
www___._j__a___va_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.