1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package libcore.internal; 18 19import junit.framework.TestCase; 20import libcore.internal.StringPool; 21 22public final class StringPoolTest extends TestCase { 23 24 public void testStringPool() { 25 StringPool stringPool = new StringPool(); 26 String bcd = stringPool.get(new char[] { 'a', 'b', 'c', 'd', 'e' }, 1, 3); 27 assertEquals("bcd", bcd); 28 assertSame(bcd, stringPool.get(new char[] { 'a', 'b', 'c', 'd', 'e' }, 1, 3)); 29 } 30 31 public void testHashCollision() { 32 StringPool stringPool = new StringPool(); 33 char[] a = { (char) 1, (char) 0 }; 34 char[] b = { (char) 0, (char) 31 }; 35 assertEquals(new String(a).hashCode(), new String(b).hashCode()); 36 37 String aString = stringPool.get(a, 0, 2); 38 assertEquals(new String(a), aString); 39 String bString = stringPool.get(b, 0, 2); 40 assertEquals(new String(b), bString); 41 assertSame(bString, stringPool.get(b, 0, 2)); 42 assertNotSame(aString, stringPool.get(a, 0, 2)); 43 } 44} 45