StatusUpdater extends Thread { public void saveStatus() { connector.getStatusWriter().increment(getAndClearProcessed(), getAndClearFailed(), getAndClearDiscarded()); } StatusUpdater(DatabaseConnector<?> connector);  StatusUpdater(DatabaseConnector<?> connector, int updateIntervalMs); void setUpdateInterval(int updateIntervalMs); int getUpdateInterval(); synchronized void addProcessed(int toAdd); synchronized void addFailed(int toAdd); synchronized void addDiscarded(int toAdd); void run(); void saveStatus();  }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testSaveStatus() { DatabaseConnector<?> dbc = Mockito.mock(DatabaseConnector.class); StatusWriter sw = Mockito.mock(StatusWriter.class); Mockito.when(dbc.getStatusWriter()).thenReturn(sw); StatusUpdater su = new StatusUpdater(dbc); su.addProcessed(3); su.addFailed(2); su.addDiscarded(1); su.saveStatus(); Mockito.verify(sw).increment(3, 2, 1); su.saveStatus(); Mockito.verify(sw).increment(0, 0, 0); }