@Test public class IndexerTest { private static final Indexer<String> avengers = Indexer.fromStream(Stream.of("cap", "iron-man", "hulk", "cap")); public void testIndexer() { assertFalse(avengers.isEmpty()); assertTrue(avengers.size() == 3); assertTrue(avengers.indexOf("cap") == 0); assertTrue(avengers.lastIndexOf("cap") == 0); assertTrue(avengers.get(0).equals("cap")); assertTrue(avengers.contains("cap")); assertFalse(avengers.contains("made-up")); Object[] arr = avengers.toArray(); assertEquals(arr, new String[] {"cap", "iron-man", "hulk"}); assertEquals(avengers, avengers.subList(0, avengers.size())); } @Test(expectedExceptions = RuntimeException.class) public void testIndexerThrowsRemove() { Indexer.fromStream(Stream.of("a", "b", "c")).remove(0); } @Test(expectedExceptions = RuntimeException.class) public void testIndexerThrowsAdd() { Indexer.fromStream(Stream.of("a", "b", "c")).add("d"); } public void testSaveLoadRoundtrip() throws IOException { val baos = new ByteArrayOutputStream(3200); val dos = new DataOutputStream(baos); avengers.save(dos); val dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())); val otherAvengers = Indexer.load(dis); assertEquals(avengers, otherAvengers); } }
@Test(expectedExceptions = RuntimeException.class) public void testIndexerThrowsAdd() { Indexer.fromStream(Stream.of("a", "b", "c")).add("d"); }
@Test(expectedExceptions = RuntimeException.class) public void testIndexerThrowsRemove() { Indexer.fromStream(Stream.of("a", "b", "c")).remove(0); }