### Question:
ErrorMessageHeaderReader implements SerializationReader<ErrorMessageHeader> { @NoJavadoc @Override public ErrorMessageHeader readObject(InputStream inputStream) throws ErrorMessageHeaderSerializationException { ObjectMapper mapper = new ObjectMapper(); try { return mapper.readValue(inputStream, ErrorMessageHeader.class); } catch (Exception e) { String message = "Could not deserialize input into a " + ErrorMessageHeader.class.getName() + " object. Cause: " + e.getMessage(); throw new ErrorMessageHeaderSerializationException(message, e); } }  @NoJavadoc @Override ErrorMessageHeader readObject(InputStream inputStream); @NoJavadoc @Override ErrorMessageHeader readObject(Reader reader); @NoJavadoc ErrorMessageHeader readObject(String content);  }### Answer:
@Test public void testReadMessageHeaderFromStream() { InputStream inputJsonStream = getClass().getClassLoader().getResourceAsStream("errors/serialization/errormessageheader.json"); ErrorMessageHeader actualErrorMessageHeader = new ErrorMessageHeaderReader().readObject(inputJsonStream); ErrorMessageHeader expectedErrorMessageHeader = new ErrorMessageHeader("microservice-1-uri", 1456485443905L, 404, "Service unavailable"); Assert.assertEquals("Unexpected error message header", expectedErrorMessageHeader, actualErrorMessageHeader); }
@Test public void testReadErrorMessageHeaderFromString() { InputStream inputJsonStream = getClass().getClassLoader().getResourceAsStream("errors/serialization/errormessageheader.json"); String inputJson = null; try { inputJson = ReadFile.getFileContents(inputJsonStream).toString(); } catch (IOException e) { e.printStackTrace(); } ErrorMessageHeader actualErrorMessageHeader = new ErrorMessageHeaderReader().readObject(inputJson); ErrorMessageHeader expectedErrorMessageHeader = new ErrorMessageHeader("microservice-1-uri", 1456485443905L, 404, "Service unavailable"); Assert.assertEquals("Unexpected error message header", expectedErrorMessageHeader, actualErrorMessageHeader); }
@Test public void testException() { InputStream inputStream = null; ErrorMessageHeaderReader reader = new ErrorMessageHeaderReader(); 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; ErrorMessageHeaderReader reader = new ErrorMessageHeaderReader(); try { reader.readObject(content); } catch (ErrorMessageHeaderSerializationException e) { String message = e.getMessage(); Assert.assertTrue(message.startsWith("Could not deserialize ")); } }