InfrastructureErrorBundle implements ErrorBundle { @Override public String getErrorMessage() { String errorMessage = ""; if (exception != null && exception.getMessage() != null) { errorMessage = exception.getMessage(); } return errorMessage; } InfrastructureErrorBundle(Exception exception); @Override Exception getException(); @Override String getErrorMessage();  }
@Test public void shouldReturnTheRightMessageForTheGivenException() throws Exception { when(mockException.getMessage()).thenReturn("Error message!!"); String errorMessage = infrastructureErrorBundle.getErrorMessage(); verify(mockException, times(2)).getMessage(); verifyNoMoreInteractions(mockException); assertThat(errorMessage, notNullValue()); assertThat(errorMessage, is(instanceOf(String.class))); assertThat(errorMessage, is("Error message!!")); }
@Test public void shouldReturnEmptyErrorMessageGivenANullException() throws Exception { InfrastructureErrorBundle infrastructureErrorBundleWithNullException = new InfrastructureErrorBundle(null); String errorMessage = infrastructureErrorBundleWithNullException.getErrorMessage(); assertThat(errorMessage, is("")); }
@Test public void shouldReturnEmptyErrorMessageGivenAnExceptionWithoutMessage() throws Exception { InfrastructureErrorBundle infrastructureErrorBundle = new InfrastructureErrorBundle(new NoInternetConnectionException()); String errorMessage = infrastructureErrorBundle.getErrorMessage(); assertThat(errorMessage, is("")); }