@Override
    public void write(Object object) throws IOException {
        objectOutputStream.writeObject(object);
        objectOutputStream.flush();
        preventMemoryLeak();
    }
@Test
    public void flushesAfterWrite() throws IOException {

        // given
        ObjectWriter objectWriter = new AutoFlushingObjectWriter(objectOutputStream, 2);
        String object = "foo";

        // when
        objectWriter.write(object);

        // then
        InOrder inOrder = inOrder(objectOutputStream);
        inOrder.verify(objectOutputStream).writeObjectOverride(object);
        inOrder.verify(objectOutputStream).flush();
    }