@Test
public void testLastScan() {

    // Setup: trigger the scan and pass our progressDialog-mock as callback-object:
    wifiCapturer.makeFingerprint(progressDialog, consumer);
    // Get us the BroadcastReceiver that the Captor has created for the wifi-notifications:
    receiver = getReceiver();
    // The progressDialog-mock is now supposed to indicate the last scan:
    when(progressDialog.getProgress()).thenReturn(100);
    // Send fake-notification to the receiver:
    receiver.onReceive(null, null);
    // We need the Runnable that the WifiReceiver creates because we need to execute it to see what it does:
    ArgumentCaptor<Runnable> uiRunnableArgumentCaptor = ArgumentCaptor.forClass(Runnable.class);
    verify(activity).runOnUiThread(uiRunnableArgumentCaptor.capture());
    Runnable uiRunnable = uiRunnableArgumentCaptor.getValue();
    // We have no uiThread so we call the Runnable ourselves.
    uiRunnable.run();
    // The Runnable was supposed dismiss the progressDialog:
    verify(progressDialog).dismiss();
    // Because we are done there should not be a second scan:
    verify(wifiManager, times(1)).startScan();
    // And our HistogramConsumer should have been passed a histogram, because we finished.
    verify(consumer).addHistogram(any(Histogram.class));
}