@Test public void emptyFailureReason() { model.failureReason = ""; assertThat(model.getError(), instanceOf(ServerException.class)); }
public Exception getError() { if (!isSuccess()) { switch (failureReason) { case FAILURE_LOGIN: return new LoginException(); case FAILURE_PASSWORD: return new PasswordException(); default: return new ServerException("Unknown failure reason: " + failureReason); } } else { throw new IllegalStateException("Can't build error for successful result"); } }
LoginResponseModel { public Exception getError() { if (!isSuccess()) { switch (failureReason) { case FAILURE_LOGIN: return new LoginException(); case FAILURE_PASSWORD: return new PasswordException(); default: return new ServerException("Unknown failure reason: " + failureReason); } } else { throw new IllegalStateException("Can't build error for successful result"); } } }
LoginResponseModel { public Exception getError() { if (!isSuccess()) { switch (failureReason) { case FAILURE_LOGIN: return new LoginException(); case FAILURE_PASSWORD: return new PasswordException(); default: return new ServerException("Unknown failure reason: " + failureReason); } } else { throw new IllegalStateException("Can't build error for successful result"); } }  }
LoginResponseModel { public Exception getError() { if (!isSuccess()) { switch (failureReason) { case FAILURE_LOGIN: return new LoginException(); case FAILURE_PASSWORD: return new PasswordException(); default: return new ServerException("Unknown failure reason: " + failureReason); } } else { throw new IllegalStateException("Can't build error for successful result"); } }  boolean isSuccess(); String getUserId(); Exception getError(); }
LoginResponseModel { public Exception getError() { if (!isSuccess()) { switch (failureReason) { case FAILURE_LOGIN: return new LoginException(); case FAILURE_PASSWORD: return new PasswordException(); default: return new ServerException("Unknown failure reason: " + failureReason); } } else { throw new IllegalStateException("Can't build error for successful result"); } }  boolean isSuccess(); String getUserId(); Exception getError();  }