commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang SystemUtilsTest.java LangTestSuite.java
Date Sat, 24 May 2003 12:11:02 GMT
scolebourne    2003/05/24 05:11:02

  Modified:    lang/src/test/org/apache/commons/lang LangTestSuite.java
  Added:       lang/src/test/org/apache/commons/lang SystemUtilsTest.java
  Log:
  Add SystemUtils tests
  
  Revision  Changes    Path
  1.18      +2 -1      jakarta-commons/lang/src/test/org/apache/commons/lang/LangTestSuite.java
  
  Index: LangTestSuite.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/LangTestSuite.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- LangTestSuite.java	24 May 2003 04:38:05 -0000	1.17
  +++ LangTestSuite.java	24 May 2003 12:11:02 -0000	1.18
  @@ -108,6 +108,7 @@
           suite.addTest(StringUtilsEqualsIndexOfTest.suite());
           suite.addTest(StringUtilsIsTest.suite());
           suite.addTest(StringEscapeUtilsTest.suite());
  +        suite.addTest(SystemUtilsTest.suite());
           suite.addTest(UnhandledExceptionTest.suite());
           suite.addTest(WordWrapUtilsTest.suite());
           return suite;
  
  
  
  1.1                  jakarta-commons/lang/src/test/org/apache/commons/lang/SystemUtilsTest.java
  
  Index: SystemUtilsTest.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.lang;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * Unit tests {@link org.apache.commons.lang.SystemUtils}.
   * 
   * Only limited testing can be performed.
   *
   * @author Stephen Colebourne
   * @version $Id: SystemUtilsTest.java,v 1.1 2003/05/24 12:11:02 scolebourne Exp $
   */
  public class SystemUtilsTest extends TestCase {
  
      public SystemUtilsTest(String name) {
          super(name);
      }
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          TestSuite suite = new TestSuite(SystemUtilsTest.class);
          suite.setName("SystemUtils Tests");
          return suite;
      }
  
      protected void setUp() throws Exception {
          super.setUp();
      }
  
      protected void tearDown() throws Exception {
          super.tearDown();
      }
  
      //-----------------------------------------------------------------------
      // COPIED FROM SystemUtils
      //-----------------------------------------------------------------------
      private String JAVA_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);
      }    
  
      /**
       * <p>Get the Java version number as a <code>float</code>.</p>
       *
       * <p>Example output:</p>
       * <ul>
       *  <li><code>1.2f</code> for JDK 1.2
       *  <li><code>1.31f</code> for JDK 1.3.1
       * </ul>
       * 
       * <p>Patch releases are not reported.
       * Zero is returned if JAVA_VERSION is <code>null</code>.</p>
       * 
       * @return the version, for example 1.31f for JDK 1.3.1
       */
      private float getJavaVersionAsFloat() {
          if (JAVA_VERSION == null) {
              return 0f;
          }
          String str = JAVA_VERSION.substring(0, 3);
          if (JAVA_VERSION.length() >= 5) {
              str = str + JAVA_VERSION.substring(4, 5);
          }
          return Float.parseFloat(str);
      }
      
      /**
       * <p>Get the Java version number as an <code>int</code>.</p>
       *
       * <p>Example output:</p>
       * <ul>
       *  <li><code>120</code> for JDK 1.2
       *  <li><code>131</code> for JDK 1.3.1
       * </ul>
       * 
       * <p>Patch releases are not reported.
       * Zero is returned if JAVA_VERSION is <code>null</code>.</p>
       * 
       * @return the version, for example 131 for JDK 1.3.1
       */
      private int getJavaVersionAsInt() {
          if (JAVA_VERSION == null) {
              return 0;
          }
          String str = JAVA_VERSION.substring(0, 1);
          str = str + JAVA_VERSION.substring(2, 3);
          if (JAVA_VERSION.length() >= 5) {
              str = str + JAVA_VERSION.substring(4, 5);
          } else {
              str = str + "0";
          }
          return Integer.parseInt(str);
      }
  
      //-----------------------------------------------------------------------
      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 testJavaVersionAsFloat() {
          JAVA_VERSION = null;
          assertEquals(0f, getJavaVersionAsFloat(), 0.000001f);
          JAVA_VERSION = "1.1";
          assertEquals(1.1f, getJavaVersionAsFloat(), 0.000001f);
          JAVA_VERSION = "1.2";
          assertEquals(1.2f, getJavaVersionAsFloat(), 0.000001f);
          JAVA_VERSION = "1.3.0";
          assertEquals(1.3f, getJavaVersionAsFloat(), 0.000001f);
          JAVA_VERSION = "1.3.1";
          assertEquals(1.31f, getJavaVersionAsFloat(), 0.000001f);
          JAVA_VERSION = "1.4.0";
          assertEquals(1.4f, getJavaVersionAsFloat(), 0.000001f);
          JAVA_VERSION = "1.4.1";
          assertEquals(1.41f, getJavaVersionAsFloat(), 0.000001f);
          JAVA_VERSION = "1.5.0";
          assertEquals(1.5f, getJavaVersionAsFloat(), 0.000001f);
          JAVA_VERSION = "1.6.0";
          assertEquals(1.6f, getJavaVersionAsFloat(), 0.000001f);
      }
      
      public void testJavaVersionAsInt() {
          JAVA_VERSION = null;
          assertEquals(0, getJavaVersionAsInt());
          JAVA_VERSION = "1.1";
          assertEquals(110, getJavaVersionAsInt());
          JAVA_VERSION = "1.2";
          assertEquals(120, getJavaVersionAsInt());
          JAVA_VERSION = "1.3.0";
          assertEquals(130, getJavaVersionAsInt());
          JAVA_VERSION = "1.3.1";
          assertEquals(131, getJavaVersionAsInt());
          JAVA_VERSION = "1.4.0";
          assertEquals(140, getJavaVersionAsInt());
          JAVA_VERSION = "1.4.1";
          assertEquals(141, getJavaVersionAsInt());
          JAVA_VERSION = "1.5.0";
          assertEquals(150, getJavaVersionAsInt());
          JAVA_VERSION = "1.6.0";
          assertEquals(160, getJavaVersionAsInt());
      }
      
      public void testJavaVersionAtLeastFloat() {
          float version = SystemUtils.JAVA_VERSION_FLOAT;
          assertEquals(true, SystemUtils.isJavaVersionAtLeast(version));
          version -= 0.1f;
          assertEquals(true, SystemUtils.isJavaVersionAtLeast(version));
          version += 0.2f;
          assertEquals(false, SystemUtils.isJavaVersionAtLeast(version));
      }
      
      public void testJavaVersionAtLeastInt() {
          int version = SystemUtils.JAVA_VERSION_INT;
          assertEquals(true, SystemUtils.isJavaVersionAtLeast(version));
          version -= 10;
          assertEquals(true, SystemUtils.isJavaVersionAtLeast(version));
          version += 20;
          assertEquals(false, SystemUtils.isJavaVersionAtLeast(version));
      }
      
  }
  
  
  

---------------------------------------------------------------------
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