S3TransportBuffer implements TransportBuffer { @Override public boolean add(InternalEvent ievent) throws IllegalStateException, IOException { byte[] payload = serializer.serialize(ievent); if (cos.getByteCount() + payload.length > this.maxBytes) { throw new IllegalStateException("buffer is full"); } os.write(payload); return true; } S3TransportBuffer(long maxBytes, boolean useCompression, S3TransportSerializer serializer); @Override boolean add(InternalEvent ievent); @Override ByteArrayOutputStream getInternalBuffer(); @Override boolean isEmpty(); @Override void close(); @Override void clear(); boolean isCompressed();  }
@Test public void testAdd() throws IOException, TransportException { S3TransportSerializer serializer = mock(S3TransportSerializer.class); doReturn("foo".getBytes()).when(serializer).serialize(any(InternalEvent.class)); S3TransportBuffer buffer = new S3TransportBuffer(5, 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, TransportException { S3TransportSerializer serializer = mock(S3TransportSerializer.class); doReturn("foo".getBytes()).when(serializer).serialize(any(InternalEvent.class)); S3TransportBuffer buffer = new S3TransportBuffer(5, false, serializer); InternalEvent mockEvent = mock(InternalEvent.class); buffer.add(mockEvent); buffer.add(mockEvent); }