@Test(expected = DocumentIndexingException.class) public void checkThatThrowsExceptionIfNoClassIsFound() throws DocumentIndexingException { // Given ClassMap<IndexGenerator> classMap = mock(ClassMap.class); IndexGeneratorRegistry registry = new IndexGeneratorRegistry(classMap); when(classMap.get(String.class)).thenReturn(null); // When registry.generateIndex("This would need a string entry"); // Then fail("Expected an exception to be thrown"); }
@Test public void checkThatDelegatesToAFoundIndex() throws DocumentIndexingException { // Given String expectedIndex = "Expected Index"; ClassMap<IndexGenerator> classMap = mock(ClassMap.class); IndexGenerator delegatee = mock(IndexGenerator.class); IndexGeneratorRegistry registry = new IndexGeneratorRegistry(classMap); when(classMap.get(String.class)).thenReturn(delegatee); when(delegatee.generateIndex("delegate")).thenReturn(expectedIndex); // When Object index = registry.generateIndex("delegate"); // Then assertThat(index, is(expectedIndex)); }