Home | History | Annotate | Download | only in analysis
      1 /*******************************************************************************
      2  * Copyright (c) 2009, 2018 Mountainminds GmbH & Co. KG and Contributors
      3  * All rights reserved. This program and the accompanying materials
      4  * are made available under the terms of the Eclipse Public License v1.0
      5  * which accompanies this distribution, and is available at
      6  * http://www.eclipse.org/legal/epl-v10.html
      7  *
      8  * Contributors:
      9  *    Marc R. Hoffmann - initial API and implementation
     10  *
     11  *******************************************************************************/
     12 package org.jacoco.core.internal.analysis;
     13 
     14 import static org.junit.Assert.assertEquals;
     15 import static org.junit.Assert.assertNull;
     16 import static org.junit.Assert.assertSame;
     17 
     18 import org.junit.Before;
     19 import org.junit.Test;
     20 
     21 /**
     22  * Unit tests for {@link StringPool}.
     23  */
     24 public class StringPoolTest {
     25 
     26 	private StringPool pool;
     27 
     28 	@Before
     29 	public void setup() {
     30 		pool = new StringPool();
     31 	}
     32 
     33 	@Test
     34 	public void testGetStringNull() {
     35 		assertNull(pool.get((String) null));
     36 	}
     37 
     38 	@Test
     39 	public void testGetString() {
     40 		final String a = pool.get(new String("JaCoCo"));
     41 		final String b = pool.get(new String("JaCoCo"));
     42 
     43 		assertEquals("JaCoCo", a);
     44 		assertEquals("JaCoCo", b);
     45 		assertSame(a, b);
     46 	}
     47 
     48 	@Test
     49 	public void testGetArrayNull() {
     50 		assertNull(pool.get((String[]) null));
     51 	}
     52 
     53 	@Test
     54 	public void testGetEmptyArray() {
     55 		final String[] arr1 = pool.get(new String[0]);
     56 		final String[] arr2 = pool.get(new String[0]);
     57 
     58 		assertEquals(0, arr1.length);
     59 		assertSame(arr1, arr2);
     60 	}
     61 
     62 	@Test
     63 	public void testGetArray() {
     64 		final String[] arr1 = pool.get(new String[] { new String("JaCoCo") });
     65 		final String[] arr2 = pool.get(new String[] { new String("JaCoCo") });
     66 
     67 		assertEquals(1, arr1.length);
     68 		assertEquals("JaCoCo", arr1[0]);
     69 		assertSame(arr1[0], arr2[0]);
     70 	}
     71 
     72 }
     73