KafkaCommandTransporterStrategy implements CommandTransporterStrategy { @Override public Boolean transportCommand(TransporterCommand command) { return postCommand(command); } KafkaCommandTransporterStrategy(KafkaTemplate<String, TransporterCommand> kafkaTemplate,
			KermossProperties kermossProperties); @Override Boolean transportPrepareCommand(final TransporterCommand command); @Override Boolean transportCommand(TransporterCommand command);  }
@Test public void whenKafkaProducerWorkTransportCommandReturnTrue() throws InterruptedException, ExecutionException { when(kermossProperties.getKafkaDestination(anyString())).thenReturn("io.kermoss.topic.pizza-shop"); ListenableFuture mock = mock(ListenableFuture.class); TransporterCommand command =mock(TransporterCommand.class); ListenableFuture<SendResult<String, TransporterCommand>> send = this.kafkaTemplate.send("io.kermoss.topic.pizza-shop", command); when(send).thenReturn(mock); Boolean transportCommand = kafkaCommandTransporterStrategy.transportCommand(command); Assert.assertTrue(transportCommand); }
@Test public void whenKafkaProducerFailTransportCommandReturnFalse() throws InterruptedException, ExecutionException { when(kermossProperties.getKafkaDestination(anyString())).thenReturn("io.kermoss.topic.pizza-shop"); ListenableFuture mock = mock(ListenableFuture.class); TransporterCommand command =mock(TransporterCommand.class); ListenableFuture<SendResult<String, TransporterCommand>> send = this.kafkaTemplate.send("io.kermoss.topic.pizza-shop", command); when(send).thenThrow(InterruptedException.class); Boolean transportCommand = kafkaCommandTransporterStrategy.transportCommand(command); Assert.assertFalse(transportCommand); }
@Test public void whenKafkaGetProducerFailTransportCommandReturnFalse() throws InterruptedException, ExecutionException { when(kermossProperties.getKafkaDestination(anyString())).thenReturn("io.kermoss.topic.pizza-shop"); ListenableFuture mock = mock(ListenableFuture.class); TransporterCommand command =mock(TransporterCommand.class); ListenableFuture<SendResult<String, TransporterCommand>> send = this.kafkaTemplate.send("io.kermoss.topic.pizza-shop", command); when(send).thenReturn(mock); when(mock.get()).thenThrow(ExecutionException.class); Boolean transportCommand = kafkaCommandTransporterStrategy.transportCommand(command); Assert.assertFalse(transportCommand); }
@Test public void whenTransportCommandUseGetMethod() throws InterruptedException, ExecutionException { when(kermossProperties.getKafkaDestination(anyString())).thenReturn("io.kermoss.topic.pizza-shop"); ListenableFuture mock = mock(ListenableFuture.class); TransporterCommand command =mock(TransporterCommand.class); ListenableFuture<SendResult<String, TransporterCommand>> send = this.kafkaTemplate.send("io.kermoss.topic.pizza-shop", command); when(send).thenReturn(mock); Boolean transportCommand = kafkaCommandTransporterStrategy.transportCommand(command); verify(mock).get(); Assert.assertTrue(transportCommand); }