commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang SystemUtilsTest.java
Date Wed, 31 Dec 2003 22:01:06 GMT
ggregory    2003/12/31 14:01:06

  Modified:    lang/src/test/org/apache/commons/lang SystemUtilsTest.java
  Log:
  PR: http://issues.apache.org/bugzilla/show_bug.cgi?id=25849
  Added to SystemUtils: getJavaHome, getJavaIoTmpDir, getUserDir, getUserHome.
  Sorted source (Eclispe).
  
  Revision  Changes    Path
  1.8       +191 -153  jakarta-commons/lang/src/test/org/apache/commons/lang/SystemUtilsTest.java
  
  Index: SystemUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/SystemUtilsTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SystemUtilsTest.java	7 Oct 2003 20:59:46 -0000	1.7
  +++ SystemUtilsTest.java	31 Dec 2003 22:01:06 -0000	1.8
  @@ -53,9 +53,11 @@
    */
   package org.apache.commons.lang;
   
  +import java.io.File;
   import java.lang.reflect.Constructor;
   import java.lang.reflect.Modifier;
   
  +import junit.framework.Assert;
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  @@ -68,14 +70,11 @@
    *
    * @author Stephen Colebourne
    * @author Tetsuya Kaneuchi
  + * @author Gary D. Gregory
    * @version $Id$
    */
   public class SystemUtilsTest extends TestCase {
   
  -    public SystemUtilsTest(String name) {
  -        super(name);
  -    }
  -
       public static void main(String[] args) {
           TestRunner.run(suite());
       }
  @@ -85,24 +84,6 @@
           suite.setName("SystemUtils Tests");
           return suite;
       }
  -
  -    protected void setUp() throws Exception {
  -        super.setUp();
  -    }
  -
  -    protected void tearDown() throws Exception {
  -        super.tearDown();
  -    }
  -
  -    //-----------------------------------------------------------------------
  -    public void testConstructor() {
  -        assertNotNull(new SystemUtils());
  -        Constructor[] cons = SystemUtils.class.getDeclaredConstructors();
  -        assertEquals(1, cons.length);
  -        assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
  -        assertEquals(true, Modifier.isPublic(SystemUtils.class.getModifiers()));
  -        assertEquals(false, Modifier.isFinal(SystemUtils.class.getModifiers()));
  -    }
       
       //-----------------------------------------------------------------------
       // COPIED FROM SystemUtils
  @@ -110,19 +91,10 @@
       private String JAVA_VERSION;
       private String OS_NAME;
       private String OS_VERSION;
  -    
  -    /**
  -     * Decides if the java version matches.
  -     * 
  -     * @param versionPrefix  the prefix for the java version
  -     * @return true if matches, or false if not or can't determine
  -     */
  -    private boolean getJavaVersionMatches(String versionPrefix) {
  -        if (JAVA_VERSION == null) {
  -            return false;
  -        }
  -        return JAVA_VERSION.startsWith(versionPrefix);
  -    }    
  +
  +    public SystemUtilsTest(String name) {
  +        super(name);
  +    }
   
       /**
        * <p>Get the Java version number as a <code>float</code>.</p>
  @@ -176,6 +148,19 @@
           }
           return Integer.parseInt(str);
       }
  +    
  +    /**
  +     * Decides if the java version matches.
  +     * 
  +     * @param versionPrefix  the prefix for the java version
  +     * @return true if matches, or false if not or can't determine
  +     */
  +    private boolean getJavaVersionMatches(String versionPrefix) {
  +        if (JAVA_VERSION == null) {
  +            return false;
  +        }
  +        return JAVA_VERSION.startsWith(versionPrefix);
  +    }    
   
       /**
        * Decides if the operating system matches.
  @@ -204,67 +189,122 @@
           return OS_NAME.startsWith(osNamePrefix) && OS_VERSION.startsWith(osVersionPrefix);
       }    
   
  +    protected void setUp() throws Exception {
  +        super.setUp();
  +    }
  +
  +    protected void tearDown() throws Exception {
  +        super.tearDown();
  +    }
  +
       //-----------------------------------------------------------------------
  -    public void testJavaVersion() {
  -        assertEquals(SystemUtils.JAVA_VERSION_FLOAT, SystemUtils.getJavaVersion(), 0f);
  +    public void testConstructor() {
  +        assertNotNull(new SystemUtils());
  +        Constructor[] cons = SystemUtils.class.getDeclaredConstructors();
  +        assertEquals(1, cons.length);
  +        assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
  +        assertEquals(true, Modifier.isPublic(SystemUtils.class.getModifiers()));
  +        assertEquals(false, Modifier.isFinal(SystemUtils.class.getModifiers()));
       }
       
  +    /**
  +     * Assums no security manager exists.
  +     */
  +    public void testGetJavaHome() {
  +        File dir = SystemUtils.getJavaHome();
  +        Assert.assertNotNull(dir);
  +        Assert.assertTrue(dir.exists());
  +    }
  +
  +    /**
  +     * Assums no security manager exists.
  +     */
  +    public void testGetJavaIoTmpDir() {
  +        File dir = SystemUtils.getJavaIoTmpDir();
  +        Assert.assertNotNull(dir);
  +        Assert.assertTrue(dir.exists());
  +    }
  +
  +    /**
  +     * Assums no security manager exists.
  +     */
  +    public void testGetUserDir() {
  +        File dir = SystemUtils.getUserDir();
  +        Assert.assertNotNull(dir);
  +        Assert.assertTrue(dir.exists());
  +    }
  +
  +    /**
  +     * Assums no security manager exists.
  +     */
  +    public void testGetUserHome() {
  +        File dir = SystemUtils.getUserHome();
  +        Assert.assertNotNull(dir);
  +        Assert.assertTrue(dir.exists());
  +    }
  +
  +    public void testIS_JAVA() {
  +        String javaVersion = System.getProperty("java.version");
  +        if (javaVersion == null) {
  +            assertEquals(false, SystemUtils.IS_JAVA_1_1);
  +            assertEquals(false, SystemUtils.IS_JAVA_1_2);
  +            assertEquals(false, SystemUtils.IS_JAVA_1_3);
  +            assertEquals(false, SystemUtils.IS_JAVA_1_4);
  +            assertEquals(false, SystemUtils.IS_JAVA_1_5);
  +        } else if (javaVersion.startsWith("1.1")) {
  +            assertTrue(SystemUtils.IS_JAVA_1_1);
  +        } else if (javaVersion.startsWith("1.2")) {
  +            assertTrue(SystemUtils.IS_JAVA_1_2);
  +        } else if (javaVersion.startsWith("1.3")) {
  +            assertTrue(SystemUtils.IS_JAVA_1_3);
  +        } else if (javaVersion.startsWith("1.4")) {
  +            assertTrue(SystemUtils.IS_JAVA_1_4);
  +        } else if (javaVersion.startsWith("1.5")) {
  +            assertTrue(SystemUtils.IS_JAVA_1_5);
  +        } else {
  +            System.out.println("Can't test IS_JAVA value");
  +        }
  +    }
  +
  +    public void testIS_OS() {
  +        String osName = System.getProperty("os.name");
  +        if (osName == null) {
  +            assertEquals(false, SystemUtils.IS_OS_WINDOWS);
  +            assertEquals(false, SystemUtils.IS_OS_UNIX);
  +            assertEquals(false, SystemUtils.IS_OS_SOLARIS);
  +            assertEquals(false, SystemUtils.IS_OS_LINUX);
  +            assertEquals(false, SystemUtils.IS_OS_MAC_OSX);
  +        } else if (osName.startsWith("Windows")) {
  +            assertEquals(false, SystemUtils.IS_OS_UNIX);
  +            assertEquals(true, SystemUtils.IS_OS_WINDOWS);
  +        } else if (osName.startsWith("Solaris")) {
  +            assertEquals(true, SystemUtils.IS_OS_SOLARIS);
  +            assertEquals(true, SystemUtils.IS_OS_UNIX);
  +            assertEquals(false, SystemUtils.IS_OS_WINDOWS);
  +        } else if (osName.toLowerCase().startsWith("linux")) {
  +            assertEquals(true, SystemUtils.IS_OS_LINUX);
  +            assertEquals(true, SystemUtils.IS_OS_UNIX);
  +            assertEquals(false, SystemUtils.IS_OS_WINDOWS);
  +        } else if (osName.startsWith("Mac OS X")) {
  +            assertEquals(true, SystemUtils.IS_OS_MAC_OSX);
  +            assertEquals(true, SystemUtils.IS_OS_UNIX);
  +            assertEquals(false, SystemUtils.IS_OS_WINDOWS);
  +        } else if (osName.startsWith("OS/2")) {
  +            assertEquals(true, SystemUtils.IS_OS_OS2);
  +            assertEquals(false, SystemUtils.IS_OS_UNIX);
  +            assertEquals(false, SystemUtils.IS_OS_WINDOWS);
  +        } else if (osName.startsWith("SunOS")) {
  +            assertEquals(true, SystemUtils.IS_OS_SUN_OS);
  +            assertEquals(true, SystemUtils.IS_OS_UNIX);
  +            assertEquals(false, SystemUtils.IS_OS_WINDOWS);
  +        } else {
  +            System.out.println("Can't test IS_OS value");
  +        }
  +    }
  +
       //-----------------------------------------------------------------------
  -    public void testJavaVersionMatches() {
  -        JAVA_VERSION = null;
  -        assertEquals(false, getJavaVersionMatches("1.1"));
  -        assertEquals(false, getJavaVersionMatches("1.2"));
  -        assertEquals(false, getJavaVersionMatches("1.3"));
  -        assertEquals(false, getJavaVersionMatches("1.4"));
  -        assertEquals(false, getJavaVersionMatches("1.5"));
  -        JAVA_VERSION = "1.1";
  -        assertEquals(true, getJavaVersionMatches("1.1"));
  -        assertEquals(false, getJavaVersionMatches("1.2"));
  -        assertEquals(false, getJavaVersionMatches("1.3"));
  -        assertEquals(false, getJavaVersionMatches("1.4"));
  -        assertEquals(false, getJavaVersionMatches("1.5"));
  -        JAVA_VERSION = "1.2";
  -        assertEquals(false, getJavaVersionMatches("1.1"));
  -        assertEquals(true, getJavaVersionMatches("1.2"));
  -        assertEquals(false, getJavaVersionMatches("1.3"));
  -        assertEquals(false, getJavaVersionMatches("1.4"));
  -        assertEquals(false, getJavaVersionMatches("1.5"));
  -        JAVA_VERSION = "1.3.0";
  -        assertEquals(false, getJavaVersionMatches("1.1"));
  -        assertEquals(false, getJavaVersionMatches("1.2"));
  -        assertEquals(true, getJavaVersionMatches("1.3"));
  -        assertEquals(false, getJavaVersionMatches("1.4"));
  -        assertEquals(false, getJavaVersionMatches("1.5"));
  -        JAVA_VERSION = "1.3.1";
  -        assertEquals(false, getJavaVersionMatches("1.1"));
  -        assertEquals(false, getJavaVersionMatches("1.2"));
  -        assertEquals(true, getJavaVersionMatches("1.3"));
  -        assertEquals(false, getJavaVersionMatches("1.4"));
  -        assertEquals(false, getJavaVersionMatches("1.5"));
  -        JAVA_VERSION = "1.4.0";
  -        assertEquals(false, getJavaVersionMatches("1.1"));
  -        assertEquals(false, getJavaVersionMatches("1.2"));
  -        assertEquals(false, getJavaVersionMatches("1.3"));
  -        assertEquals(true, getJavaVersionMatches("1.4"));
  -        assertEquals(false, getJavaVersionMatches("1.5"));
  -        JAVA_VERSION = "1.4.1";
  -        assertEquals(false, getJavaVersionMatches("1.1"));
  -        assertEquals(false, getJavaVersionMatches("1.2"));
  -        assertEquals(false, getJavaVersionMatches("1.3"));
  -        assertEquals(true, getJavaVersionMatches("1.4"));
  -        assertEquals(false, getJavaVersionMatches("1.5"));
  -        JAVA_VERSION = "1.5.0";
  -        assertEquals(false, getJavaVersionMatches("1.1"));
  -        assertEquals(false, getJavaVersionMatches("1.2"));
  -        assertEquals(false, getJavaVersionMatches("1.3"));
  -        assertEquals(false, getJavaVersionMatches("1.4"));
  -        assertEquals(true, getJavaVersionMatches("1.5"));
  -        JAVA_VERSION = "1.6.0";
  -        assertEquals(false, getJavaVersionMatches("1.1"));
  -        assertEquals(false, getJavaVersionMatches("1.2"));
  -        assertEquals(false, getJavaVersionMatches("1.3"));
  -        assertEquals(false, getJavaVersionMatches("1.4"));
  -        assertEquals(false, getJavaVersionMatches("1.5"));
  +    public void testJavaVersion() {
  +        assertEquals(SystemUtils.JAVA_VERSION_FLOAT, SystemUtils.getJavaVersion(), 0f);
       }
      
       public void testJavaVersionAsFloat() {
  @@ -327,6 +367,64 @@
           assertEquals(false, SystemUtils.isJavaVersionAtLeast(version));
       }
       
  +    //-----------------------------------------------------------------------
  +    public void testJavaVersionMatches() {
  +        JAVA_VERSION = null;
  +        assertEquals(false, getJavaVersionMatches("1.1"));
  +        assertEquals(false, getJavaVersionMatches("1.2"));
  +        assertEquals(false, getJavaVersionMatches("1.3"));
  +        assertEquals(false, getJavaVersionMatches("1.4"));
  +        assertEquals(false, getJavaVersionMatches("1.5"));
  +        JAVA_VERSION = "1.1";
  +        assertEquals(true, getJavaVersionMatches("1.1"));
  +        assertEquals(false, getJavaVersionMatches("1.2"));
  +        assertEquals(false, getJavaVersionMatches("1.3"));
  +        assertEquals(false, getJavaVersionMatches("1.4"));
  +        assertEquals(false, getJavaVersionMatches("1.5"));
  +        JAVA_VERSION = "1.2";
  +        assertEquals(false, getJavaVersionMatches("1.1"));
  +        assertEquals(true, getJavaVersionMatches("1.2"));
  +        assertEquals(false, getJavaVersionMatches("1.3"));
  +        assertEquals(false, getJavaVersionMatches("1.4"));
  +        assertEquals(false, getJavaVersionMatches("1.5"));
  +        JAVA_VERSION = "1.3.0";
  +        assertEquals(false, getJavaVersionMatches("1.1"));
  +        assertEquals(false, getJavaVersionMatches("1.2"));
  +        assertEquals(true, getJavaVersionMatches("1.3"));
  +        assertEquals(false, getJavaVersionMatches("1.4"));
  +        assertEquals(false, getJavaVersionMatches("1.5"));
  +        JAVA_VERSION = "1.3.1";
  +        assertEquals(false, getJavaVersionMatches("1.1"));
  +        assertEquals(false, getJavaVersionMatches("1.2"));
  +        assertEquals(true, getJavaVersionMatches("1.3"));
  +        assertEquals(false, getJavaVersionMatches("1.4"));
  +        assertEquals(false, getJavaVersionMatches("1.5"));
  +        JAVA_VERSION = "1.4.0";
  +        assertEquals(false, getJavaVersionMatches("1.1"));
  +        assertEquals(false, getJavaVersionMatches("1.2"));
  +        assertEquals(false, getJavaVersionMatches("1.3"));
  +        assertEquals(true, getJavaVersionMatches("1.4"));
  +        assertEquals(false, getJavaVersionMatches("1.5"));
  +        JAVA_VERSION = "1.4.1";
  +        assertEquals(false, getJavaVersionMatches("1.1"));
  +        assertEquals(false, getJavaVersionMatches("1.2"));
  +        assertEquals(false, getJavaVersionMatches("1.3"));
  +        assertEquals(true, getJavaVersionMatches("1.4"));
  +        assertEquals(false, getJavaVersionMatches("1.5"));
  +        JAVA_VERSION = "1.5.0";
  +        assertEquals(false, getJavaVersionMatches("1.1"));
  +        assertEquals(false, getJavaVersionMatches("1.2"));
  +        assertEquals(false, getJavaVersionMatches("1.3"));
  +        assertEquals(false, getJavaVersionMatches("1.4"));
  +        assertEquals(true, getJavaVersionMatches("1.5"));
  +        JAVA_VERSION = "1.6.0";
  +        assertEquals(false, getJavaVersionMatches("1.1"));
  +        assertEquals(false, getJavaVersionMatches("1.2"));
  +        assertEquals(false, getJavaVersionMatches("1.3"));
  +        assertEquals(false, getJavaVersionMatches("1.4"));
  +        assertEquals(false, getJavaVersionMatches("1.5"));
  +    }
  +    
       public void testOSMatches() {
           OS_NAME = null;
           assertEquals(false, getOSMatches("Windows"));
  @@ -358,64 +456,4 @@
           OS_VERSION = "4.0";
           assertEquals(false, getOSMatches("Windows 9", "4.1"));
       }
  -
  -    public void testIS_OS() {
  -        String osName = System.getProperty("os.name");
  -        if (osName == null) {
  -            assertEquals(false, SystemUtils.IS_OS_WINDOWS);
  -            assertEquals(false, SystemUtils.IS_OS_UNIX);
  -            assertEquals(false, SystemUtils.IS_OS_SOLARIS);
  -            assertEquals(false, SystemUtils.IS_OS_LINUX);
  -            assertEquals(false, SystemUtils.IS_OS_MAC_OSX);
  -        } else if (osName.startsWith("Windows")) {
  -            assertEquals(false, SystemUtils.IS_OS_UNIX);
  -            assertEquals(true, SystemUtils.IS_OS_WINDOWS);
  -        } else if (osName.startsWith("Solaris")) {
  -            assertEquals(true, SystemUtils.IS_OS_SOLARIS);
  -            assertEquals(true, SystemUtils.IS_OS_UNIX);
  -            assertEquals(false, SystemUtils.IS_OS_WINDOWS);
  -        } else if (osName.toLowerCase().startsWith("linux")) {
  -            assertEquals(true, SystemUtils.IS_OS_LINUX);
  -            assertEquals(true, SystemUtils.IS_OS_UNIX);
  -            assertEquals(false, SystemUtils.IS_OS_WINDOWS);
  -        } else if (osName.startsWith("Mac OS X")) {
  -            assertEquals(true, SystemUtils.IS_OS_MAC_OSX);
  -            assertEquals(true, SystemUtils.IS_OS_UNIX);
  -            assertEquals(false, SystemUtils.IS_OS_WINDOWS);
  -        } else if (osName.startsWith("OS/2")) {
  -            assertEquals(true, SystemUtils.IS_OS_OS2);
  -            assertEquals(false, SystemUtils.IS_OS_UNIX);
  -            assertEquals(false, SystemUtils.IS_OS_WINDOWS);
  -        } else if (osName.startsWith("SunOS")) {
  -            assertEquals(true, SystemUtils.IS_OS_SUN_OS);
  -            assertEquals(true, SystemUtils.IS_OS_UNIX);
  -            assertEquals(false, SystemUtils.IS_OS_WINDOWS);
  -        } else {
  -            System.out.println("Can't test IS_OS value");
  -        }
  -    }
  -
  -    public void testIS_JAVA() {
  -        String javaVersion = System.getProperty("java.version");
  -        if (javaVersion == null) {
  -            assertEquals(false, SystemUtils.IS_JAVA_1_1);
  -            assertEquals(false, SystemUtils.IS_JAVA_1_2);
  -            assertEquals(false, SystemUtils.IS_JAVA_1_3);
  -            assertEquals(false, SystemUtils.IS_JAVA_1_4);
  -            assertEquals(false, SystemUtils.IS_JAVA_1_5);
  -        } else if (javaVersion.startsWith("1.1")) {
  -            assertTrue(SystemUtils.IS_JAVA_1_1);
  -        } else if (javaVersion.startsWith("1.2")) {
  -            assertTrue(SystemUtils.IS_JAVA_1_2);
  -        } else if (javaVersion.startsWith("1.3")) {
  -            assertTrue(SystemUtils.IS_JAVA_1_3);
  -        } else if (javaVersion.startsWith("1.4")) {
  -            assertTrue(SystemUtils.IS_JAVA_1_4);
  -        } else if (javaVersion.startsWith("1.5")) {
  -            assertTrue(SystemUtils.IS_JAVA_1_5);
  -        } else {
  -            System.out.println("Can't test IS_JAVA value");
  -        }
  -    }
  -    
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message