Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
w3stling committed Aug 14, 2023
1 parent 87a56cc commit b897581
Showing 1 changed file with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,36 @@ public class ItemComparatorTest {
@Test
void testSortNewestItem() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
.sorted(ItemComparator.newestItemFirst())
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
.map(ZonedDateTime::toEpochSecond)
.collect(Collectors.toList());
.sorted(ItemComparator.newestItemFirst())
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
.map(ZonedDateTime::toEpochSecond)
.collect(Collectors.toList());

assertTrue(isDescendingSortOrder(items));
}

@Test
void testSortNewestItemWithCustomDateTimeParser() throws IOException {
var items = new RssReader().setDateTimeParser(new DateTime())
.read("https://www.theverge.com/rss/reviews/index.xml")
.sorted(ItemComparator.newestItemFirst())
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
.map(ZonedDateTime::toEpochSecond)
.collect(Collectors.toList());

assertTrue(isDescendingSortOrder(items));
}

@Test
void testSortNewestItemWithDateTimeParser() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
.sorted(ItemComparator.newestItemFirst(new DateTime()))
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
.map(ZonedDateTime::toEpochSecond)
.collect(Collectors.toList());
.sorted(ItemComparator.newestItemFirst(new DateTime()))
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
.map(ZonedDateTime::toEpochSecond)
.collect(Collectors.toList());

assertTrue(isDescendingSortOrder(items));
}
Expand All @@ -52,10 +65,10 @@ void testSortOldestItemFirst() throws IOException {
@Test
void testSortOldestItemFirstWithDateTimeParser() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
.sorted(ItemComparator.oldestItemFirst(new DateTime()))
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
.collect(Collectors.toList());
.sorted(ItemComparator.oldestItemFirst(new DateTime()))
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
.collect(Collectors.toList());

assertTrue(isAscendingSortOrder(items));
}
Expand All @@ -64,10 +77,10 @@ void testSortOldestItemFirstWithDateTimeParser() throws IOException {
void testSortChannelTitle() {
var urlList = List.of("https://www.theverge.com/rss/reviews/index.xml", "https://feeds.macrumors.com/MacRumors-All");
var items = new RssReader().read(urlList)
.sorted(ItemComparator.channelTitle())
.map(i -> i.getChannel().getTitle())
.filter(Objects::nonNull)
.collect(Collectors.toList());
.sorted(ItemComparator.channelTitle())
.map(i -> i.getChannel().getTitle())
.filter(Objects::nonNull)
.collect(Collectors.toList());

assertTrue(isAscendingSortOrder(items));
}
Expand Down

0 comments on commit b897581

Please sign in to comment.