Skip to content

Commit

Permalink
#3 feat : added one test to compare function
Browse files Browse the repository at this point in the history
the useNextComparatorForTieBreak() checks if the next comparator is used if the primary comparator find two entities are identical
  • Loading branch information
raeef96 committed Feb 21, 2024
1 parent 84f15fd commit ed8cfd1
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,24 @@ void withAuthorIsBeforeWithoutAuthorWhenSortingWithAuthor() {
BibEntry e2 = new BibEntry();
assertEquals(1, new EntryComparator(false, false, StandardField.AUTHOR).compare(e1, e2));
}

@Test
void useNextComparatorForTieBreak() {
// Entries with the same title
BibEntry entry1 = new BibEntry()
.withField(StandardField.TITLE, "Shared Title")
.withField(StandardField.YEAR, "2020");
BibEntry entry2 = new BibEntry()
.withField(StandardField.TITLE, "Shared Title")
.withField(StandardField.YEAR, "2019");

// Primary comparator based on title, next comparator based on year
EntryComparator entryComparator = new EntryComparator(false, false, StandardField.TITLE,
new EntryComparator(false, false, StandardField.YEAR));

// Expecting entry1 > entry2 because of the next comparator (year comparison)
assertEquals(1, entryComparator.compare(entry1, entry2));
}
}


0 comments on commit ed8cfd1

Please sign in to comment.