-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1687 "month" field ascending/descending sorting swapped
- Loading branch information
1 parent
9ac0e67
commit d2f27d2
Showing
3 changed files
with
199 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
src/test/java/net/sf/jabref/logic/bibtex/comparator/FieldComparatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package net.sf.jabref.logic.bibtex.comparator; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class FieldComparatorTest { | ||
@Test | ||
public void compareMonthFieldIdentity() throws Exception { | ||
FieldComparator comparator = new FieldComparator("month"); | ||
BibEntry equal = new BibEntry(); | ||
equal.setField("month", "1"); | ||
|
||
assertEquals(0, comparator.compare(equal, equal)); | ||
} | ||
|
||
@Test | ||
public void compareMonthFieldEquality() throws Exception { | ||
FieldComparator comparator = new FieldComparator("month"); | ||
BibEntry equal = new BibEntry(); | ||
equal.setField("month", "1"); | ||
BibEntry equal2 = new BibEntry(); | ||
equal2.setField("month", "1"); | ||
|
||
assertEquals(0, comparator.compare(equal, equal2)); | ||
} | ||
|
||
@Test | ||
public void compareMonthFieldBiggerAscending() throws Exception { | ||
FieldComparator comparator = new FieldComparator("month"); | ||
BibEntry smaller = new BibEntry(); | ||
smaller.setField("month", "jan"); | ||
BibEntry bigger = new BibEntry(); | ||
bigger.setField("month", "feb"); | ||
|
||
assertEquals(1, comparator.compare(bigger, smaller)); | ||
} | ||
|
||
@Test | ||
public void compareMonthFieldBiggerDescending() throws Exception { | ||
FieldComparator comparator = new FieldComparator("month", true); | ||
BibEntry smaller = new BibEntry(); | ||
smaller.setField("month", "feb"); | ||
BibEntry bigger = new BibEntry(); | ||
bigger.setField("month", "jan"); | ||
|
||
assertEquals(1, comparator.compare(bigger, smaller)); | ||
} | ||
|
||
@Test | ||
public void compareYearFieldIdentity() throws Exception { | ||
FieldComparator comparator = new FieldComparator("year"); | ||
BibEntry equal = new BibEntry(); | ||
equal.setField("year", "2016"); | ||
|
||
assertEquals(0, comparator.compare(equal, equal)); | ||
} | ||
|
||
@Test | ||
public void compareYearFieldEquality() throws Exception { | ||
FieldComparator comparator = new FieldComparator("year"); | ||
BibEntry equal = new BibEntry(); | ||
equal.setField("year", "2016"); | ||
BibEntry equal2 = new BibEntry(); | ||
equal2.setField("year", "2016"); | ||
|
||
assertEquals(0, comparator.compare(equal, equal2)); | ||
} | ||
|
||
@Test | ||
public void compareYearFieldBiggerAscending() throws Exception { | ||
FieldComparator comparator = new FieldComparator("year"); | ||
BibEntry smaller = new BibEntry(); | ||
smaller.setField("year", "2000"); | ||
BibEntry bigger = new BibEntry(); | ||
bigger.setField("year", "2016"); | ||
|
||
assertEquals(1, comparator.compare(bigger, smaller)); | ||
} | ||
|
||
@Test | ||
public void compareYearFieldBiggerDescending() throws Exception { | ||
FieldComparator comparator = new FieldComparator("year", true); | ||
BibEntry smaller = new BibEntry(); | ||
smaller.setField("year", "2016"); | ||
BibEntry bigger = new BibEntry(); | ||
bigger.setField("year", "2000"); | ||
|
||
assertEquals(1, comparator.compare(bigger, smaller)); | ||
} | ||
|
||
@Test | ||
public void compareTypeFieldIdentity() throws Exception { | ||
FieldComparator comparator = new FieldComparator("entrytype"); | ||
BibEntry equal = new BibEntry("1", "article"); | ||
|
||
assertEquals(0, comparator.compare(equal, equal)); | ||
} | ||
|
||
@Test | ||
public void compareTypeFieldEquality() throws Exception { | ||
FieldComparator comparator = new FieldComparator("entrytype"); | ||
BibEntry equal = new BibEntry("1", "article"); | ||
BibEntry equal2 = new BibEntry("1", "article"); | ||
|
||
assertEquals(0, comparator.compare(equal, equal2)); | ||
} | ||
|
||
@Test | ||
public void compareTypeFieldBiggerAscending() throws Exception { | ||
FieldComparator comparator = new FieldComparator("entrytype"); | ||
BibEntry smaller = new BibEntry("1", "article"); | ||
BibEntry bigger = new BibEntry("2", "book"); | ||
|
||
assertEquals(1, comparator.compare(bigger, smaller)); | ||
} | ||
|
||
@Test | ||
public void compareTypeFieldBiggerDescending() throws Exception { | ||
FieldComparator comparator = new FieldComparator("entrytype", true); | ||
BibEntry bigger = new BibEntry("1", "article"); | ||
BibEntry smaller = new BibEntry("2", "book"); | ||
|
||
assertEquals(1, comparator.compare(bigger, smaller)); | ||
} | ||
|
||
@Test | ||
public void compareStringFieldsIdentity() throws Exception { | ||
FieldComparator comparator = new FieldComparator("title"); | ||
BibEntry equal = new BibEntry(); | ||
equal.setField("title", "title"); | ||
|
||
assertEquals(0, comparator.compare(equal, equal)); | ||
} | ||
|
||
@Test | ||
public void compareStringFieldsEquality() throws Exception { | ||
FieldComparator comparator = new FieldComparator("title"); | ||
BibEntry equal = new BibEntry(); | ||
equal.setField("title", "title"); | ||
BibEntry equal2 = new BibEntry(); | ||
equal2.setField("title", "title"); | ||
|
||
assertEquals(0, comparator.compare(equal, equal2)); | ||
} | ||
|
||
@Test | ||
public void compareStringFieldsBiggerAscending() throws Exception { | ||
FieldComparator comparator = new FieldComparator("title"); | ||
BibEntry bigger = new BibEntry(); | ||
bigger.setField("title", "b"); | ||
BibEntry smaller = new BibEntry(); | ||
smaller.setField("title", "a"); | ||
|
||
assertEquals(1, comparator.compare(bigger, smaller)); | ||
} | ||
|
||
@Test | ||
public void compareStringFieldsBiggerDescending() throws Exception { | ||
FieldComparator comparator = new FieldComparator("title", true); | ||
BibEntry bigger = new BibEntry(); | ||
bigger.setField("title", "a"); | ||
BibEntry smaller = new BibEntry(); | ||
smaller.setField("title", "b"); | ||
|
||
assertEquals(1, comparator.compare(bigger, smaller)); | ||
} | ||
|
||
@Test | ||
public void nameOfComparisonField() throws Exception { | ||
FieldComparator comparator = new FieldComparator("title"); | ||
assertEquals("title", comparator.getFieldName()); | ||
} | ||
|
||
@Test | ||
public void nameOfComparisonFieldAlias() throws Exception { | ||
FieldComparator comparator = new FieldComparator("author/editor"); | ||
assertEquals("author/editor", comparator.getFieldName()); | ||
} | ||
} |