### Question:
HeaderDetector implements CellDetector<Integer> { @Override public ValuesWithConfidence<Integer> detect(CellSampler sampler) { ValuesWithConfidence<Integer> returnValue; if (myColumnCount > 1) { returnValue = detectFromMultipleColumns(sampler); } else { returnValue = detectFromSingleColumn(sampler); } return returnValue; } HeaderDetector(int columnCount); @Override ValuesWithConfidence<Integer> detect(CellSampler sampler);  }### Answer:
@Test public void testBasic() { List<List<String>> cells = CsvTestUtils.createBasicData(); CellSampler sampler = createMockCellSampler(cells); ValuesWithConfidence<Integer> result = new HeaderDetector(5).detect(sampler); Assert.assertEquals(1f, result.getBestConfidence(), 0f); Assert.assertEquals(0, result.getBestValue().intValue()); }
@Test public void testCrap() { List<List<String>> cells = New.list(); List<String> rows = CsvTestUtils.createCrap(); for (String row : rows) { cells.add(Collections.singletonList(row)); } cells.addAll(CsvTestUtils.createBasicData()); CellSampler sampler = createMockCellSampler(cells); ValuesWithConfidence<Integer> result = new HeaderDetector(5).detect(sampler); Assert.assertEquals(1f, result.getBestConfidence(), 0f); Assert.assertEquals(rows.size(), result.getBestValue().intValue()); }
@Test public void testNoHeader() { List<List<String>> cells = New.list(); List<String> rows = CsvTestUtils.createHardData(); for (String row : rows) { cells.add(Arrays.asList(row.split(","))); } CellSampler sampler = createMockCellSampler(cells); ValuesWithConfidence<Integer> result = new HeaderDetector(3).detect(sampler); Assert.assertEquals(0f, result.getBestConfidence(), 0f); }
@Test public void testSpacesAndUnderscoresAndQuotes() { final List<List<String>> cells = New.list(); cells.add(Arrays.asList("There", " is a 'house'", " in_\"New_Orleans\"")); cells.add(Arrays.asList("5", "8", "12")); cells.add(Arrays.asList("a", "", "")); CellSampler sampler = createMockCellSampler(cells); ValuesWithConfidence<Integer> result = new HeaderDetector(3).detect(sampler); Assert.assertEquals(1f, result.getBestConfidence(), 0f); Assert.assertEquals(0, result.getBestValue().intValue()); }