migrate from java.util.Date to java.time

This commit is contained in:
Athou
2024-01-08 20:42:45 +01:00
parent b1a4debb95
commit 69c9988404
35 changed files with 203 additions and 206 deletions

View File

@@ -1,6 +1,6 @@
package com.commafeed.backend.feed;
import java.util.Date;
import java.time.Instant;
import java.util.Set;
import org.apache.commons.codec.digest.DigestUtils;
@@ -49,7 +49,7 @@ class FeedFetcherTest {
.thenReturn(new HttpResult(content, "content-type", "last-modified-2", "etag-2", 20, null));
NotModifiedException e = Assertions.assertThrows(NotModifiedException.class,
() -> fetcher.fetch(url, false, lastModified, etag, new Date(), lastContentHash));
() -> fetcher.fetch(url, false, lastModified, etag, Instant.now(), lastContentHash));
Assertions.assertEquals("last-modified-2", e.getNewLastModifiedHeader());
Assertions.assertEquals("etag-2", e.getNewEtagHeader());

View File

@@ -3,8 +3,8 @@ package com.commafeed.e2e;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
import org.junit.jupiter.api.AfterAll;
@@ -115,7 +115,7 @@ public class PlaywrightTestBase {
private String getFileName(ExtensionContext context) {
return String.format("%s.%s-%s", context.getRequiredTestClass().getSimpleName(), context.getRequiredTestMethod().getName(),
new SimpleDateFormat("yyyy-MM-dd--HH-mm-ss").format(new Date()));
DateTimeFormatter.ofPattern("yyyy-MM-dd--HH-mm-ss").format(Instant.now()));
}
private void saveScreenshot(PlaywrightTestBase testInstance, String fileName) {

View File

@@ -3,9 +3,9 @@ package com.commafeed.integration.rest;
import java.io.IOException;
import java.io.InputStream;
import java.time.Duration;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.Objects;
import org.apache.commons.io.IOUtils;
@@ -99,13 +99,13 @@ class FeedIT extends BaseIT {
@Test
void markOlderThan() {
long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
markFeedEntries(subscriptionId, new GregorianCalendar(2023, Calendar.DECEMBER, 28).getTime(), null);
markFeedEntries(subscriptionId, LocalDate.of(2023, 12, 28).atStartOfDay().toInstant(ZoneOffset.UTC), null);
Assertions.assertEquals(1, getFeedEntries(subscriptionId).getEntries().stream().filter(Entry::isRead).count());
}
@Test
void markInsertedBeforeBeforeSubscription() {
Date insertedBefore = new Date();
Instant insertedBefore = Instant.now();
long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
markFeedEntries(subscriptionId, null, insertedBefore);
@@ -116,17 +116,17 @@ class FeedIT extends BaseIT {
void markInsertedBeforeAfterSubscription() {
long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
Date insertedBefore = new Date();
Instant insertedBefore = Instant.now();
markFeedEntries(subscriptionId, null, insertedBefore);
Assertions.assertTrue(getFeedEntries(subscriptionId).getEntries().stream().allMatch(Entry::isRead));
}
private void markFeedEntries(long subscriptionId, Date olderThan, Date insertedBefore) {
private void markFeedEntries(long subscriptionId, Instant olderThan, Instant insertedBefore) {
MarkRequest request = new MarkRequest();
request.setId(String.valueOf(subscriptionId));
request.setOlderThan(olderThan == null ? null : olderThan.getTime());
request.setInsertedBefore(insertedBefore == null ? null : insertedBefore.getTime());
request.setOlderThan(olderThan == null ? null : olderThan.toEpochMilli());
request.setInsertedBefore(insertedBefore == null ? null : insertedBefore.toEpochMilli());
getClient().target(getApiBaseUrl() + "feed/mark").request().post(Entity.json(request), Void.TYPE);
}
}
@@ -137,26 +137,26 @@ class FeedIT extends BaseIT {
void refresh() {
Long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
Date now = new Date();
Instant now = Instant.now();
IDRequest request = new IDRequest();
request.setId(subscriptionId);
getClient().target(getApiBaseUrl() + "feed/refresh").request().post(Entity.json(request), Void.TYPE);
Awaitility.await()
.atMost(Duration.ofSeconds(15))
.until(() -> getSubscription(subscriptionId), f -> f.getLastRefresh().after(now));
.until(() -> getSubscription(subscriptionId), f -> f.getLastRefresh().isAfter(now));
}
@Test
void refreshAll() {
Long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
Date now = new Date();
Instant now = Instant.now();
getClient().target(getApiBaseUrl() + "feed/refreshAll").request().get(Void.TYPE);
Awaitility.await()
.atMost(Duration.ofSeconds(15))
.until(() -> getSubscription(subscriptionId), f -> f.getLastRefresh().after(now));
.until(() -> getSubscription(subscriptionId), f -> f.getLastRefresh().isAfter(now));
}
}