title: How do you write a java unit test of a class method that does not return a value?
body: <p>I am a newbie to Java unit testing and need help writing a unit test that just needs to handle 2 paths of an &quot;if&quot; statement where the method has no return value.</p>
  <pre><code>public class Consumer extends KafkaConsumer {
      private final MessageService service;
  
      public Consumer(MessageService service) {
          this.service = service;
      }
  
      @Override
      protected void processRecords(ConsumerRecords&lt;Long, String&gt; records) {
          for (ConsumerRecord&lt;Long, String&gt; records) {
              if (record.value().startsWith(&quot;{&quot;)) {
                  OldFormatMessageObject mo = new OldFormatMessageObject(record.value());
                  service.processMessage(mo);
              } else if (record.value().startsWith(&quot;metadata&quot;)) {
                  NewFormatMessageObject mo = new NewFormatMessageObject(record.value());
                  service.processMessage(mo);
              }
          }
      }
  </code></pre>