@Test(expected = TransportException.class)
public void testThreadExceptionDuringAdd() throws TransportException, InterruptedException {

  DummyTransporter mockDummyTransporter = mock(DummyTransporter.class);
  DummyTransporterFactory tfactory = new DummyTransporterFactory();
  tfactory.transporter = mockDummyTransporter;
  doThrow(new TransportException("expected exception in test")).when(mockDummyTransporter)
          .sendBatch(any(DummyTransportBuffer.class));
  IpcSenderService ipc = new IpcSenderService(tfactory);
  // add 5 events to fill up the buffer so the next will result in a sendBatch()
  for (int i = 0; i < 5; i++) {
    ipc.add(mock(InternalEvent.class));
  }
  // this will trigger the sendBatch exception above
  ipc.add(mock(InternalEvent.class));
  Thread.sleep(5); // lets thread from last event complete and throw exception
  ipc.add(mock(InternalEvent.class)); // add() checks at start for any threads that threw exceptions
}