SeparatorAnalyzer implements Consumer<Separator> { public int compare(Separator s1, Separator s2) { return comparator.compare(s1, s2); } SeparatorAnalyzer(int numberOfLines, List<String> sampleLines); @Override void accept(Separator separator); int compare(Separator s1, Separator s2);  }
@Test(expected = IllegalArgumentException.class) public void should_throw_illegal_argument_exception_when_first_separator_is_null() { final Separator semiColonSeparator = new Separator(';'); SeparatorAnalyzer separatorAnalyzer = new SeparatorAnalyzer(1, Collections.emptyList()); separatorAnalyzer.compare(null, semiColonSeparator); }
@Test(expected = IllegalArgumentException.class) public void should_throw_illegal_argument_exception_when_second_separator_is_null() { final Separator semiColonSeparator = new Separator(';'); SeparatorAnalyzer separatorAnalyzer = new SeparatorAnalyzer(1, Collections.emptyList()); separatorAnalyzer.compare(semiColonSeparator, null); }
@Test public void should_return_char_with_more_priority() { final Separator semiColonSeparator = new Separator(';'); final Separator commaSeparator = new Separator(','); final Separator spaceSeparator = new Separator(' '); final Separator tabulationSeparator = new Separator('\t'); final Separator invalidSeparator = new Separator('A'); SeparatorAnalyzer separatorAnalyzer = new SeparatorAnalyzer(1, Collections.emptyList()); assertTrue(separatorAnalyzer.compare(semiColonSeparator, commaSeparator) < 0); assertTrue(separatorAnalyzer.compare(commaSeparator, tabulationSeparator) < 0); assertTrue(separatorAnalyzer.compare(tabulationSeparator, spaceSeparator) < 0); assertTrue(separatorAnalyzer.compare(spaceSeparator, invalidSeparator) < 0); }
@Test public void should_return_char_with_more_consistency_level() { final Separator semiColonSeparator = new Separator(';'); final Separator commaSeparator = new Separator(','); commaSeparator.incrementCount(1); final Separator tabulationSeparator = new Separator('\t'); tabulationSeparator.incrementCount(2); tabulationSeparator.incrementCount(3); final Separator spaceSeparator = new Separator(' '); spaceSeparator.incrementCount(1); spaceSeparator.incrementCount(2); SeparatorAnalyzer separatorAnalyzer = new SeparatorAnalyzer(3, Collections.emptyList()); assertTrue(separatorAnalyzer.compare(spaceSeparator, tabulationSeparator) < 0); assertTrue(separatorAnalyzer.compare(tabulationSeparator, commaSeparator) < 0); assertTrue(separatorAnalyzer.compare(commaSeparator, semiColonSeparator) < 0); }
@Test public void should_return_separator_with_more_reliable_header_info() { final Separator semiColonSeparator = new Separator(';'); final Separator commaSeparator = new Separator(','); commaSeparator.setHeaderInfoReliable(true); semiColonSeparator.setHeaderInfoReliable(false); SeparatorAnalyzer separatorAnalyzer = new SeparatorAnalyzer(3, Collections.emptyList()); assertTrue(separatorAnalyzer.compare(commaSeparator, semiColonSeparator) < 0); }
@Test public void should_return_separator_with_first_line_as_header() { final Separator semiColonSeparator = new Separator(';'); final Separator commaSeparator = new Separator(','); commaSeparator.setFirstLineAHeader(true); semiColonSeparator.setFirstLineAHeader(false); SeparatorAnalyzer separatorAnalyzer = new SeparatorAnalyzer(3, Collections.emptyList()); assertTrue(separatorAnalyzer.compare(commaSeparator, semiColonSeparator) < 0); }
@Test public void should_return_separator_with_first_more_columns() { final Separator semiColonSeparator = new Separator(';'); List<Pair<String, Type>> semiColonHeader = new ArrayList<>(); semiColonHeader.add(new Pair<>("First", Type.STRING)); semiColonSeparator.setHeaders(semiColonHeader); final Separator commaSeparator = new Separator(','); List<Pair<String, Type>> commaHeader = new ArrayList<>(); commaHeader.add(new Pair<>("First", Type.STRING)); commaHeader.add(new Pair<>("Last", Type.STRING)); commaSeparator.setHeaders(commaHeader); SeparatorAnalyzer separatorAnalyzer = new SeparatorAnalyzer(3, Collections.emptyList()); assertTrue(separatorAnalyzer.compare(commaSeparator, semiColonSeparator) < 0); }
@Test public void should_return_arbitrarily_first_separator() { final Separator invalidSeparator1 = new Separator('A'); final Separator invalidSeparator2 = new Separator('B'); SeparatorAnalyzer separatorAnalyzer = new SeparatorAnalyzer(1, Collections.emptyList()); assertTrue(separatorAnalyzer.compare(invalidSeparator1, invalidSeparator2) < 0); }