### Question:
ObjectXMLWriter implements MessageBodyWriter { @Override public void writeTo(Object o, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { XmlMapper xmlMapper = new XmlMapper(); xmlMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); xmlMapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); xmlMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); xmlMapper.writeValue(entityStream, o); }  @Override boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Object o, Class type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override void writeTo(Object o, Class type, Type genericType, Annotation[] annotations, MediaType mediaType,
                        MultivaluedMap httpHeaders, OutputStream entityStream);  }### Answer:
@Test(expected = IOException.class) public void testEntityNullCollection() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); EntityBody body = new EntityBody(); body.put("id", "1234"); body.put("name", "test name"); Home response = new Home(null, body); writer.writeTo(response, null, null, null, null, null, out); }
@Test public void testEntityHome() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); EntityBody body = new EntityBody(); body.put("id", "1234"); body.put("name", "test name"); Home response = new Home("TestEntity", body); writer.writeTo(response, null, null, null, null, null, out); assertNotNull("Should not be null", out); String value = new String(out.toByteArray()); assertTrue("Should match", value.startsWith("<Home")); assertTrue("Should match", value.indexOf("<id>") > 0); assertTrue("Should match", value.indexOf("<name>") > 0); }
@Test(expected = IOException.class) public void testNullObject() throws IOException { EntityBody body = new EntityBody(); body.put("id", "1234"); body.put("name", "test name"); Home response = new Home("TestEntity", body); writer.writeTo(response, null, null, null, null, null, null); }