WifiCapturer implements SensorCollector { @Override public void startSensors() { histogramBuilder = new HistogramBuilder("my histo", maxAge); wifiReceiver = new WifiReceiver(); activity.registerReceiver(wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); wifi = (WifiManager) activity.getSystemService(activity.WIFI_SERVICE); wifi.startScan(); } WifiCapturer(final Activity activity);  WifiCapturer(final Activity activity, final HistogramConsumer consumer, final int maxAge); void makeFingerprint(final  ProgressDialog progressDialog, final HistogramConsumer consumer); @Override void startSensors(); @Override void stopSensors(); static final String TAG; static final int NUMBER_SCANS; }
@Test public void testScanBuffer() { wifiCapturer.startSensors(); receiver = getReceiver(); 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); receiver.onReceive(null, null); receiver.onReceive(null, null); receiver.onReceive(null, null); verify(activity, never()).runOnUiThread(any(Runnable.class)); ArgumentCaptor<Histogram> consumerArgumentCaptor = ArgumentCaptor.forClass(Histogram.class); verify(consumer, times(3)).addHistogram(consumerArgumentCaptor.capture()); Histogram histogram1 = consumerArgumentCaptor.getAllValues().get(0); Histogram histogram2 = consumerArgumentCaptor.getAllValues().get(1); Histogram histogram3 = consumerArgumentCaptor.getAllValues().get(2); assertEquals(1, histogram1.size()); assertEquals(1, histogram2.size()); assertEquals(1, histogram3.size()); assertTrue(histogram1.keySet().contains("00:01:02:03:04:05")); assertTrue(histogram2.keySet().contains("00:01:02:03:04:05")); assertTrue(histogram3.keySet().contains("00:01:02:03:04:05")); Map<Integer, Float> levels1 = histogram1.get("00:01:02:03:04:05"); assertEquals(1, levels1.size()); assertEquals(1.0f, levels1.get(-50), 0.00001); Map<Integer, Float> levels2 = histogram2.get("00:01:02:03:04:05"); assertEquals(2, levels2.size()); assertEquals(0.5f, levels2.get(-40), 0.00001); assertEquals(0.5f, levels2.get(-50), 0.00001); Map<Integer, Float> levels3 = histogram3.get("00:01:02:03:04:05"); assertEquals(2, levels3.size()); assertEquals(1.0 / 3.0, levels3.get(-40), 0.00001); assertEquals(2.0 / 3.0, levels3.get(-50), 0.00001); }