001: /* Licensed to the Apache Software Foundation (ASF) under one or more
002: * contributor license agreements. See the NOTICE file distributed with
003: * this work for additional information regarding copyright ownership.
004: * The ASF licenses this file to You under the Apache License, Version 2.0
005: * (the "License"); you may not use this file except in compliance with
006: * the License. You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.harmony.luni.tests.java.lang;
018:
019: import junit.framework.TestCase;
020:
021: public class BooleanTest extends TestCase {
022:
023: /**
024: * @tests java.lang.Boolean#hashCode()
025: */
026: public void test_hashCode() {
027: assertEquals(1231, Boolean.TRUE.hashCode());
028: assertEquals(1237, Boolean.FALSE.hashCode());
029: }
030:
031: /**
032: * @tests java.lang.Boolean#Boolean(String)
033: */
034: public void test_ConstructorLjava_lang_String() {
035: assertEquals(Boolean.TRUE, new Boolean("TRUE"));
036: assertEquals(Boolean.TRUE, new Boolean("true"));
037: assertEquals(Boolean.TRUE, new Boolean("True"));
038:
039: assertEquals(Boolean.FALSE, new Boolean("yes"));
040: assertEquals(Boolean.FALSE, new Boolean("false"));
041: }
042:
043: /**
044: * @tests java.lang.Boolean#Boolean(boolean)
045: */
046: public void test_ConstructorZ() {
047: assertEquals(Boolean.TRUE, new Boolean(true));
048: assertEquals(Boolean.FALSE, new Boolean(false));
049: }
050:
051: /**
052: * @tests java.lang.Boolean#booleanValue()
053: */
054: public void test_booleanValue() {
055: assertTrue(Boolean.TRUE.booleanValue());
056: assertFalse(Boolean.FALSE.booleanValue());
057: }
058:
059: /**
060: * @tests java.lang.Boolean#equals(Object)
061: */
062: public void test_equalsLjava_lang_Object() {
063: assertTrue(Boolean.TRUE.equals(Boolean.TRUE));
064: assertTrue(Boolean.TRUE.equals(new Boolean(true)));
065: assertFalse(Boolean.TRUE.equals("true"));
066: assertFalse(Boolean.TRUE.equals(null));
067: assertFalse(Boolean.FALSE.equals(Boolean.TRUE));
068: assertTrue(Boolean.FALSE.equals(Boolean.FALSE));
069: assertTrue(Boolean.FALSE.equals(new Boolean(false)));
070: }
071:
072: /**
073: * @tests java.lang.Boolean#getBoolean(String)
074: */
075: public void test_getBooleanLjava_lang_String() {
076: System.setProperty(getClass().getName(), "true");
077: assertTrue(Boolean.getBoolean(getClass().getName()));
078:
079: System.setProperty(getClass().getName(), "TRUE");
080: assertTrue(Boolean.getBoolean(getClass().getName()));
081:
082: System.setProperty(getClass().getName(), "false");
083: assertFalse(Boolean.getBoolean(getClass().getName()));
084: }
085:
086: /**
087: * @tests java.lang.Boolean#toString()
088: */
089: public void test_toString() {
090: assertEquals("true", Boolean.TRUE.toString());
091: assertEquals("false", Boolean.FALSE.toString());
092: }
093:
094: /**
095: * @tests java.lang.Boolean#toString(boolean)
096: */
097: public void test_toStringZ() {
098: assertEquals("true", Boolean.toString(true));
099: assertEquals("false", Boolean.toString(false));
100: }
101:
102: /**
103: * @tests java.lang.Boolean#valueOf(String)
104: */
105: public void test_valueOfLjava_lang_String() {
106: assertEquals(Boolean.TRUE, Boolean.valueOf("true"));
107: assertEquals(Boolean.FALSE, Boolean.valueOf("false"));
108:
109: assertEquals(Boolean.TRUE, Boolean.valueOf("TRUE"));
110: assertEquals(Boolean.FALSE, Boolean.valueOf("false"));
111:
112: assertEquals(Boolean.FALSE, Boolean.valueOf(null));
113: assertEquals(Boolean.FALSE, Boolean.valueOf(""));
114: assertEquals(Boolean.FALSE, Boolean.valueOf("invalid"));
115:
116: assertTrue("Failed to parse true to true", Boolean.valueOf(
117: "true").booleanValue());
118: assertTrue("Failed to parse mixed case true to true", Boolean
119: .valueOf("TrUe").booleanValue());
120: assertTrue("parsed non-true to true", !Boolean.valueOf("ddddd")
121: .booleanValue());
122: }
123:
124: /**
125: * @tests java.lang.Boolean#valueOf(boolean)
126: */
127: public void test_valueOfZ() {
128: assertEquals(Boolean.TRUE, Boolean.valueOf(true));
129: assertEquals(Boolean.FALSE, Boolean.valueOf(false));
130: }
131:
132: /**
133: * @tests java.lang.Boolean#parseBoolean(String)
134: */
135: public void test_parseBooleanLjava_lang_String() {
136: assertTrue(Boolean.parseBoolean("true"));
137: assertTrue(Boolean.parseBoolean("TRUE"));
138: assertFalse(Boolean.parseBoolean("false"));
139: assertFalse(Boolean.parseBoolean(null));
140: assertFalse(Boolean.parseBoolean(""));
141: assertFalse(Boolean.parseBoolean("invalid"));
142: }
143:
144: /**
145: * @tests java.lang.Boolean#compareTo(Boolean)
146: */
147: public void test_compareToLjava_lang_Boolean() {
148: assertTrue(Boolean.TRUE.compareTo(Boolean.TRUE) == 0);
149: assertTrue(Boolean.FALSE.compareTo(Boolean.FALSE) == 0);
150: assertTrue(Boolean.TRUE.compareTo(Boolean.FALSE) > 0);
151: assertTrue(Boolean.FALSE.compareTo(Boolean.TRUE) < 0);
152:
153: try {
154: Boolean.TRUE.compareTo(null);
155: fail("No NPE");
156: } catch (NullPointerException e) {
157: }
158: }
159: }
|