### Question:
ErrorsMessageHeaderWriter implements SerializationWriter<ErrorsMessageHeader> { @Override public void writeObject(ErrorsMessageHeader errorsMessageHeader, OutputStream outputStream) throws ErrorMessageHeaderSerializationException { ObjectMapper mapper = new ObjectMapper(); try { mapper.writeValue(outputStream, errorsMessageHeader); } catch (Exception e) { String message = "Could not serialize a List of " + ErrorMessageHeader.class.getName() + " object. Cause: " + e.getMessage(); throw new ErrorMessageHeaderSerializationException(message, e); } }  @Override void writeObject(ErrorsMessageHeader errorsMessageHeader, OutputStream outputStream);  }### Answer:
@Test public void testWriteListErrorMessageHeader() { List<ErrorMessageHeader> errorMessageHeaders = new ArrayList<>(); errorMessageHeaders.add(new ErrorMessageHeader( "microservice-1-uri", 1456485443905L, 404, "Service 1 unavailable")); errorMessageHeaders.add(new ErrorMessageHeader( "microservice-2-uri", 1456485443906L, 405, "Service 2 unavailable")); errorMessageHeaders.add(new ErrorMessageHeader( "microservice-3-uri", 1456485443907L, 406, "Service 3 unavailable")); errorMessageHeaders.add(new ErrorMessageHeader( "microservice-4-uri", 1456485443908L, 407, "Service 4 unavailable")); ErrorsMessageHeader errorsMessageHeader = new ErrorsMessageHeader(errorMessageHeaders); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); new ErrorsMessageHeaderWriter().writeObject(errorsMessageHeader, outputStream); String jsonResult = outputStream.toString(); JsonFluentAssert actualJson = JsonFluentAssert.assertThatJson(jsonResult); InputStream expectedJson = getClass().getClassLoader().getResourceAsStream("errors/serialization/errorsmessageheader.json"); String expectedJSON = null; try { expectedJSON = ReadFile.getFileContents(expectedJson).toString(); } catch (IOException e) { e.printStackTrace(); } actualJson.hasSameStructureAs(expectedJSON); actualJson.isEqualTo(expectedJSON); }
@Test public void testException() { ErrorsMessageHeaderWriter writer = new ErrorsMessageHeaderWriter(); try { writer.writeObject(null, null); } catch (ErrorMessageHeaderSerializationException e) { String message = e.getMessage(); Assert.assertTrue(message.startsWith("Could not serialize ")); } }