### Question:
JsrJsonpProvider implements MessageBodyReader<JsonStructure>, MessageBodyWriter<JsonStructure> { @Override public JsonStructure readFrom(Class<JsonStructure> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { if (entityStream == null) { throw new IOException("Initialized InputStream should be provided"); } try (JsonReader reader = Json.createReader(entityStream)) { return reader.read(); } catch (JsonException ex) { throw ExceptionUtils.toBadRequestException(ex, null); } }  @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(JsonStructure t, Class<?> type, Type genericType, Annotation[] annotations,
        MediaType mediaType); @Override void writeTo(JsonStructure t, Class<?> type, Type genericType, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override JsonStructure readFrom(Class<JsonStructure> type, Type genericType, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream);  }### Answer:
@Test(expected = IOException.class) public void testReadWithNullStream() throws Exception { provider.readFrom(JsonStructure.class, null, null, null, null, null); }
@Test public void testReadMalformedJson() throws Exception { byte[] bytes = "junk".getBytes(); try { provider.readFrom(JsonStructure.class, null, null, null, null, new ByteArrayInputStream(bytes)); fail("400 BAD REQUEST is expected"); } catch (WebApplicationException ex) { assertThat(ex.getResponse().getStatus(), equalTo(Response.Status.BAD_REQUEST.getStatusCode())); } }
@Test public void testReadJsonObject() throws Exception { final StringWriter writer = new StringWriter(); Json.createGenerator(writer) .writeStartObject() .write("firstName", "Tom") .write("lastName", "Tommyknocker") .writeEnd() .close(); final String str = writer.toString(); writer.close(); final JsonStructure obj = provider.readFrom(JsonStructure.class, null, null, null, null, new ByteArrayInputStream(str.getBytes())); assertThat(obj, instanceOf(JsonObject.class)); assertThat(((JsonObject)obj).getString("firstName"), equalTo("Tom")); assertThat(((JsonObject)obj).getString("lastName"), equalTo("Tommyknocker")); }
@Test public void testReadJsonArray() throws Exception { final StringWriter writer = new StringWriter(); Json.createGenerator(writer) .writeStartArray() .write("Tom") .write("Tommyknocker") .writeEnd() .close(); final JsonStructure obj = provider.readFrom(JsonStructure.class, null, null, null, null, new ByteArrayInputStream(writer.toString().getBytes())); assertThat(obj, instanceOf(JsonArray.class)); assertThat(((JsonArray)obj).getString(0), equalTo("Tom")); assertThat(((JsonArray)obj).getString(1), equalTo("Tommyknocker")); assertThat(((JsonArray)obj).size(), equalTo(2)); }