### Question:
PendingResultHandler { public void offerException(final String pendingResultId, final Exception exception) { offerResult(pendingResultId, new ExceptionResult(exception)); } @Autowired  PendingResultHandler(final PendingResultsHolder pendingResultsHolder,
            @Value("${server.application.name}") final String applicationName); String createPendingResult(); void removePendingResult(final String pendingResultId); Object pollValue(final String pendingResultId); void offerValue(final String pendingResultId, final Object value); void offerException(final String pendingResultId, final Exception exception);  }### Answer:
@Test public void shouldPublishEvent_onOfferException() throws Exception { final Exception exception = new IllegalStateException(randomString()); final String pendingResultId = randomId(); pendingResultHandler.offerException(pendingResultId, exception); final ArgumentCaptor<PendingResultOfferedEvent> captor = ArgumentCaptor.forClass(PendingResultOfferedEvent.class); verify(mockSystemEventPublisher).publishEvent(captor.capture()); final PendingResultOfferedEvent event = captor.getValue(); assertEquals(applicationName, event.getTargetApplicationName()); assertNull(event.getTargetApplicationVersion()); assertEquals(pendingResultId, event.getPendingResultId()); final Object actualResult = new XStream().fromXML(event.getResultXml()); assertTrue(actualResult instanceof Result); IllegalStateException thrownException = null; try { ((Result) actualResult).getValue(); } catch (final IllegalStateException e) { thrownException = e; } assertNotNull(thrownException); assertEquals(thrownException.getMessage(), exception.getMessage()); }