GenericTransportBuffer implements TransportBuffer { @Override public boolean add(InternalEvent ievent) throws IllegalStateException, IOException { if (batchSize >= maxBatchSize) { throw new IllegalStateException("max batch size was hit"); } os.write(serializer.serialize(ievent)); batchSize++; return true; } GenericTransportBuffer(long maxBatchSize, boolean useCompression,
      TransportSerializer serializer); @Override boolean add(InternalEvent ievent); @Override ByteArrayOutputStream getInternalBuffer(); @Override boolean isEmpty(); @Override void close(); @Override void clear();  }
@Test public void testAdd() throws IOException { GenericTransportSerializer serializer = mock(GenericTransportSerializer.class); doReturn("foo".getBytes()).when(serializer).serialize(any(InternalEvent.class)); GenericTransportBuffer buffer = new GenericTransportBuffer(1, false, serializer); InternalEvent mockEvent = mock(InternalEvent.class); buffer.add(mockEvent); ByteArrayOutputStream baos = buffer.getInternalBuffer(); baos.close(); String actual = new String(baos.toByteArray()); assertEquals("foo", actual); assertEquals(false, buffer.isEmpty()); }
@Test(expected = IllegalStateException.class) public void testAddBufferFull() throws IOException { GenericTransportSerializer serializer = mock(GenericTransportSerializer.class); doReturn("foo".getBytes()).when(serializer).serialize(any(InternalEvent.class)); GenericTransportBuffer buffer = new GenericTransportBuffer(1, false, serializer); InternalEvent mockEvent = mock(InternalEvent.class); buffer.add(mockEvent); buffer.add(mockEvent); }