title: mockito - checking if condition passes and calls a method which does not return anythig
body: <p>I have the following service class:</p>
  
  <pre><code> class Person() {
  
     AgeDAO dao;
     Speaker speaker;
  
     public method checkSpeak( List&lt;Jon&gt; list) {
          List&lt;Integer&gt; ages = dao.getAge(list);
  
          if ( ages != null &amp;&amp; !ages.isEmpty() ) {
             speaker.speak(list);
          }
  
     }   
  
   }
  </code></pre>
  
  <p>Test class:</p>
  
  <pre><code> @Test
   class MyTest {
  
      void speakTest() {
          Person p = new Person();
          Speaker speaker = mock(Speaker.class); 
          p.speaker = speaker;
  
          AgeDAO dao = mock(AgeDAO.class);
          p.dao = dao;
  
          List&lt;Jon&gt; list = createJonList();
          List&lt;Integer&gt; ages = createAgesList();
          when(dao.getAge(anyList())).thenReturn(ages);
          p.checkSpeak(ages);
  
          verify(p.speaker).speak(anyList()); // This is not called/invoked.
  
      }
   }
  </code></pre>
  
  <p>I just want to verify <code>speak</code> is invoked. Should I still mock the method? If I need to mock the method, how do I mock the method that does not return anything. <code>when</code> requires a method return something.</p>