コード例 #1
0
  @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");
  }
コード例 #2
0
  @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));
  }