Source Code Cross Referenced for SystemUtilsTest.java in  » Library » Apache-common-lang » org » apache » commons » 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 » Library » Apache common lang » org.apache.commons.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:
020:        package org.apache.commons.lang;
021:
022:        import java.io.File;
023:        import java.lang.reflect.Constructor;
024:        import java.lang.reflect.Modifier;
025:        import junit.framework.Assert;
026:        import junit.framework.Test;
027:        import junit.framework.TestCase;
028:        import junit.framework.TestSuite;
029:        import junit.textui.TestRunner;
030:
031:        /**
032:         * Unit tests {@link org.apache.commons.lang.SystemUtils}.
033:         * 
034:         * Only limited testing can be performed.
035:         * 
036:         * @author Stephen Colebourne
037:         * @author Tetsuya Kaneuchi
038:         * @author Gary D. Gregory
039:         * @version $Id: SystemUtilsTest.java 437554 2006-08-28 06:21:41Z bayard $
040:         */
041:        public class SystemUtilsTest extends TestCase {
042:            public static void main(String[] args) {
043:                TestRunner.run(suite());
044:            }
045:
046:            public static Test suite() {
047:                TestSuite suite = new TestSuite(SystemUtilsTest.class);
048:                suite.setName("SystemUtils Tests");
049:                return suite;
050:            }
051:
052:            //-----------------------------------------------------------------------
053:            // COPIED FROM SystemUtils
054:            //-----------------------------------------------------------------------
055:            private String JAVA_VERSION;
056:
057:            private String JAVA_VERSION_TRIMMED;
058:
059:            private String OS_NAME;
060:
061:            private String OS_VERSION;
062:
063:            public SystemUtilsTest(String name) {
064:                super (name);
065:            }
066:
067:            /**
068:             * <p>Gets the Java version number as a <code>float</code>.</p>
069:             *
070:             * <p>Example return values:</p>
071:             * <ul>
072:             *  <li><code>1.2f</code> for JDK 1.2
073:             *  <li><code>1.31f</code> for JDK 1.3.1
074:             * </ul>
075:             * 
076:             * <p>Patch releases are not reported.
077:             * Zero is returned if {@link #JAVA_VERSION_TRIMMED} is <code>null</code>.</p>
078:             * 
079:             * @return the version, for example 1.31f for JDK 1.3.1
080:             */
081:            private float getJavaVersionAsFloat() {
082:                if (JAVA_VERSION_TRIMMED == null) {
083:                    return 0f;
084:                }
085:                String str = JAVA_VERSION_TRIMMED.substring(0, 3);
086:                if (JAVA_VERSION_TRIMMED.length() >= 5) {
087:                    str = str + JAVA_VERSION_TRIMMED.substring(4, 5);
088:                }
089:                try {
090:                    return Float.parseFloat(str);
091:                } catch (Exception ex) {
092:                    return 0;
093:                }
094:            }
095:
096:            /**
097:             * <p>Gets the Java version number as an <code>int</code>.</p>
098:             *
099:             * <p>Example return values:</p>
100:             * <ul>
101:             *  <li><code>120</code> for JDK 1.2
102:             *  <li><code>131</code> for JDK 1.3.1
103:             * </ul>
104:             * 
105:             * <p>Patch releases are not reported.
106:             * Zero is returned if {@link #JAVA_VERSION_TRIMMED} is <code>null</code>.</p>
107:             * 
108:             * @return the version, for example 131 for JDK 1.3.1
109:             */
110:            private int getJavaVersionAsInt() {
111:                if (JAVA_VERSION == null) {
112:                    return 0;
113:                }
114:                String str = JAVA_VERSION_TRIMMED.substring(0, 1);
115:                str = str + JAVA_VERSION_TRIMMED.substring(2, 3);
116:                if (JAVA_VERSION_TRIMMED.length() >= 5) {
117:                    str = str + JAVA_VERSION_TRIMMED.substring(4, 5);
118:                } else {
119:                    str = str + "0";
120:                }
121:                try {
122:                    return Integer.parseInt(str);
123:                } catch (Exception ex) {
124:                    return 0;
125:                }
126:            }
127:
128:            /**
129:             * Trims the text of the java version to start with numbers.
130:             * 
131:             * @return the trimmed java version
132:             */
133:            private String getJavaVersionTrimmed() {
134:                if (JAVA_VERSION != null) {
135:                    for (int i = 0; i < JAVA_VERSION.length(); i++) {
136:                        char ch = JAVA_VERSION.charAt(i);
137:                        if (ch >= '0' && ch <= '9') {
138:                            return JAVA_VERSION.substring(i);
139:                        }
140:                    }
141:                }
142:                return null;
143:            }
144:
145:            /**
146:             * Decides if the java version matches.
147:             * 
148:             * @param versionPrefix
149:             *                  the prefix for the java version
150:             * @return true if matches, or false if not or can't determine
151:             */
152:            private boolean getJavaVersionMatches(String versionPrefix) {
153:                if (JAVA_VERSION_TRIMMED == null) {
154:                    return false;
155:                }
156:                return JAVA_VERSION_TRIMMED.startsWith(versionPrefix);
157:            }
158:
159:            /**
160:             * Decides if the operating system matches.
161:             * 
162:             * @param osNamePrefix
163:             *                  the prefix for the os name
164:             * @return true if matches, or false if not or can't determine
165:             */
166:            private boolean getOSMatches(String osNamePrefix) {
167:                if (OS_NAME == null) {
168:                    return false;
169:                }
170:                return OS_NAME.startsWith(osNamePrefix);
171:            }
172:
173:            /**
174:             * Decides if the operating system matches.
175:             * 
176:             * @param osNamePrefix
177:             *                  the prefix for the os name
178:             * @param osVersionPrefix
179:             *                  the prefix for the version
180:             * @return true if matches, or false if not or can't determine
181:             */
182:            private boolean getOSMatches(String osNamePrefix,
183:                    String osVersionPrefix) {
184:                if (OS_NAME == null || OS_VERSION == null) {
185:                    return false;
186:                }
187:                return OS_NAME.startsWith(osNamePrefix)
188:                        && OS_VERSION.startsWith(osVersionPrefix);
189:            }
190:
191:            protected void setUp() throws Exception {
192:                super .setUp();
193:            }
194:
195:            protected void tearDown() throws Exception {
196:                super .tearDown();
197:            }
198:
199:            //-----------------------------------------------------------------------
200:            public void testConstructor() {
201:                assertNotNull(new SystemUtils());
202:                Constructor[] cons = SystemUtils.class
203:                        .getDeclaredConstructors();
204:                assertEquals(1, cons.length);
205:                assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
206:                assertEquals(true, Modifier.isPublic(SystemUtils.class
207:                        .getModifiers()));
208:                assertEquals(false, Modifier.isFinal(SystemUtils.class
209:                        .getModifiers()));
210:            }
211:
212:            /**
213:             * Assums no security manager exists.
214:             */
215:            public void testGetJavaHome() {
216:                File dir = SystemUtils.getJavaHome();
217:                Assert.assertNotNull(dir);
218:                Assert.assertTrue(dir.exists());
219:            }
220:
221:            /**
222:             * Assums no security manager exists.
223:             */
224:            public void testGetJavaIoTmpDir() {
225:                File dir = SystemUtils.getJavaIoTmpDir();
226:                Assert.assertNotNull(dir);
227:                Assert.assertTrue(dir.exists());
228:            }
229:
230:            /**
231:             * Assums no security manager exists.
232:             */
233:            public void testGetUserDir() {
234:                File dir = SystemUtils.getUserDir();
235:                Assert.assertNotNull(dir);
236:                Assert.assertTrue(dir.exists());
237:            }
238:
239:            /**
240:             * Assums no security manager exists.
241:             */
242:            public void testGetUserHome() {
243:                File dir = SystemUtils.getUserHome();
244:                Assert.assertNotNull(dir);
245:                Assert.assertTrue(dir.exists());
246:            }
247:
248:            public void testIS_JAVA() {
249:                String javaVersion = System.getProperty("java.version");
250:                if (javaVersion == null) {
251:                    assertEquals(false, SystemUtils.IS_JAVA_1_1);
252:                    assertEquals(false, SystemUtils.IS_JAVA_1_2);
253:                    assertEquals(false, SystemUtils.IS_JAVA_1_3);
254:                    assertEquals(false, SystemUtils.IS_JAVA_1_4);
255:                    assertEquals(false, SystemUtils.IS_JAVA_1_5);
256:                    assertEquals(false, SystemUtils.IS_JAVA_1_6);
257:                } else if (javaVersion.startsWith("1.1")) {
258:                    assertEquals(true, SystemUtils.IS_JAVA_1_1);
259:                    assertEquals(false, SystemUtils.IS_JAVA_1_2);
260:                    assertEquals(false, SystemUtils.IS_JAVA_1_3);
261:                    assertEquals(false, SystemUtils.IS_JAVA_1_4);
262:                    assertEquals(false, SystemUtils.IS_JAVA_1_5);
263:                    assertEquals(false, SystemUtils.IS_JAVA_1_6);
264:                } else if (javaVersion.startsWith("1.2")) {
265:                    assertEquals(false, SystemUtils.IS_JAVA_1_1);
266:                    assertEquals(true, SystemUtils.IS_JAVA_1_2);
267:                    assertEquals(false, SystemUtils.IS_JAVA_1_3);
268:                    assertEquals(false, SystemUtils.IS_JAVA_1_4);
269:                    assertEquals(false, SystemUtils.IS_JAVA_1_5);
270:                    assertEquals(false, SystemUtils.IS_JAVA_1_6);
271:                } else if (javaVersion.startsWith("1.3")) {
272:                    assertEquals(false, SystemUtils.IS_JAVA_1_1);
273:                    assertEquals(false, SystemUtils.IS_JAVA_1_2);
274:                    assertEquals(true, SystemUtils.IS_JAVA_1_3);
275:                    assertEquals(false, SystemUtils.IS_JAVA_1_4);
276:                    assertEquals(false, SystemUtils.IS_JAVA_1_5);
277:                    assertEquals(false, SystemUtils.IS_JAVA_1_6);
278:                } else if (javaVersion.startsWith("1.4")) {
279:                    assertEquals(false, SystemUtils.IS_JAVA_1_1);
280:                    assertEquals(false, SystemUtils.IS_JAVA_1_2);
281:                    assertEquals(false, SystemUtils.IS_JAVA_1_3);
282:                    assertEquals(true, SystemUtils.IS_JAVA_1_4);
283:                    assertEquals(false, SystemUtils.IS_JAVA_1_5);
284:                    assertEquals(false, SystemUtils.IS_JAVA_1_6);
285:                } else if (javaVersion.startsWith("1.5")) {
286:                    assertEquals(false, SystemUtils.IS_JAVA_1_1);
287:                    assertEquals(false, SystemUtils.IS_JAVA_1_2);
288:                    assertEquals(false, SystemUtils.IS_JAVA_1_3);
289:                    assertEquals(false, SystemUtils.IS_JAVA_1_4);
290:                    assertEquals(true, SystemUtils.IS_JAVA_1_5);
291:                    assertEquals(false, SystemUtils.IS_JAVA_1_6);
292:                } else if (javaVersion.startsWith("1.6")) {
293:                    assertEquals(false, SystemUtils.IS_JAVA_1_1);
294:                    assertEquals(false, SystemUtils.IS_JAVA_1_2);
295:                    assertEquals(false, SystemUtils.IS_JAVA_1_3);
296:                    assertEquals(false, SystemUtils.IS_JAVA_1_4);
297:                    assertEquals(false, SystemUtils.IS_JAVA_1_5);
298:                    assertEquals(true, SystemUtils.IS_JAVA_1_6);
299:                } else {
300:                    System.out.println("Can't test IS_JAVA value");
301:                }
302:            }
303:
304:            public void testIS_OS() {
305:                String osName = System.getProperty("os.name");
306:                if (osName == null) {
307:                    assertEquals(false, SystemUtils.IS_OS_WINDOWS);
308:                    assertEquals(false, SystemUtils.IS_OS_UNIX);
309:                    assertEquals(false, SystemUtils.IS_OS_SOLARIS);
310:                    assertEquals(false, SystemUtils.IS_OS_LINUX);
311:                    assertEquals(false, SystemUtils.IS_OS_MAC_OSX);
312:                } else if (osName.startsWith("Windows")) {
313:                    assertEquals(false, SystemUtils.IS_OS_UNIX);
314:                    assertEquals(true, SystemUtils.IS_OS_WINDOWS);
315:                } else if (osName.startsWith("Solaris")) {
316:                    assertEquals(true, SystemUtils.IS_OS_SOLARIS);
317:                    assertEquals(true, SystemUtils.IS_OS_UNIX);
318:                    assertEquals(false, SystemUtils.IS_OS_WINDOWS);
319:                } else if (osName.toLowerCase().startsWith("linux")) {
320:                    assertEquals(true, SystemUtils.IS_OS_LINUX);
321:                    assertEquals(true, SystemUtils.IS_OS_UNIX);
322:                    assertEquals(false, SystemUtils.IS_OS_WINDOWS);
323:                } else if (osName.startsWith("Mac OS X")) {
324:                    assertEquals(true, SystemUtils.IS_OS_MAC_OSX);
325:                    assertEquals(true, SystemUtils.IS_OS_UNIX);
326:                    assertEquals(false, SystemUtils.IS_OS_WINDOWS);
327:                } else if (osName.startsWith("OS/2")) {
328:                    assertEquals(true, SystemUtils.IS_OS_OS2);
329:                    assertEquals(false, SystemUtils.IS_OS_UNIX);
330:                    assertEquals(false, SystemUtils.IS_OS_WINDOWS);
331:                } else if (osName.startsWith("SunOS")) {
332:                    assertEquals(true, SystemUtils.IS_OS_SUN_OS);
333:                    assertEquals(true, SystemUtils.IS_OS_UNIX);
334:                    assertEquals(false, SystemUtils.IS_OS_WINDOWS);
335:                } else {
336:                    System.out.println("Can't test IS_OS value");
337:                }
338:            }
339:
340:            //-----------------------------------------------------------------------
341:            public void testJavaVersion() {
342:                assertEquals(SystemUtils.JAVA_VERSION_FLOAT, SystemUtils
343:                        .getJavaVersion(), 0f);
344:            }
345:
346:            public void testJavaVersionAsFloat() {
347:                JAVA_VERSION = null;
348:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
349:                assertEquals(0f, getJavaVersionAsFloat(), 0.000001f);
350:                JAVA_VERSION = "1.1";
351:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
352:                assertEquals(1.1f, getJavaVersionAsFloat(), 0.000001f);
353:                JAVA_VERSION = "1.2";
354:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
355:                assertEquals(1.2f, getJavaVersionAsFloat(), 0.000001f);
356:                JAVA_VERSION = "1.3.0";
357:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
358:                assertEquals(1.3f, getJavaVersionAsFloat(), 0.000001f);
359:                JAVA_VERSION = "1.3.1";
360:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
361:                assertEquals(1.31f, getJavaVersionAsFloat(), 0.000001f);
362:                JAVA_VERSION = "1.4.0";
363:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
364:                assertEquals(1.4f, getJavaVersionAsFloat(), 0.000001f);
365:                JAVA_VERSION = "1.4.1";
366:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
367:                assertEquals(1.41f, getJavaVersionAsFloat(), 0.000001f);
368:                JAVA_VERSION = "1.5.0";
369:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
370:                assertEquals(1.5f, getJavaVersionAsFloat(), 0.000001f);
371:                JAVA_VERSION = "1.6.0";
372:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
373:                assertEquals(1.6f, getJavaVersionAsFloat(), 0.000001f);
374:                JAVA_VERSION = "JavaVM-1.3.1"; //HP-UX
375:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
376:                assertEquals(1.31f, getJavaVersionAsFloat(), 0.000001f);
377:                JAVA_VERSION = "XXX-1.3.x"; //error
378:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
379:                assertEquals(0.0f, getJavaVersionAsFloat(), 0.000001f);
380:            }
381:
382:            public void testJavaVersionAsInt() {
383:                JAVA_VERSION = null;
384:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
385:                assertEquals(0, getJavaVersionAsInt());
386:                JAVA_VERSION = "1.1";
387:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
388:                assertEquals(110, getJavaVersionAsInt());
389:                JAVA_VERSION = "1.2";
390:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
391:                assertEquals(120, getJavaVersionAsInt());
392:                JAVA_VERSION = "1.3.0";
393:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
394:                assertEquals(130, getJavaVersionAsInt());
395:                JAVA_VERSION = "1.3.1";
396:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
397:                assertEquals(131, getJavaVersionAsInt());
398:                JAVA_VERSION = "1.4.0";
399:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
400:                assertEquals(140, getJavaVersionAsInt());
401:                JAVA_VERSION = "1.4.1";
402:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
403:                assertEquals(141, getJavaVersionAsInt());
404:                JAVA_VERSION = "1.5.0";
405:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
406:                assertEquals(150, getJavaVersionAsInt());
407:                JAVA_VERSION = "1.6.0";
408:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
409:                assertEquals(160, getJavaVersionAsInt());
410:                JAVA_VERSION = "JavaVM-1.3.1"; //HP-UX
411:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
412:                assertEquals(131, getJavaVersionAsInt());
413:                JAVA_VERSION = "XXX-1.3.x"; //error
414:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
415:                assertEquals(0, getJavaVersionAsInt());
416:            }
417:
418:            public void testJavaVersionAtLeastFloat() {
419:                float version = SystemUtils.JAVA_VERSION_FLOAT;
420:                assertEquals(true, SystemUtils.isJavaVersionAtLeast(version));
421:                version -= 0.1f;
422:                assertEquals(true, SystemUtils.isJavaVersionAtLeast(version));
423:                version += 0.2f;
424:                assertEquals(false, SystemUtils.isJavaVersionAtLeast(version));
425:            }
426:
427:            public void testJavaVersionAtLeastInt() {
428:                int version = SystemUtils.JAVA_VERSION_INT;
429:                assertEquals(true, SystemUtils.isJavaVersionAtLeast(version));
430:                version -= 10;
431:                assertEquals(true, SystemUtils.isJavaVersionAtLeast(version));
432:                version += 20;
433:                assertEquals(false, SystemUtils.isJavaVersionAtLeast(version));
434:            }
435:
436:            //-----------------------------------------------------------------------
437:            public void testJavaVersionMatches() {
438:                JAVA_VERSION = null;
439:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
440:                assertEquals(false, getJavaVersionMatches("1.1"));
441:                assertEquals(false, getJavaVersionMatches("1.2"));
442:                assertEquals(false, getJavaVersionMatches("1.3"));
443:                assertEquals(false, getJavaVersionMatches("1.4"));
444:                assertEquals(false, getJavaVersionMatches("1.5"));
445:                JAVA_VERSION = "1.1";
446:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
447:                assertEquals(true, getJavaVersionMatches("1.1"));
448:                assertEquals(false, getJavaVersionMatches("1.2"));
449:                assertEquals(false, getJavaVersionMatches("1.3"));
450:                assertEquals(false, getJavaVersionMatches("1.4"));
451:                assertEquals(false, getJavaVersionMatches("1.5"));
452:                JAVA_VERSION = "1.2";
453:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
454:                assertEquals(false, getJavaVersionMatches("1.1"));
455:                assertEquals(true, getJavaVersionMatches("1.2"));
456:                assertEquals(false, getJavaVersionMatches("1.3"));
457:                assertEquals(false, getJavaVersionMatches("1.4"));
458:                assertEquals(false, getJavaVersionMatches("1.5"));
459:                JAVA_VERSION = "1.3.0";
460:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
461:                assertEquals(false, getJavaVersionMatches("1.1"));
462:                assertEquals(false, getJavaVersionMatches("1.2"));
463:                assertEquals(true, getJavaVersionMatches("1.3"));
464:                assertEquals(false, getJavaVersionMatches("1.4"));
465:                assertEquals(false, getJavaVersionMatches("1.5"));
466:                JAVA_VERSION = "1.3.1";
467:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
468:                assertEquals(false, getJavaVersionMatches("1.1"));
469:                assertEquals(false, getJavaVersionMatches("1.2"));
470:                assertEquals(true, getJavaVersionMatches("1.3"));
471:                assertEquals(false, getJavaVersionMatches("1.4"));
472:                assertEquals(false, getJavaVersionMatches("1.5"));
473:                JAVA_VERSION = "1.4.0";
474:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
475:                assertEquals(false, getJavaVersionMatches("1.1"));
476:                assertEquals(false, getJavaVersionMatches("1.2"));
477:                assertEquals(false, getJavaVersionMatches("1.3"));
478:                assertEquals(true, getJavaVersionMatches("1.4"));
479:                assertEquals(false, getJavaVersionMatches("1.5"));
480:                JAVA_VERSION = "1.4.1";
481:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
482:                assertEquals(false, getJavaVersionMatches("1.1"));
483:                assertEquals(false, getJavaVersionMatches("1.2"));
484:                assertEquals(false, getJavaVersionMatches("1.3"));
485:                assertEquals(true, getJavaVersionMatches("1.4"));
486:                assertEquals(false, getJavaVersionMatches("1.5"));
487:                JAVA_VERSION = "1.5.0";
488:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
489:                assertEquals(false, getJavaVersionMatches("1.1"));
490:                assertEquals(false, getJavaVersionMatches("1.2"));
491:                assertEquals(false, getJavaVersionMatches("1.3"));
492:                assertEquals(false, getJavaVersionMatches("1.4"));
493:                assertEquals(true, getJavaVersionMatches("1.5"));
494:                JAVA_VERSION = "1.6.0";
495:                JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
496:                assertEquals(false, getJavaVersionMatches("1.1"));
497:                assertEquals(false, getJavaVersionMatches("1.2"));
498:                assertEquals(false, getJavaVersionMatches("1.3"));
499:                assertEquals(false, getJavaVersionMatches("1.4"));
500:                assertEquals(false, getJavaVersionMatches("1.5"));
501:            }
502:
503:            public void testOSMatches() {
504:                OS_NAME = null;
505:                assertEquals(false, getOSMatches("Windows"));
506:                OS_NAME = "Windows 95";
507:                assertEquals(true, getOSMatches("Windows"));
508:                OS_NAME = "Windows NT";
509:                assertEquals(true, getOSMatches("Windows"));
510:                OS_NAME = "OS/2";
511:                assertEquals(false, getOSMatches("Windows"));
512:            }
513:
514:            public void testOSMatches2() {
515:                OS_NAME = null;
516:                OS_VERSION = null;
517:                assertEquals(false, getOSMatches("Windows 9", "4.1"));
518:                OS_NAME = "Windows 95";
519:                OS_VERSION = "4.0";
520:                assertEquals(false, getOSMatches("Windows 9", "4.1"));
521:                OS_NAME = "Windows 95";
522:                OS_VERSION = "4.1";
523:                assertEquals(true, getOSMatches("Windows 9", "4.1"));
524:                OS_NAME = "Windows 98";
525:                OS_VERSION = "4.1";
526:                assertEquals(true, getOSMatches("Windows 9", "4.1"));
527:                OS_NAME = "Windows NT";
528:                OS_VERSION = "4.0";
529:                assertEquals(false, getOSMatches("Windows 9", "4.1"));
530:                OS_NAME = "OS/2";
531:                OS_VERSION = "4.0";
532:                assertEquals(false, getOSMatches("Windows 9", "4.1"));
533:            }
534:
535:            public void testJavaAwtHeadless() {
536:                boolean atLeastJava14 = SystemUtils.isJavaVersionAtLeast(140);
537:                String expectedStringValue = System
538:                        .getProperty("java.awt.headless");
539:                String expectedStringValueWithDefault = System.getProperty(
540:                        "java.awt.headless", "false");
541:                assertNotNull(expectedStringValueWithDefault);
542:                if (atLeastJava14) {
543:                    boolean expectedValue = Boolean
544:                            .valueOf(expectedStringValue).booleanValue();
545:                    if (expectedStringValue != null) {
546:                        assertEquals(expectedStringValue,
547:                                SystemUtils.JAVA_AWT_HEADLESS);
548:                    }
549:                    assertEquals(expectedValue, SystemUtils.isJavaAwtHeadless());
550:                } else {
551:                    assertNull(expectedStringValue);
552:                    assertNull(SystemUtils.JAVA_AWT_HEADLESS);
553:                    assertEquals(expectedStringValueWithDefault, ""
554:                            + SystemUtils.isJavaAwtHeadless());
555:                }
556:                assertEquals(expectedStringValueWithDefault, ""
557:                        + SystemUtils.isJavaAwtHeadless());
558:            }
559:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.