@Test public void testProcessErrorResponse() throws Exception { final HttpClientUtilResponse response = new HttpClientUtilResponse(); final String mockError = "<error>\n" + "<errorCode>905</errorCode>\n" + "<message>contactZipCode parameter should be 5 numeric characters</message>\n" + "</error>"; response.setResponseByteArray(mockError.getBytes("UTF-8")); final ServiceResponseException mockServiceResponseException = new ServiceResponseException(); mockServiceResponseException.setErrorCode("905"); mockServiceResponseException.setMessage( "contactZipCode parameter should be 5 numeric characters"); PowerMockito.when(marshaller.unmarshal(Mockito.any(Source.class))) .thenReturn(mockServiceResponseException); final FormHandlerResponseInterface result = customerCareService.processErrorResponse(null, response, true); assertNotNull(result); assertEquals(new Integer(905), ((Errors) result).getErrors().get(0).getCode()); assertEquals( "contactZipCode parameter should be 5 numeric characters", ((Errors) result).getErrors().get(0).getMessage()); }