package net.sf.jabref.logic.formatter;

import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class PageNumbersFormatterTest {
    private PageNumbersFormatter formatter;

    @Before
    public void setUp() {
        formatter = new PageNumbersFormatter();
    }

    @After
    public void teardown() {
        formatter = null;
    }

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

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

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

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

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

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

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

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

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

        Assert.assertEquals("", result);

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

        Assert.assertEquals(null, result);
    }

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

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

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

        Assert.assertEquals("12", result);
    }
}
@@ -483,122 +483,35 @@
     
-String value = %221-2%22;%0A        String result = formatter.format(value);%0A%0A        Assert.assertEquals
+expectCorrect
 (%221-
--
 2%22, 
-result
+%221--2%22
 );%0A 
@@ -590,506 +590,245 @@
     
-String value = %221,2,3%22;%0A        String result = formatter.format(value);%0A%0A        Assert.assertEquals(%221,2,3%22, result);%0A    %7D%0A%0A    @Test%0A    public void ignoreWhitespaceInPageNumbers() %7B%0A        String value = %22   1  - 2 %22;%0A        String result = formatter.format(value);%0A%0A        Assert.assertEquals(%221--2%22, result);%0A    %7D%0A%0A    @Test%0A    public void keepCorrectlyFormattedPageNumbers() %7B%0A        String value = %221--2%22;%0A        String result = formatter.format(value);%0A%0A        Assert.assertEquals
+expectCorrect(%221,2,3%22, %221,2,3%22);%0A    %7D%0A%0A    @Test%0A    public void ignoreWhitespaceInPageNumbers() %7B%0A        expectCorrect(%22   1  - 2 %22, %221--2%22);%0A    %7D%0A%0A    @Test%0A    public void keepCorrectlyFormattedPageNumbers() %7B%0A        expectCorrect
 (%221-
@@ -824,38 +824,38 @@
 Correct(%221--2%22, 
-result
+%221--2%22
 );%0A    %7D%0A%0A    @T
@@ -919,127 +919,39 @@
     
-String value = %22%22;%0A        String result = formatter.format(value);%0A%0A        Assert.assertEquals(%22%22, result
+expectCorrect(%22%22, %22%22
 );%0A
-%0A
         
 valu
@@ -950,105 +950,32 @@
     
-value = null;%0A        result = formatter.format(value);%0A%0A        Assert.assertEquals
+expectCorrect
 (null, 
-result
+null
 );%0A 
@@ -1064,126 +1064,39 @@
     
-String value = %22%7B1%7D-%7B2%7D%22;%0A        String result = formatter.format(value);%0A%0A        Assert.assertEquals(%221--2%22, result
+expectCorrect(%22%7B1%7D-%7B2%7D%22, %221--2%22
 );%0A 
@@ -1177,119 +1177,167 @@
     
-String value =
+expectCorrect(%2212%22,
  %2212%22
+)
 ;%0A   
+ %7D%0A%0A
     
- String result = formatter.format(value);%0A%0A        Assert.assertEquals(%2212%22, result
+private void expectCorrect(String input, String expected) %7B%0A        Assert.assertEquals(expected, formatter.format(input)
 );%0A 

Refactor PageNumbersFormatter test