TextMessageBodyWriter implements MessageBodyWriter<Object> { @Override public void writeTo(final Object object, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException { entityStream.write(JSONSerialiser.serialise(object)); entityStream.flush(); entityStream.close(); }  @Override boolean isWriteable(final Class<?> type, final Type genericType,
                               final Annotation[] annotations, final MediaType mediaType); @Override long getSize(final Object object, final Class<?> type,
                        final Type genericType, final Annotation[] annotations,
                        final MediaType mediaType); @Override void writeTo(final Object object, final Class<?> type,
                        final Type genericType, final Annotation[] annotations,
                        final MediaType mediaType,
                        final MultivaluedMap<String, Object> httpHeaders,
                        final OutputStream entityStream);  }
@Test public void shouldSerialiseObjectToJsonAndWrite() throws IOException { final TextMessageBodyWriter writer = new TextMessageBodyWriter(); final Object object = new Entity.Builder() .group(TestGroups.ENTITY) .vertex("vertex1") .property(TestPropertyNames.COUNT, 1) .build(); final OutputStream outputStream = mock(OutputStream.class); writer.writeTo(object, null, null, null, null, null, outputStream); InOrder inOrder = Mockito.inOrder(outputStream); final ArgumentCaptor<byte[]> bytesCaptor = ArgumentCaptor.forClass(byte[].class); inOrder.verify(outputStream).write(bytesCaptor.capture()); inOrder.verify(outputStream).flush(); inOrder.verify(outputStream).close(); JsonAssert.assertEquals(JSONSerialiser.serialise(object), bytesCaptor.getValue()); }