@Test public void testConstructors() { DefaultIndexer<String> instance = new DefaultIndexer<String>(); assertTrue(instance.isEmpty()); assertTrue(instance.valueSet().isEmpty()); assertTrue(instance.valueList().isEmpty()); assertTrue(instance.asMap().isEmpty()); instance = new DefaultIndexer<String>(123); assertTrue(instance.isEmpty()); assertTrue(instance.valueSet().isEmpty()); assertTrue(instance.valueList().isEmpty()); assertTrue(instance.asMap().isEmpty()); List<String> values = Arrays.asList("a", "c", new String("a"), null, "b"); instance = new DefaultIndexer<String>(values); assertEquals(4, instance.size()); assertEquals(4, instance.valueSet().size()); assertEquals(4, instance.valueList().size()); assertEquals(4, instance.asMap().size()); assertTrue(instance.valueSet().containsAll(values)); assertTrue(instance.valueList().containsAll(values)); assertTrue(instance.asMap().keySet().containsAll(values)); assertEquals(0, (int) instance.getIndex("a")); assertEquals(3, (int) instance.getIndex("b")); assertEquals(1, (int) instance.getIndex("c")); assertEquals(2, (int) instance.getIndex(null)); }
/** Test of clone method, of class DefaultIndexer. */ @Test public void testClone() { DefaultIndexer<String> instance = new DefaultIndexer<String>(); DefaultIndexer<String> clone = instance.clone(); assertNotSame(instance, clone); assertNotSame(clone, instance.clone()); instance.add("a"); assertEquals(0, (int) instance.getIndex("a")); assertNull(clone.getIndex("a")); assertTrue(clone.isEmpty()); assertTrue(clone.valueSet().isEmpty()); assertTrue(clone.valueList().isEmpty()); instance.add("b"); clone = instance.clone(); assertEquals(2, clone.size()); assertEquals(instance.valueList(), clone.valueList()); assertEquals(instance.asMap(), clone.asMap()); assertEquals(0, (int) clone.getIndex("a")); assertEquals(1, (int) clone.getIndex("b")); }
/** Test of asMap method, of class DefaultIndexer. */ @Test public void testAsMap() { DefaultIndexer<String> instance = new DefaultIndexer<String>(); assertTrue(instance.asMap().isEmpty()); instance.add("something"); assertEquals(1, instance.asMap().size()); assertTrue(instance.asMap().containsKey("something")); assertEquals(0, (int) instance.asMap().get("something")); List<String> values = Arrays.asList("a", "c", new String("a"), null, "b"); instance.addAll(values); assertEquals(5, instance.asMap().size()); assertTrue(instance.asMap().containsKey("something")); assertTrue(instance.asMap().keySet().containsAll(values)); assertEquals(0, (int) instance.asMap().get("something")); assertEquals(1, (int) instance.asMap().get("a")); assertEquals(2, (int) instance.asMap().get("c")); assertEquals(3, (int) instance.asMap().get(null)); assertEquals(4, (int) instance.asMap().get("b")); }