Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/gradle/org.mockito-mockito-core…
Browse files Browse the repository at this point in the history
…-5.4.0
  • Loading branch information
w3stling authored Aug 7, 2023
2 parents b555bc1 + 041a366 commit 8153d14
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'signing'
id 'maven-publish'
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
id 'org.sonarqube' version '4.2.1.3168'
id 'org.sonarqube' version '4.3.0.3225'
}

group 'com.apptasticsoftware'
Expand All @@ -20,7 +20,7 @@ dependencies {
testImplementation('com.github.npathai:hamcrest-optional:2.0.0')
testImplementation('org.hamcrest:hamcrest:2.2')
testImplementation('org.mockito:mockito-core:5.4.0')
testImplementation('nl.jqno.equalsverifier:equalsverifier:3.14.2')
testImplementation('nl.jqno.equalsverifier:equalsverifier:3.15.1')
}

test {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/apptasticsoftware/rssreader/DateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class DateTime {
public static final DateTimeFormatter BASIC_ISO_DATE;
public static final DateTimeFormatter ISO_LOCAL_DATE;
public static final DateTimeFormatter ISO_OFFSET_DATE_TIME;
public static final DateTimeFormatter ISO_OFFSET_DATE_TIME_SPECIAL;
public static final DateTimeFormatter ISO_LOCAL_DATE_TIME;
public static final DateTimeFormatter ISO_LOCAL_DATE_TIME_SPECIAL;

Expand Down Expand Up @@ -91,6 +92,7 @@ public final class DateTime {
ISO_OFFSET_DATE_TIME = DateTimeFormatter.ISO_OFFSET_DATE_TIME.withLocale(Locale.ENGLISH);
ISO_LOCAL_DATE_TIME = DateTimeFormatter.ISO_LOCAL_DATE_TIME.withLocale(Locale.ENGLISH);
ISO_LOCAL_DATE_TIME_SPECIAL = new DateTimeFormatterBuilder().parseCaseInsensitive().append(ISO_LOCAL_DATE).appendLiteral(' ').append(ISO_LOCAL_TIME).toFormatter().withLocale(Locale.ENGLISH);
ISO_OFFSET_DATE_TIME_SPECIAL = new DateTimeFormatterBuilder().parseCaseInsensitive().append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T').append(ISO_LOCAL_TIME).appendOffset("+HHMM", "0000").toFormatter(Locale.ENGLISH);

RFC_1123_DATE_TIME = DateTimeFormatter.RFC_1123_DATE_TIME.withLocale(Locale.ENGLISH);
RFC_1123_DATE_TIME_TIMEZONE = DateTimeFormatter.ofPattern("E, d LLL yyyy HH:mm:ss zzz", Locale.ENGLISH);
Expand Down Expand Up @@ -229,7 +231,9 @@ private static DateTimeFormatter getDateTimeFormatter(String dateTime, boolean s
}

private static DateTimeFormatter parseIsoDateTime(String dateTime) {
if (dateTime.length() >= 20 && dateTime.length() <= 35 && dateTime.charAt(4) == '-' && dateTime.charAt(10) == 'T')
if (dateTime.length() == 24 && dateTime.charAt(4) == '-' && dateTime.charAt(10) == 'T' && (dateTime.charAt(dateTime.length() - 5) == '-' || dateTime.charAt(dateTime.length() - 5) == '+'))
return ISO_OFFSET_DATE_TIME_SPECIAL;
else if (dateTime.length() >= 20 && dateTime.length() <= 35 && dateTime.charAt(4) == '-' && dateTime.charAt(10) == 'T') // && dateTime.charAt(dateTime.length() - 3) == ':')
return ISO_OFFSET_DATE_TIME;
else if (dateTime.length() == 19 && dateTime.charAt(10) == 'T')
return ISO_LOCAL_DATE_TIME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,12 @@ void testItemExtensionNoNamespace() throws IOException {

@Test
void testUserAgent() throws IOException {
List<Item> items = new RssReader().setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101")
.read("https://lwn.net/headlines/rss")
.collect(Collectors.toList());

for (Item item : items) {
assertThat(item.getChannel().getTitle(), is("LWN.net"));
}
var list = new RssReader()
.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36")
.read("https://www.sciencedaily.com/rss/top.xml")
.sorted()
.collect(Collectors.toList());
assertTrue(list.size() > 10);
}

@Test
Expand Down
18 changes: 10 additions & 8 deletions src/test/java/com/apptasticsoftware/integrationtest/SortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;

class SortTest {

Expand All @@ -36,18 +37,19 @@ void testTimestampSortTest() {
"https://blog.ploeh.dk/rss.xml",
"https://www.politico.com/rss/politicopicks.xml",
"https://www.e1.ru/talk/forum/rss.php?f=86",
"https://failed-to-read-from-this-url.com");
"https://failed-to-read-from-this-url.com",
"https://www.nrdc.org/rss.xml");


List<String> extendedUrlList = new ArrayList<>(urlList);
extendedUrlList.add(null);

var timestamps = new RssReader().read(extendedUrlList)
.sorted()
.map(Item::getPubDateZonedDateTime)
.flatMap(Optional::stream)
.map(t -> t.toInstant().toEpochMilli())
.collect(Collectors.toList());
.sorted()
.map(Item::getPubDateZonedDateTime)
.flatMap(Optional::stream)
.map(t -> t.toInstant().toEpochMilli())
.collect(Collectors.toList());

assertTrue(timestamps.size() > 10);

Expand All @@ -66,7 +68,7 @@ void testSortNewestFirst() throws IOException {
.sorted(ItemComparator.newestItemFirst())
.collect(Collectors.toList());

assertTrue(list.size() > 0);
assertFalse(list.isEmpty());

var previous = list.get(0);
for (Item current : list) {
Expand All @@ -81,7 +83,7 @@ void testSortOldestFirst() throws IOException {
.sorted(ItemComparator.oldestItemFirst())
.collect(Collectors.toList());

assertTrue(list.size() > 0);
assertFalse(list.isEmpty());

var previous = list.get(0);
for (Item current : list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ void dateTimeFormat15() {
assertEquals(1677605828823L, timestamp);
}

@Test
void dateTimeFormat16() {
var timestamp = DateTime.toEpochMilli("2023-08-07T10:06:05-0400");
assertEquals(1691417165000L, timestamp);

timestamp = DateTime.toEpochMilli("2023-08-07T10:06:05+0400");
assertEquals(1691388365000L, timestamp);
}

@Test
void testWrongDayOfWeek() {
assertEquals(1423026000000L, DateTime.toEpochMilli("Monday, 04 Feb 2015 00:00:00 EST"));
Expand Down

0 comments on commit 8153d14

Please sign in to comment.