001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/test/java/org/apache/http/util/TestLangUtils.java $
003: * $Revision: 496069 $
004: * $Date: 2007-01-14 13:03:05 +0100 (Sun, 14 Jan 2007) $
005: *
006: * ====================================================================
007: * Licensed to the Apache Software Foundation (ASF) under one
008: * or more contributor license agreements. See the NOTICE file
009: * distributed with this work for additional information
010: * regarding copyright ownership. The ASF licenses this file
011: * to you under the Apache License, Version 2.0 (the
012: * "License"); you may not use this file except in compliance
013: * with the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing,
018: * software distributed under the License is distributed on an
019: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020: * KIND, either express or implied. See the License for the
021: * specific language governing permissions and limitations
022: * under the License.
023: * ====================================================================
024: *
025: * This software consists of voluntary contributions made by many
026: * individuals on behalf of the Apache Software Foundation. For more
027: * information on the Apache Software Foundation, please see
028: * <http://www.apache.org/>.
029: *
030: */
031:
032: package org.apache.http.util;
033:
034: import junit.framework.Test;
035: import junit.framework.TestCase;
036: import junit.framework.TestSuite;
037:
038: /**
039: * Unit tests for {@link LangUtil}.
040: *
041: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
042: */
043: public class TestLangUtils extends TestCase {
044:
045: public TestLangUtils(String testName) {
046: super (testName);
047: }
048:
049: public static void main(String args[]) {
050: String[] testCaseName = { TestLangUtils.class.getName() };
051: junit.textui.TestRunner.main(testCaseName);
052: }
053:
054: public static Test suite() {
055: return new TestSuite(TestLangUtils.class);
056: }
057:
058: public void testBasicHash() {
059: Integer i = new Integer(1234);
060: int h1 = LangUtils.hashCode(LangUtils.HASH_SEED, i.hashCode());
061: int h2 = LangUtils.hashCode(LangUtils.HASH_SEED, i);
062: assertTrue(h1 == h2);
063: }
064:
065: public void testNullObjectHash() {
066: int h1 = LangUtils.hashCode(LangUtils.HASH_SEED, null);
067: int h2 = LangUtils.hashCode(LangUtils.HASH_SEED, 0);
068: assertTrue(h1 == h2);
069: }
070:
071: public void testBooleanHash() {
072: int h1 = LangUtils.hashCode(LangUtils.HASH_SEED, true);
073: int h2 = LangUtils.hashCode(LangUtils.HASH_SEED, false);
074: int h3 = LangUtils.hashCode(LangUtils.HASH_SEED, true);
075: int h4 = LangUtils.hashCode(LangUtils.HASH_SEED, false);
076: assertTrue(h1 != h2);
077: assertTrue(h1 == h3);
078: assertTrue(h2 == h4);
079: }
080:
081: public void testBasicEquality() {
082: assertTrue(LangUtils.equals(null, null));
083: assertFalse(LangUtils.equals(null, "abc"));
084: assertFalse(LangUtils.equals("abc", null));
085: assertTrue(LangUtils.equals("abc", "abc"));
086: }
087:
088: public void testArrayEquals() {
089: assertFalse(LangUtils.equals(null, new Object[] {}));
090: assertFalse(LangUtils.equals(new Object[] {}, null));
091: assertTrue(LangUtils.equals(new Object[] {}, new Object[] {}));
092: assertFalse(LangUtils.equals(new Object[] { new Integer(1),
093: new Integer(2) }, new Object[] { new Integer(1) }));
094: assertFalse(LangUtils.equals(new Object[] { new Integer(1),
095: new Integer(2) }, new Object[] { new Integer(1),
096: new Integer(3) }));
097: assertTrue(LangUtils.equals(new Object[] { new Integer(1),
098: new Integer(2) }, new Object[] { new Integer(1),
099: new Integer(2) }));
100: }
101: }
|