Skip to content

Commit

Permalink
Refactor PageNumbersFormatter test
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-kolb committed Oct 28, 2015
1 parent 6624485 commit cc5db9f
Showing 1 changed file with 11 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,62 +22,41 @@ public void teardown() {

@Test
public void formatPageNumbers() {
String value = "1-2";
String result = formatter.format(value);

Assert.assertEquals("1--2", result);
expectCorrect("1-2", "1--2");
}

@Test
public void formatPageNumbersCommaSeparated() {
String value = "1,2,3";
String result = formatter.format(value);

Assert.assertEquals("1,2,3", result);
expectCorrect("1,2,3", "1,2,3");
}

@Test
public void ignoreWhitespaceInPageNumbers() {
String value = " 1 - 2 ";
String result = formatter.format(value);

Assert.assertEquals("1--2", result);
expectCorrect(" 1 - 2 ", "1--2");
}

@Test
public void keepCorrectlyFormattedPageNumbers() {
String value = "1--2";
String result = formatter.format(value);

Assert.assertEquals("1--2", result);
expectCorrect("1--2", "1--2");
}

@Test
public void formatPageNumbersEmptyFields() {
String value = "";
String result = formatter.format(value);

Assert.assertEquals("", result);

value = null;
result = formatter.format(value);

Assert.assertEquals(null, result);
expectCorrect("", "");
expectCorrect(null, null);
}

@Test
public void formatPageNumbersRemoveUnexpectedLiterals() {
String value = "{1}-{2}";
String result = formatter.format(value);

Assert.assertEquals("1--2", result);
expectCorrect("{1}-{2}", "1--2");
}

@Test
public void formatPageNumbersRegexNotMatching() {
String value = "12";
String result = formatter.format(value);
expectCorrect("12", "12");
}

Assert.assertEquals("12", result);
private void expectCorrect(String input, String expected) {
Assert.assertEquals(expected, formatter.format(input));
}
}

0 comments on commit cc5db9f

Please sign in to comment.