### Question:
AAIClientResponseExceptionMapper extends ResponseExceptionMapper { @Override public Optional<String> extractMessage(String entity) { String errorString = "Error calling A&AI. Request-Id=" + this.getRequestId() + " "; try { AAIError error = new ObjectMapper().readValue(entity, AAIError.class); AAIErrorFormatter formatter = new AAIErrorFormatter(error); return Optional.of(errorString + formatter.getMessage()); } catch (IOException e) { return Optional.of(errorString + entity); } } AAIClientResponseExceptionMapper(); @Override Optional<String> extractMessage(String entity);  }### Answer:
@Test public void testExtractMessageWithEntity() throws JsonProcessingException { ServiceException svcException = new ServiceException(); svcException.setText("test %1 message - %2"); svcException.setVariables(Arrays.asList("error", "service exception %1 test")); RequestError requestError = new RequestError(); requestError.setServiceException(svcException); AAIError error = new AAIError(); error.setRequestError(requestError); ObjectMapper objMapper = new ObjectMapper(); String strRequestError = objMapper.writeValueAsString(error); assertEquals(errorMsg + "test error message - service exception error test", mapper.extractMessage(strRequestError).get()); }
@Test public void testExtractMessageWithoutEntity() { assertEquals(errorMsg, mapper.extractMessage("").get()); }