@Test
public void testFingerprintHistogram() {

    wifiCapturer.makeFingerprint(progressDialog, consumer);
    // Get us the BroadcastReceiver that the Captor has created for the wifi-notifications:
    receiver = getReceiver();
    // The progressDialog-mock will indicate "unfinished" two times, and "100%" on the third call:
    when(progressDialog.getProgress()).thenReturn(1, 2, 100);
    // The WifiManager-mock will return three different scanresults, one on each call to getScanResults:
    List<ScanResult> scanResult1 = makeScanResult(scan1, -50);
    List<ScanResult> scanResult2 = makeScanResult(scan2, -40);
    List<ScanResult> scanResult3 = makeScanResult(scan3, -50);
    when(wifiManager.getScanResults()).thenReturn(scanResult1, scanResult2, scanResult3);
    // Send 3 fake-notifications to the receiver:
    receiver.onReceive(null, null);
    receiver.onReceive(null, null);
    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);
    Runnable uiRunnable;
    // The ArgumentCaptor will automagically capture the arguments for each invocation:
    verify(activity, times(3)).runOnUiThread(uiRunnableArgumentCaptor.capture());
    // Now we get the three runnables and execute them all. The last should build our histogram, and the first two
    // should simply not break anything :-)
    uiRunnable = uiRunnableArgumentCaptor.getAllValues().get(0);
    uiRunnable.run();
    uiRunnable = uiRunnableArgumentCaptor.getAllValues().get(1);
    uiRunnable.run();
    uiRunnable = uiRunnableArgumentCaptor.getAllValues().get(2);
    uiRunnable.run();
    // After the third time the histogram should be built and we can verify its contents, step by step:
    ArgumentCaptor<Histogram> consumerArgumentCaptor = ArgumentCaptor.forClass(Histogram.class);
    verify(consumer).addHistogram(consumerArgumentCaptor.capture());
    Histogram histogram =  consumerArgumentCaptor.getValue();
    assertEquals(1, histogram.size());
    assertTrue(histogram.keySet().contains("00:01:02:03:04:05"));
    Map<Integer, Float> levels = histogram.get("00:01:02:03:04:05");
    assertEquals(2, levels.size());
    // Stupid floats need not be exactly equal:
    assertEquals(1.0 / 3.0, levels.get(-40), 0.00001);
    assertEquals(2.0 / 3.0, levels.get(-50), 0.00001);
}