ApiErrorException extends RuntimeException { @Override public String getMessage() { final String message = super.getMessage(); return requestId == null || message.contains(requestId) ? message : message + " (Request ID: " + requestId + ")"; } ApiErrorException(String message, int code, boolean authenticated, String requestId); int getCode(); boolean isAuthenticated(); String getRequestId(); @Override String getMessage();  }
@Test public void getMessage() { final String message = "fubared: rid=" + REQUEST_ID; ApiErrorException exception = new ApiErrorException(message, 4711, true, REQUEST_ID); assertThat(exception.getMessage(), is(message)); }
@Test public void getMessageNoRequestIdInMessage() { ApiErrorException exception = new ApiErrorException("fubared!", 4711, true, REQUEST_ID); assertThat(exception.getMessage(), is("fubared! (Request ID: " + REQUEST_ID + ")")); }
@Test public void getMessageNoRequestId() { ApiErrorException exception = new ApiErrorException("fubared!", 4711, true, null); assertThat(exception.getMessage(), is("fubared!")); }