Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
w3stling committed Dec 5, 2024
1 parent 32ac3d7 commit 4d935c8
Show file tree
Hide file tree
Showing 2 changed files with 259 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Objects;
Expand All @@ -16,7 +17,7 @@ class ItemComparatorTest {

@Test
void testSortNewestItem() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
var items = new RssReader().read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.newestItemFirst())
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -28,7 +29,7 @@ void testSortNewestItem() throws IOException {

@Test
void testSortNewestPublishedItem() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
var items = new RssReader().read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.newestPublishedItemFirst())
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -41,7 +42,7 @@ void testSortNewestPublishedItem() throws IOException {
@Test
void testSortNewestItemWithCustomDateTimeParser() throws IOException {
var items = new RssReader().setDateTimeParser(Default.getDateTimeParser())
.read("https://www.theverge.com/rss/reviews/index.xml")
.read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.newestItemFirst())
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -54,7 +55,7 @@ void testSortNewestItemWithCustomDateTimeParser() throws IOException {
@Test
void testSortNewestPublishedItemWithCustomDateTimeParser() throws IOException {
var items = new RssReader().setDateTimeParser(Default.getDateTimeParser())
.read("https://www.theverge.com/rss/reviews/index.xml")
.read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.newestPublishedItemFirst())
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -66,7 +67,7 @@ void testSortNewestPublishedItemWithCustomDateTimeParser() throws IOException {

@Test
void testSortNewestItemWithDateTimeParser() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
var items = new RssReader().read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.newestItemFirst(Default.getDateTimeParser()))
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -78,7 +79,7 @@ void testSortNewestItemWithDateTimeParser() throws IOException {

@Test
void testSortNewestPublishedItemWithDateTimeParser() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
var items = new RssReader().read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.newestPublishedItemFirst(Default.getDateTimeParser()))
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -90,7 +91,7 @@ void testSortNewestPublishedItemWithDateTimeParser() throws IOException {

@Test
void testSortOldestItemFirst() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
var items = new RssReader().read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.oldestItemFirst())
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -101,7 +102,7 @@ void testSortOldestItemFirst() throws IOException {

@Test
void testSortOldestPublishedItemFirst() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
var items = new RssReader().read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.oldestPublishedItemFirst())
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -112,7 +113,7 @@ void testSortOldestPublishedItemFirst() throws IOException {

@Test
void testSortOldestItemFirstWithDateTimeParser() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
var items = new RssReader().read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.oldestItemFirst(Default.getDateTimeParser()))
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -123,7 +124,7 @@ void testSortOldestItemFirstWithDateTimeParser() throws IOException {

@Test
void testSortOldestPublishedItemFirstWithDateTimeParser() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
var items = new RssReader().read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.oldestPublishedItemFirst(Default.getDateTimeParser()))
.map(i -> i.getPubDateZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -134,7 +135,7 @@ void testSortOldestPublishedItemFirstWithDateTimeParser() throws IOException {

@Test
void testSortNewestUpdatedItem() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
var items = new RssReader().read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.newestUpdatedItemFirst())
.map(i -> i.getUpdatedZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -147,7 +148,7 @@ void testSortNewestUpdatedItem() throws IOException {
@Test
void testSortNewestUpdatedItemWithCustomDateTimeParser() throws IOException {
var items = new RssReader().setDateTimeParser(Default.getDateTimeParser())
.read("https://www.theverge.com/rss/reviews/index.xml")
.read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.newestUpdatedItemFirst())
.map(i -> i.getUpdatedZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -159,7 +160,7 @@ void testSortNewestUpdatedItemWithCustomDateTimeParser() throws IOException {

@Test
void testSortNewestUpdatedItemWithDateTimeParser() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
var items = new RssReader().read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.newestUpdatedItemFirst(Default.getDateTimeParser()))
.map(i -> i.getUpdatedZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -171,7 +172,7 @@ void testSortNewestUpdatedItemWithDateTimeParser() throws IOException {

@Test
void testSortOldestUpdatedItemFirst() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
var items = new RssReader().read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.oldestUpdatedItemFirst())
.map(i -> i.getUpdatedZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand All @@ -182,7 +183,7 @@ void testSortOldestUpdatedItemFirst() throws IOException {

@Test
void testSortOldestUpdatedItemFirstWithDateTimeParser() throws IOException {
var items = new RssReader().read("https://www.theverge.com/rss/reviews/index.xml")
var items = new RssReader().read(fromFile("item-sort-test.xml"))
.sorted(ItemComparator.oldestUpdatedItemFirst(Default.getDateTimeParser()))
.map(i -> i.getUpdatedZonedDateTime().orElse(null))
.filter(Objects::nonNull)
Expand Down Expand Up @@ -222,4 +223,8 @@ private static <T extends Comparable<? super T>> boolean isDescendingSortOrder(L
return true;
}

private InputStream fromFile(String fileName) {
return getClass().getClassLoader().getResourceAsStream(fileName);
}

}
Loading

0 comments on commit 4d935c8

Please sign in to comment.