@Test public void sendEventShouldNotFailWhenObjectMapperThrowsException() throws Exception { doThrow(new JsonGenerationException("Nothing serious!")).when(mapper).writeValueAsString(any()); Event event = mock(Event.class); eventSinkImpl.queueEvent(event); verify(mockClientProducer, never()).send(any(ClientMessage.class)); }
@Test public void sendEventShouldSendMessageOnProperEventInput() throws Exception { final String content = "Simple String"; doReturn(content).when(mapper).writeValueAsString(anyObject()); ArgumentCaptor<ClientMessage> argumentCaptor = ArgumentCaptor.forClass(ClientMessage.class); eventSinkImpl.queueEvent(mock(Event.class)); eventSinkImpl.sendEvents(); verify(mockClientProducer).send(argumentCaptor.capture()); assertEquals(content, argumentCaptor.getValue().getBodyBuffer().readString()); }