title: How to write Unit test case for adding callback for ListenableFuture
body: <p>I am trying to write the unit test case for ListenableFuture adding Callback but I am not sure how to do it. Didn`t get anything useful on internet.</p>
  
  <pre><code> @Test
      public void can_publish_data_to_kafka() {
          String topic = someString(10);
          String key = someAlphanumericString(5);
          String data = someString(50);
          SendResult sendResult = mock(SendResult.class);
          ListenableFuture&lt;SendResult&lt;String, Object&gt;&gt; future = mock(ListenableFuture.class);
  
          given(kafkaTemplate.send(topic, key, data)).willReturn(future);
  
          doAnswer(new Answer() {
              @Override
              public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                  return invocationOnMock.getArguments()[1];
              }
          });
  
          service.method(key, topic, data);
  
      }
  </code></pre>
  
  <p>Code for which i want to write test case</p>
  
  <pre><code>ListenableFuture&lt;SendResult&lt;String, Object&gt;&gt; future = kafkaTemplate.send(topicName, key, data);
  
          future.addCallback(new ListenableFutureCallback&lt;SendResult&lt;String, Object&gt;&gt;() {
              @Override
              public void onSuccess(SendResult&lt;String, Object&gt; stringKafkaBeanSendResult) {
                  RecordMetadata recordMetadata = stringKafkaBeanSendResult.getRecordMetadata();
                  LOGGER.info(String.format("sent message %s to topic %s partition %s with offset %s" + data.toString(), recordMetadata.topic(), recordMetadata.partition(), recordMetadata.offset()));
              }
  
              @Override
              public void onFailure(Throwable throwable) {
                  LOGGER.error(String.format("unable to send message = %s to topic %s because of error %s" + data.toString(), topicName, throwable.getMessage()));
              }
          });
  </code></pre>
  
  <p>I am expecting a direction in which i should go towards for writing UT using mockito.</p>