### Question:
ErrorsMessageHeaderReader implements SerializationReader<ErrorsMessageHeader> { @Override public ErrorsMessageHeader readObject(InputStream inputStream) throws ErrorMessageHeaderSerializationException { ObjectMapper mapper = new ObjectMapper(); try { return mapper.readValue(inputStream, ErrorsMessageHeader.class); } catch (Exception e) { String message = "Could not deserialize input into a List of " + ErrorMessageHeader.class.getName() + " object. Cause: " + e.getMessage(); throw new ErrorMessageHeaderSerializationException(message, e); } }  @Override ErrorsMessageHeader readObject(InputStream inputStream); @Override ErrorsMessageHeader readObject(Reader reader); @NoJavadoc ErrorsMessageHeader readObject(String content);  }### Answer:
@Test public void testReadErrorsMessageHeaderFromStream() { InputStream inputJsonStream = getClass().getClassLoader().getResourceAsStream("errors/serialization/errorsmessageheader.json"); ErrorsMessageHeader actualErrorsMessageHeader = new ErrorsMessageHeaderReader().readObject(inputJsonStream); ArrayList<ErrorMessageHeader> expectedErrorMessageHeaders = new ArrayList<>(); expectedErrorMessageHeaders.add(new ErrorMessageHeader( "microservice-1-uri", 1456485443905L, 404, "Service 1 unavailable")); expectedErrorMessageHeaders.add(new ErrorMessageHeader( "microservice-2-uri", 1456485443906L, 405, "Service 2 unavailable")); expectedErrorMessageHeaders.add(new ErrorMessageHeader( "microservice-3-uri", 1456485443907L, 406, "Service 3 unavailable")); expectedErrorMessageHeaders.add(new ErrorMessageHeader( "microservice-4-uri", 1456485443908L, 407, "Service 4 unavailable")); ErrorsMessageHeader expectedErrorsMessageHeader = new ErrorsMessageHeader(expectedErrorMessageHeaders); Assert.assertTrue( "Unexpected error message header", expectedErrorsMessageHeader .getErrorMessageHeaders() .containsAll(actualErrorsMessageHeader.getErrorMessageHeaders())); }
@Test public void testReadErrorsMessageHeaderFromString() { InputStream inputJsonStream = getClass().getClassLoader().getResourceAsStream("errors/serialization/errorsmessageheader.json"); String inputJson = null; try { inputJson = ReadFile.getFileContents(inputJsonStream).toString(); } catch (IOException e) { e.printStackTrace(); } ErrorsMessageHeader actualErrorsMessageHeader = new ErrorsMessageHeaderReader().readObject(inputJson); List<ErrorMessageHeader> expectedErrorMessageHeaders = new ArrayList<>(); expectedErrorMessageHeaders.add(new ErrorMessageHeader( "microservice-1-uri", 1456485443905L, 404, "Service 1 unavailable")); expectedErrorMessageHeaders.add(new ErrorMessageHeader( "microservice-2-uri", 1456485443906L, 405, "Service 2 unavailable")); expectedErrorMessageHeaders.add(new ErrorMessageHeader( "microservice-3-uri", 1456485443907L, 406, "Service 3 unavailable")); expectedErrorMessageHeaders.add(new ErrorMessageHeader( "microservice-4-uri", 1456485443908L, 407, "Service 4 unavailable")); ErrorsMessageHeader expectedErrorsMessageHeader = new ErrorsMessageHeader(expectedErrorMessageHeaders); Assert.assertTrue( "Unexpected error message header", expectedErrorsMessageHeader .getErrorMessageHeaders() .containsAll(actualErrorsMessageHeader.getErrorMessageHeaders())); }
@Test public void testExceptionWithNullInputStream() { InputStream inputStream = null; ErrorsMessageHeaderReader reader = new ErrorsMessageHeaderReader(); try { reader.readObject(inputStream); } catch (ErrorMessageHeaderSerializationException e) { String message = e.getMessage(); Assert.assertTrue(message.startsWith("Could not deserialize ")); } }
@Test public void testExceptionWithNullContent() { String content = null; ErrorsMessageHeaderReader reader = new ErrorsMessageHeaderReader(); try { reader.readObject(content); } catch (ErrorMessageHeaderSerializationException e) { String message = e.getMessage(); Assert.assertTrue(message.startsWith("Could not deserialize ")); } }