title: Mockito UnfinishedVerificationException
body: <p>The problem is the following. I have several reports that I want to mock and test with <code>Mockito</code>. Each report gives the same <code>UnfinishedVerificationException</code> and nothing that I tried so far worked in order to fix the issue. Example of one of the reports with all parents is below.</p>
  
  <ul>
  <li>I changed <code>any</code> to <code>anyString</code>.</li>
  <li>Change <code>ReportSaver</code> from <code>interface</code> to <code>abstract class</code></li>
  <li>Add <code>validateMockitoUsage</code> to nail the right test</li>
  <li>Looked into similar <code>Mockito</code>-related cases on <code>StackOverflow</code></li>
  </ul>
  
  <p><strong>Test:</strong></p>
  
  <pre><code>public class ReportProcessorTest {
  
      private ReportProcessor reportProcessor;
  
      private ByteArrayOutputStream mockOutputStream = (new ReportProcessorMock()).mock();
  
      @SuppressWarnings("serial")
      private final static Map&lt;String, Object&gt; epxectedMaps = new HashMap&lt;String, Object&gt;();
  
      @Before
      public void setUp() throws IOException {
          reportProcessor = mock(ReportProcessor.class);
          ReflectionTestUtils.setField(reportProcessor, "systemOffset", "Europe/Berlin");
          ReflectionTestUtils.setField(reportProcessor, "redisKeyDelimiter", "#");
  
          Mockito.doNothing().when(reportProcessor).saveReportToDestination(Mockito.any(), Mockito.anyString());
          Mockito.doCallRealMethod().when(reportProcessor).process(Mockito.any());
      }
  
      @Test
      public void calculateSales() throws IOException {
          Map&lt;String, Object&gt; processedReport = reportProcessor.process(mockOutputStream);
          verify(reportProcessor, times(1)); // The line that cause troubles
          assertThat(Maps.difference(processedReport, epxectedMaps).areEqual(), Matchers.is(true));
      }
  
      @After
      public void validate() {
          Mockito.validateMockitoUsage();
      }
  }
  </code></pre>
  
  <p><strong>Class under test:</strong></p>
  
  <pre><code>@Component
  public class ReportProcessor extends ReportSaver {
  
      @Value("${system.offset}")
      private String systemOffset;
  
      @Value("${report.relativePath}")
      private String destinationPathToSave;
  
      @Value("${redis.delimiter}")
      private String redisKeyDelimiter;
  
      public Map&lt;String, Object&gt; process(ByteArrayOutputStream outputStream) throws IOException {
          saveReportToDestination(outputStream, destinationPathToSave);
          Map&lt;String, Object&gt; report = new HashMap&lt;&gt;();
  
          try (InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
               InputStreamReader reader = new InputStreamReader(inputStream)) {
  
              CSVReaderHeaderAware csvReader = new CSVReaderFormatter(outputStream).headerAware(reader);
  
              Map&lt;String, String&gt; data;
              while ((data = csvReader.readMap()) != null) {
  
                  String data = data.get("data").toUpperCase();
                  Long quantity = NumberUtils.toLong(data.get("quantity"));
  
                  report.put(data, quantity);
              }
          }
  
          return report;
      }
  }
  </code></pre>
  
  <p><strong>Parent class:</strong></p>
  
  <pre><code>public abstract class ReportSaver {
  
      public void saveReportToDestination(ByteArrayOutputStream outputStream, String destinationPathToSave) throws IOException {
          File destinationFile = new File(destinationPathToSave);
          destinationFile.getParentFile().mkdirs();
          destinationFile.delete();
          destinationFile.createNewFile();
          OutputStream fileOutput = new FileOutputStream(destinationFile);
          outputStream.writeTo(fileOutput);
      }
  }
  </code></pre>
  
  <p><strong>Mock:</strong></p>
  
  <pre><code>public class ReportProcessorMock implements GeneralReportProcessorMock {
  
      private static final String report = ""; // There can be some data in here
  
      @Override
      public ByteArrayOutputStream mock() {
          byte[] reportBytes = report.getBytes();
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream(reportBytes.length);
          outputStream.write(reportBytes, 0, reportBytes.length);
          return outputStream;
      }
  }
  </code></pre>