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


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        /**
019:         * @author Serguei S.Zapreyev
020:         * @version $Revision$
021:         */package java.lang;
022:
023:        import junit.framework.TestCase;
024:
025:        /*
026:         * Created on 02.02.2006
027:         * 
028:         * This PackageTest class is used to test the Core API java.lang.Package
029:         * class
030:         *  
031:         */
032:
033:        public class PackageTest extends TestCase {
034:
035:            static String vendor = System.getProperty("java.vm.vendor");
036:
037:            /**
038:             *  
039:             */
040:            public void test_getImplementationTitle_V() {
041:                //System.out.println("test_getImplementationTitle_V");
042:                Package p = java.lang.Character.class.getPackage();
043:                if (p == null)
044:                    return;
045:                String s = p.getImplementationTitle();
046:                if (s == null)
047:                    return;
048:                if (vendor.equals("Sun Microsystems Inc.")) {
049:                    assertEquals("Error1: unexpected title:",
050:                            "Java Runtime Environment", s);
051:                } else if (vendor.equals("BEA Systems, Inc.")) {
052:                    assertEquals("Error2: unexpected title:", "...", s);
053:                } else if (vendor.equals("Apache Software Foundation")) {
054:                    assertEquals("Error3: unexpected title:", "Apache Harmony",
055:                            s);
056:                }
057:            }
058:
059:            /**
060:             *  
061:             */
062:            public void test_getImplementationVendor_V() {
063:                //System.out.println("test_getImplementationVendor_V");
064:                Package p = java.lang.Character.class.getPackage();
065:                if (p == null)
066:                    return;
067:                String s = p.getImplementationVendor();
068:                if (s == null)
069:                    return; // XXX:It's not explained by spec
070:                if (vendor.equals("Sun Microsystems Inc.")) {
071:                    assertEquals("Error1: unexpected vendor:",
072:                            "Sun Microsystems, Inc.", s);
073:                } else if (vendor.equals("BEA Systems, Inc.")) {
074:                    assertEquals("Error2: unexpected vendor:", "...", s);
075:                } else if (vendor.equals("Apache Software Foundation")) {
076:                    assertEquals("Error3: unexpected vendor:",
077:                            "The Apache Software Foundation", s);
078:                }
079:            }
080:
081:            /**
082:             *  
083:             */
084:            public void test_getImplementationVersion_V() {
085:                //System.out.println("test_getImplementationVersion_V");
086:                Package p = java.lang.Character.class.getPackage();
087:                if (p == null)
088:                    return;
089:                String s = p.getImplementationVersion();
090:                if (s == null)
091:                    return;
092:                assertTrue("unexpected implementation version: " + s, s
093:                        .matches("[[0-9]._]+"));
094:            }
095:
096:            /**
097:             *  
098:             */
099:            public void test_getName_V() {
100:                //System.out.println("test_getName_V");
101:                Package p = java.lang.Character.class.getPackage();
102:                if (p == null)
103:                    return;
104:                String s = p.getName();
105:                assertEquals("unexpected name", "java.lang", s);
106:            }
107:
108:            /**
109:             *  
110:             */
111:            public void test_getPackage_Str_1() {
112:                //System.out.println("test_getPackage_Str_1");
113:                assertNull("null expected", Package
114:                        .getPackage("ABSOLUTELY.UNKNOWN.PACKAGE"));
115:            }
116:
117:            /**
118:             *  
119:             */
120:            public void test_getPackage_Str_2() {
121:                //System.out.println("test_getPackage_Str_2");
122:                try {
123:                    Package.getPackage((String) null);
124:                    fail("NullPointerException should be thrown");
125:                } catch (NullPointerException _) {
126:                    return;
127:                }
128:            }
129:
130:            /**
131:             *  
132:             */
133:            public void test_getPackage_Str_3() {
134:                //System.out.println("test_getPackage_Str");
135:                Package p = Package.getPackage("java.lang");
136:                if (p == null)
137:                    return;
138:                String s = p.getName();
139:                assertEquals("unexpected package", "java.lang", s);
140:            }
141:
142:            /**
143:             *  
144:             */
145:            public void test_getPackages_V() {
146:                //System.out.println("test_getPackages_V");
147:                Package ap[] = Package.getPackages();
148:                for (int i = 0; i < ap.length; i++) {
149:                    if (ap[i].getName().indexOf("java.lang") != -1)
150:                        return;
151:                }
152:                fail("at least java.lang should be returned");
153:            }
154:
155:            /**
156:             *  
157:             */
158:            public void test_getSpecificationTitle_V() {
159:                //System.out.println("test_getSpecificationTitle_V");
160:                Package p = java.lang.Character.class.getPackage();
161:                if (p == null)
162:                    return;
163:                String s = p.getSpecificationTitle();
164:                if (s == null)
165:                    return;
166:                String specName = System.getProperty("java.specification.name");
167:                assertEquals("unexpected specification title:", specName, s);
168:            }
169:
170:            /**
171:             *  
172:             */
173:            public void test_getSpecificationVendor_V() {
174:                //System.out.println("test_getSpecificationVendor_V");
175:                Package p = java.lang.Character.class.getPackage();
176:                if (p == null)
177:                    return;
178:                String s = p.getSpecificationVendor();
179:                if (s == null)
180:                    return;
181:                assertEquals("unexpected specification vendor:",
182:                        "Sun Microsystems, Inc.", s);
183:            }
184:
185:            /**
186:             *  
187:             */
188:            public void test_getSpecificationVersion_V() {
189:                //System.out.println("test_getSpecificationVersion_V");
190:                Package p = java.lang.Character.class.getPackage();
191:                if (p == null)
192:                    return;
193:                String s = p.getSpecificationVersion();
194:                assertNotNull("spec version is null", s);
195:                if (s == null)
196:                    return;
197:                assertTrue("unexpected specification version: " + s, s
198:                        .matches("([0-9]+?\\.)\\*?[0-9]+?"));
199:            }
200:
201:            /**
202:             *  
203:             */
204:            public void test_hashCode_V() {
205:                //System.out.println("test_hashCode_V");
206:                Package p1 = java.lang.Character.class.getPackage();
207:                Package p2 = java.io.File.class.getPackage();
208:                if (p1 == null || p2 == null)
209:                    return;
210:                assertTrue("hash codes should differ", p1.hashCode() != p2
211:                        .hashCode());
212:            }
213:
214:            /**
215:             *  
216:             */
217:            public void test_isCompatibleWith_Str_1() {
218:                //System.out.println("test_isCompatibleWith_Str_1");
219:                Package p = Package.getPackage("java.lang");
220:                if (p == null)
221:                    return;
222:                try {
223:                    p.isCompatibleWith("");
224:                } catch (NumberFormatException _) {
225:                } catch (Throwable e) {
226:                    fail("unexpected error: " + e.toString());
227:                }
228:            }
229:
230:            /**
231:             *  
232:             */
233:            public void test_isCompatibleWith_Str_2() {
234:                //System.out.println("test_isCompatibleWith_Str_2");
235:                Package p = java.lang.Character.class.getPackage();
236:                if (p == null)
237:                    return;
238:                String s = p.getSpecificationVersion();
239:                if (s == null)
240:                    return;
241:                try {
242:                    assertTrue(
243:                            "should be compatible with its own spec version", p
244:                                    .isCompatibleWith(s));
245:                } catch (NumberFormatException _) {
246:                    fail("wrong version format");
247:                }
248:            }
249:
250:            /**
251:             *  
252:             */
253:            public void test_isSealed_V() {
254:                //System.out.println("test_isSealed_V");
255:                Package p1 = java.lang.Character.class.getPackage();
256:                Package p2 = java.lang.Void.class.getPackage();
257:                if (p1 == null || p2 == null)
258:                    return;
259:                assertEquals("values should be equal", p1.isSealed(), p2
260:                        .isSealed());
261:            }
262:
263:            /**
264:             *  
265:             */
266:            public void test_isSealed_URL_1() {
267:                //System.out.println("test_isSealed_URL_1");
268:                try {
269:                    Package p1 = java.lang.Character.class.getPackage();
270:                    Package p2 = java.lang.Void.class.getPackage();
271:                    if (p1 == null || p2 == null)
272:                        return;
273:                    java.net.URL url = new java.net.URL("http://intel.com/");
274:                    assertEquals("values should be equal", p1.isSealed(url), p2
275:                            .isSealed(url));
276:                } catch (java.net.MalformedURLException _) {
277:                    fail("unexpected MalformedURLException");
278:                }
279:            }
280:
281:            /**
282:             *  
283:             */
284:            public void test_isSealed_URL_2() {
285:                //System.out.println("test_isSealed_URL_2");
286:                try {
287:                    Package p = Package.getPackage("java.lang");
288:                    if (p == null)
289:                        return;
290:                    p.isSealed((java.net.URL) null);
291:                    fail("NullPointerException has not been thrown");
292:                } catch (NullPointerException _) {
293:                    return;
294:                }
295:            }
296:
297:            /**
298:             *  
299:             */
300:            public void test_toString_V() {
301:                //System.out.println("test_toString_V");
302:                Package p = PackageTest.class.getPackage();
303:                if (p == null)
304:                    return;
305:                //assertTrue("Error1"+p.toString(), p.toString().equals("package "+"
306:                // "+p.getName()+", "+p.getSpecificationTitle()+",
307:                // "+p.getImplementationVersion()));
308:                assertTrue("unexpected: package name must be printed: "
309:                        + p.toString(), p.toString().indexOf(
310:                        "package " + p.getName()) != -1);
311:            }
312:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.