### Question:
GsonProvider implements MessageBodyReader<T>, MessageBodyWriter<T> { @Override public T readFrom( Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream ) throws IOException, WebApplicationException { InputStreamReader reader = new InputStreamReader( entityStream, "UTF-8" ); Type jsonType; if (type.equals(genericType) || genericType == null) { jsonType = type; } else { jsonType = genericType; } try { return gson.fromJson( reader, jsonType ); } finally { reader.close(); } } GsonProvider(); @Override long getSize( T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType  ); @Override boolean isWriteable( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType ); @Override void writeTo( T object,
			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 T readFrom( Class<T> type,
			Type genericType,
			Annotation[] annotations,
			MediaType mediaType,
			MultivaluedMap<String, String> httpHeaders,
			InputStream entityStream );  }### Answer:
@Test public void testReadsTestObject() throws WebApplicationException, IOException { GsonProvider<TestObject> testObjectProvider = new GsonProvider<TestObject>(); TestObject testObject = new TestObject( "foo" ); String json = new Gson().toJson( testObject ); ByteArrayInputStream inputStream = new ByteArrayInputStream( json.getBytes( "UTF-8" ) ); TestObject actualTestObject = testObjectProvider.readFrom( TestObject.class, null, null, null, null, inputStream ); assertThat( actualTestObject ).isEqualTo( testObject ); }
@Test public void testReadTestObjectClosesStream() throws WebApplicationException, IOException { GsonProvider<TestObject> testObjectProvider = new GsonProvider<TestObject>(); TestObject testObject = new TestObject( "foo" ); String json = new Gson().toJson( testObject ); ByteArrayInputStream inputStream = spy( new ByteArrayInputStream( json.getBytes( "UTF-8" ) ) ); testObjectProvider.readFrom( TestObject.class, null, null, null, null, inputStream ); verify( inputStream ).close(); }