class ErrorMessageFactory {

  public static String create(Context context, Exception exception) {
    String errorMessage = context.getString(R.string.exception_generic);

    if (exception instanceof NoInternetConnectionException) {
      errorMessage = context.getString(R.string.exception_no_internet_connection);
    } else if (exception instanceof NoResponseException) {
      errorMessage = context.getString(R.string.exception_no_response);
    } else if (exception instanceof InvalidServerException) {
      errorMessage = context.getString(R.string.exception_invalid_server);
    } else if (exception.getMessage() != null && !exception.getMessage().isEmpty()) {
      errorMessage = exception.getMessage();
    }

    return errorMessage;
  }

}

class ErrorMessageFactoryTest {

  @Mock private Context context;

  @Test
  public void shouldReturnDefaultErrorMessageForInvalidServerException() throws Exception {

    when(context.getString(R.string.exception_invalid_server)).thenReturn(
        "Invalid Server Default Error Message");
    InvalidServerException invalidServerException = new InvalidServerException();

    String errorMessage = ErrorMessageFactory.create(context, invalidServerException);

    verify(context, times(1)).getString(R.string.exception_invalid_server);
    assertThat(errorMessage, notNullValue());
    assertThat(errorMessage, is("Invalid Server Default Error Message"));
  }

}