@Test
public void testFirstScan() {

    // 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 starts at 0%, so it returns 0 when the progress is queried:
    when(progressDialog.getProgress()).thenReturn(0);
    // 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 to update the progressDialog to the first step:
    verify(progressDialog).setProgress(100 / WifiCapturer.NUMBER_SCANS);
    // There is also supposed to be a second scan triggered (by the receiver), after the initial one:
    verify(wifiManager, times(2)).startScan();
    // And our HistogramConsumer should NOT YET have been passed a histogram, because we are in
    // progress/foreground/fingerprint-mode.
    verify(consumer, never()).addHistogram(any(Histogram.class));
}