### Question:
DefaultWhenEventBus implements WhenEventBus { @Override public <T> Promise<Message<T>> send(String address, Object message) { return adapter.toPromise(handler -> eventBus.send(address, message, handler)); } @Inject  DefaultWhenEventBus(Vertx vertx, PromiseAdapter adapter);  DefaultWhenEventBus(Vertx vertx, When when);  DefaultWhenEventBus(EventBus eventBus, PromiseAdapter adapter);  DefaultWhenEventBus(EventBus eventBus, When when); @Override EventBus getEventBus(); @Override Promise<Void> close(); @Override Promise<Message<T>> send(String address, Object message); @Override Promise<Message<T>> send(String address, Object message, DeliveryOptions options);  }### Answer:
@Test public void testSend_Succeeded() throws Exception { Object message = new Object(); whenEventBus.send(address, message).then(done.onFulfilled, done.onRejected); verify(eventBus).send(eq(address), eq(message), resultCaptor.capture()); when(replyMessageResult.succeeded()).thenReturn(true); when(replyMessageResult.result()).thenReturn(replyMessage); resultCaptor.getValue().handle(replyMessageResult); done.assertFulfilled(); assertEquals(replyMessage, done.getValue()); }
@Test public void testSend_Failed() throws Exception { Object message = new Object(); whenEventBus.send(address, message).then(done.onFulfilled, done.onRejected); verify(eventBus).send(eq(address), eq(message), resultCaptor.capture()); Throwable t = new Throwable(); when(replyMessageResult.failed()).thenReturn(true); when(replyMessageResult.cause()).thenReturn(t); resultCaptor.getValue().handle(replyMessageResult); done.assertRejected(); assertEquals(t, done.getCause()); }
@Test public void testSend_WithOptions_Succeeded() throws Exception { Object message = new Object(); DeliveryOptions options = new DeliveryOptions(); whenEventBus.send(address, message, options).then(done.onFulfilled, done.onRejected); verify(eventBus).send(eq(address), eq(message), eq(options), resultCaptor.capture()); when(replyMessageResult.succeeded()).thenReturn(true); when(replyMessageResult.result()).thenReturn(replyMessage); resultCaptor.getValue().handle(replyMessageResult); done.assertFulfilled(); assertEquals(replyMessage, done.getValue()); }
@Test public void testSend_WithOptions_Failed() throws Exception { Object message = new Object(); DeliveryOptions options = new DeliveryOptions(); whenEventBus.send(address, message, options).then(done.onFulfilled, done.onRejected); verify(eventBus).send(eq(address), eq(message), eq(options), resultCaptor.capture()); Throwable t = new Throwable(); when(replyMessageResult.failed()).thenReturn(true); when(replyMessageResult.cause()).thenReturn(t); resultCaptor.getValue().handle(replyMessageResult); done.assertRejected(); assertEquals(t, done.getCause()); }