### Question:
XMLMsgBodyReader implements MessageBodyReader<EntityBody> { @Override public EntityBody readFrom(Class<EntityBody> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { EntityBody body = null; if (entityStream != null) { try { body = reader.deserialize(entityStream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Response.Status.BAD_REQUEST); } } else { body = new EntityBody(); } return body; }  @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override EntityBody readFrom(Class<EntityBody> type, Type genericType, Annotation[] annotations,
                                   MediaType mediaType, MultivaluedMap<String, String> httpHeaders,
                                   InputStream entityStream);  }### Answer:
@Test public void testNullStream() throws IOException { EntityBody body = reader.readFrom(EntityBody.class, null, null, null, null, null); assertNotNull("Should not be null", body); assertTrue("Should be empty", body.isEmpty()); }
@Test public void testBadXml() throws Exception { try { InputStream is = new ByteArrayInputStream("{\"test\":\"foo\"}".getBytes()); reader.readFrom(EntityBody.class, null, null, null, null, is); fail("Should throw Exception because of invalid XML format"); } catch(WebApplicationException wae) { assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), wae.getResponse().getStatus()); } }