harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r384227 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/lang/Boolean.java test/java/org/apache/harmony/tests/java/lang/AllTests.java test/java/org/apache/harmony/tests/java/lang/BooleanTest.java
Date Wed, 08 Mar 2006 14:54:11 GMT
Author: tellison
Date: Wed Mar  8 06:54:10 2006
New Revision: 384227

URL: http://svn.apache.org/viewcvs?rev=384227&view=rev
Log:
Fix for HARMONY-179 ([classlib][luni] Java 5 enhancements for java.lang.Boolean)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Boolean.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Boolean.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Boolean.java?rev=384227&r1=384226&r2=384227&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Boolean.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Boolean.java
Wed Mar  8 06:54:10 2006
@@ -15,11 +15,12 @@
 
 package java.lang;
 
-
 /**
- * Booleans are objects (i.e. non-base types) which represent boolean values.
+ * <p>Boolean is the wrapper for the primitive type <code>boolean</code>.</p>
+ * @since 1.0
  */
 public final class Boolean implements java.io.Serializable {
+    //TODO Add Comparable<Boolean> to implements when generics are supported.
 
 	private static final long serialVersionUID = -3665804199014368530L;
 
@@ -136,8 +137,23 @@
 	 * @return the boolean value.
 	 */
 	static boolean toBoolean(String string) {
-		return (string != null) && (string.toLowerCase().equals("true"));
+		return parseBoolean(string);
 	}
+    
+    /**
+     * <p>
+     * Parses the string as a <code>boolean</code>. If the string is not
+     * <code>null</code> and is equal to <code>"true"</code>, regardless
+     * case, then <code>true</code> is returned, otherwise <code>false</code>.
+     * </p>
+     * 
+     * @param s The string to parse.
+     * @return A boolean value.
+     * @since 1.5
+     */
+    public static boolean parseBoolean(String s) {
+        return "true".equalsIgnoreCase(s);
+    }
 
 	/**
 	 * Answers a string containing a concise, human-readable description of the

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/AllTests.java?rev=384227&r1=384226&r2=384227&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/AllTests.java
Wed Mar  8 06:54:10 2006
@@ -33,6 +33,7 @@
 		suite.addTestSuite(SecurityManagerTest.class);
 		suite.addTestSuite(DoubleTest.class);
 		suite.addTestSuite(StringBuilderTest.class);
+		suite.addTestSuite(BooleanTest.class);
 		//$JUnit-END$
 		return suite;
 	}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java?rev=384227&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java
Wed Mar  8 06:54:10 2006
@@ -0,0 +1,135 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.lang;
+
+import junit.framework.TestCase;
+
+public class BooleanTest extends TestCase {
+
+    /**
+     * @tests java.lang.Boolean#hashCode()
+     */
+    public void test_hashCode() {
+        assertEquals(1231, Boolean.TRUE.hashCode());
+        assertEquals(1237, Boolean.FALSE.hashCode());
+    }
+
+    /**
+     * @tests java.lang.Boolean#Boolean(String)
+     */
+    public void test_ConstructorLjava_lang_String() {
+        assertEquals(Boolean.TRUE, new Boolean("TRUE"));
+        assertEquals(Boolean.TRUE, new Boolean("true"));
+        assertEquals(Boolean.TRUE, new Boolean("True"));
+        
+        assertEquals(Boolean.FALSE, new Boolean("yes"));
+        assertEquals(Boolean.FALSE, new Boolean("false"));
+    }
+
+    /**
+     * @tests java.lang.Boolean#Boolean(boolean)
+     */
+    public void test_ConstructorZ() {
+        assertEquals(Boolean.TRUE, new Boolean(true));
+        assertEquals(Boolean.FALSE, new Boolean(false));
+    }
+
+    /**
+     * @tests java.lang.Boolean#booleanValue()
+     */
+    public void test_booleanValue() {
+        assertTrue(Boolean.TRUE.booleanValue());
+        assertFalse(Boolean.FALSE.booleanValue());
+    }
+
+    /**
+     * @tests java.lang.Boolean#equals(Object)
+     */
+    public void test_equalsLjava_lang_Object() {
+        assertTrue(Boolean.TRUE.equals(Boolean.TRUE));
+        assertTrue(Boolean.TRUE.equals(new Boolean(true)));
+        assertFalse(Boolean.TRUE.equals("true"));
+        assertFalse(Boolean.TRUE.equals(null));
+        assertFalse(Boolean.FALSE.equals(Boolean.TRUE));
+        assertTrue(Boolean.FALSE.equals(Boolean.FALSE));
+        assertTrue(Boolean.FALSE.equals(new Boolean(false)));
+    }
+
+    /**
+     * @tests java.lang.Boolean#getBoolean(String)
+     */
+    public void test_getBooleanLjava_lang_String() {
+        System.setProperty(getClass().getName(), "true");
+        assertTrue(Boolean.getBoolean(getClass().getName()));
+        
+        System.setProperty(getClass().getName(), "TRUE");
+        assertTrue(Boolean.getBoolean(getClass().getName()));
+        
+        System.setProperty(getClass().getName(), "false");
+        assertFalse(Boolean.getBoolean(getClass().getName()));
+    }
+
+    /**
+     * @tests java.lang.Boolean#toString()
+     */
+    public void test_toString() {
+        assertEquals("true", Boolean.TRUE.toString());
+        assertEquals("false", Boolean.FALSE.toString());
+    }
+
+    /**
+     * @tests java.lang.Boolean#toString(boolean)
+     */
+    public void test_toStringZ() {
+        assertEquals("true", Boolean.toString(true));
+        assertEquals("false", Boolean.toString(false));
+    }
+
+    /**
+     * @tests java.lang.Boolean#valueOf(String)
+     */
+    public void test_valueOfLjava_lang_String() {
+        assertEquals(Boolean.TRUE, Boolean.valueOf("true"));
+        assertEquals(Boolean.FALSE, Boolean.valueOf("false"));
+        
+        assertEquals(Boolean.TRUE, Boolean.valueOf("TRUE"));
+        assertEquals(Boolean.FALSE, Boolean.valueOf("false"));
+        
+        assertEquals(Boolean.FALSE, Boolean.valueOf(null));
+        assertEquals(Boolean.FALSE, Boolean.valueOf(""));
+        assertEquals(Boolean.FALSE, Boolean.valueOf("invalid"));
+    }
+
+    /**
+     * @tests java.lang.Boolean#valueOf(boolean)
+     */
+    public void test_valueOfZ() {
+        assertEquals(Boolean.TRUE, Boolean.valueOf(true));
+        assertEquals(Boolean.FALSE, Boolean.valueOf(false));
+    }
+
+    /**
+     * @tests java.lang.Boolean#parseBoolean(String)
+     */
+    public void test_parseBooleanLjava_lang_String() {
+        assertTrue(Boolean.parseBoolean("true"));
+        assertTrue(Boolean.parseBoolean("TRUE"));
+        assertFalse(Boolean.parseBoolean("false"));
+        assertFalse(Boolean.parseBoolean(null));
+        assertFalse(Boolean.parseBoolean(""));
+        assertFalse(Boolean.parseBoolean("invalid"));
+    }
+}



Mime
View raw message