HistogramBuilder { public Histogram build() { final Histogram histogram = new Histogram(id); final Map<String, Levels> curves = makeCurves(); for (Map.Entry<String, Levels> curve : curves.entrySet()) { histogram.put(curve.getKey(), curve.getValue().getLevels()); } return histogram; } HistogramBuilder(final String id);  HistogramBuilder(final String id, final int maxAge); HistogramBuilder addScanResults(final List<WifiScanResult> scan); Histogram build();  }
@Test public void testBuild() { initMocks(this); HistogramBuilder builder; Histogram histogram; builder = new HistogramBuilder("some histogram"); histogram = builder.build(); assertEquals("some histogram", histogram.getId()); assert (histogram.keySet().isEmpty()); scan1 = new WifiScanResult("00:01:02:03:04:05", -50); List<WifiScanResult> scanResults = new ArrayList<WifiScanResult>(); scanResults.add(scan1); builder.addScanResults(scanResults); histogram = builder.build(); assertEquals(1, histogram.keySet().size()); Map<Integer, Float> levels = histogram.get("00:01:02:03:04:05"); assertEquals(1, levels.size()); assert (levels.get(-50) == 1.0f); scan1 = new WifiScanResult("00:01:02:03:04:05", -30); scan2 = new WifiScanResult("a0:b0:c0:d0:e0:f0", -40); scanResults.clear(); scanResults.add(scan1); scanResults.add(scan2); builder.addScanResults(scanResults); histogram = builder.build(); assertEquals(2, histogram.keySet().size()); assert (histogram.containsKey("00:01:02:03:04:05")); assert (histogram.keySet().contains("a0:b0:c0:d0:e0:f0")); levels = histogram.get("00:01:02:03:04:05"); assertEquals (2, levels.size()); assert (levels.get(-30) == 0.5f); assert (levels.get(-50) == 0.5f); levels = histogram.get("a0:b0:c0:d0:e0:f0"); assert (levels.size() == 1); assert (levels.get(-40) == 1f); scan1 = new WifiScanResult("00:01:02:03:04:05", -30); scan2 = new WifiScanResult("a0:b0:c0:d0:e0:f0", -40); scan3 = new WifiScanResult("01:23:45:67:89:ab", -20); scanResults.clear(); scanResults.add(scan1); scanResults.add(scan2); scanResults.add(scan3); builder.addScanResults(scanResults); histogram = builder.build(); assertEquals(3, histogram.keySet().size()); assert (histogram.containsKey("00:01:02:03:04:05")); assert (histogram.containsKey("a0:b0:c0:d0:e0:f0")); assert (histogram.containsKey("01:23:45:67:89:ab")); levels = histogram.get("00:01:02:03:04:05"); assert(levels.size() == 2); assertEquals(2.0f / 3.0f, levels.get(-30), 0.000001); assertEquals(1.0f / 3.0f, levels.get(-50), 0.000001); levels = histogram.get("a0:b0:c0:d0:e0:f0"); assert(levels.size() == 1); assert(levels.get(-40) == 1f); levels = histogram.get("01:23:45:67:89:ab"); assert(levels.size() == 1); assert(levels.get(-20) == 1f); }