From 79cdf199904f46c24f1f02de6a5fa7ffbf1c1ad1 Mon Sep 17 00:00:00 2001 From: dev-mlb <19797865+dev-mlb@users.noreply.github.com> Date: Thu, 30 May 2024 05:43:19 -0400 Subject: [PATCH] errorprone::java util date (#773) --- pom.xml | 4 +++ .../java/emissary/command/MonitorCommand.java | 4 +-- .../java/emissary/core/BaseDataObject.java | 12 ++++---- .../java/emissary/core/IBaseDataObject.java | 8 +++--- .../emissary/core/IBaseDataObjectHelper.java | 3 +- .../emissary/directory/HeartbeatManager.java | 3 +- .../java/emissary/output/DropOffPlace.java | 9 ++++-- .../java/emissary/output/DropOffUtil.java | 4 +-- .../output/filter/JsonOutputFilter.java | 6 ++-- .../util/DateTimeFormatParserLegacy.java | 1 + src/main/java/emissary/util/PayloadUtil.java | 4 +-- src/main/java/emissary/util/TimeUtil.java | 5 ++-- .../java/emissary/util/WatcherThread.java | 6 ++-- .../emissary/core/BaseDataObjectTest.java | 4 +-- .../core/IBaseDataObjectDiffHelperTest.java | 4 +-- .../core/IBaseDataObjectHelperTest.java | 6 ++-- .../pickup/BreakableFilePickUpClient.java | 4 +-- .../java/emissary/util/PayloadUtilTest.java | 28 ++++++++++++------- src/test/java/emissary/util/TimeUtilTest.java | 6 ++-- 19 files changed, 68 insertions(+), 53 deletions(-) diff --git a/pom.xml b/pom.xml index 0f723ddd87..55398d81c4 100644 --- a/pom.xml +++ b/pom.xml @@ -294,6 +294,10 @@ com.fasterxml.jackson.core jackson-databind + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + com.github.spullara.mustache.java compiler diff --git a/src/main/java/emissary/command/MonitorCommand.java b/src/main/java/emissary/command/MonitorCommand.java index 27aaaf2953..922b09cd9d 100644 --- a/src/main/java/emissary/command/MonitorCommand.java +++ b/src/main/java/emissary/command/MonitorCommand.java @@ -9,7 +9,7 @@ import picocli.CommandLine.Option; import java.io.IOException; -import java.util.Date; +import java.time.Instant; import java.util.concurrent.TimeUnit; public abstract class MonitorCommand extends HttpCommand { @@ -51,7 +51,7 @@ public void run(CommandLine c) { setup(); try { do { - LOG.info(new Date().toString()); + LOG.info(Instant.now().toString()); collectEndpointData(); if (getMonitor()) { TimeUnit.SECONDS.sleep(getSleepInterval()); diff --git a/src/main/java/emissary/core/BaseDataObject.java b/src/main/java/emissary/core/BaseDataObject.java index 6b879e9eaa..51dbba6604 100755 --- a/src/main/java/emissary/core/BaseDataObject.java +++ b/src/main/java/emissary/core/BaseDataObject.java @@ -23,9 +23,9 @@ import java.nio.channels.Channels; import java.nio.channels.SeekableByteChannel; import java.rmi.Remote; +import java.time.Instant; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -160,7 +160,7 @@ public class BaseDataObject implements Serializable, Cloneable, Remote, IBaseDat /** * The timestamp for when the BaseDataObject was created. Used in data provenance tracking. */ - protected Date creationTimestamp; + protected Instant creationTimestamp; /** * The extracted records, if any @@ -252,7 +252,7 @@ public void checkForUnsafeDataChanges() { */ public BaseDataObject() { this.theData = null; - setCreationTimestamp(new Date(System.currentTimeMillis())); + setCreationTimestamp(Instant.now()); } /** @@ -265,7 +265,7 @@ public BaseDataObject() { public BaseDataObject(final byte[] newData, final String name) { setData(newData); setFilename(name); - setCreationTimestamp(new Date(System.currentTimeMillis())); + setCreationTimestamp(Instant.now()); } /** @@ -1373,7 +1373,7 @@ public IBaseDataObject clone() throws CloneNotSupportedException { } @Override - public Date getCreationTimestamp() { + public Instant getCreationTimestamp() { return this.creationTimestamp; } @@ -1384,7 +1384,7 @@ public Date getCreationTimestamp() { * @param creationTimestamp when this item was created */ @Override - public void setCreationTimestamp(final Date creationTimestamp) { + public void setCreationTimestamp(final Instant creationTimestamp) { if (creationTimestamp == null) { throw new IllegalArgumentException("Timestamp must not be null"); } diff --git a/src/main/java/emissary/core/IBaseDataObject.java b/src/main/java/emissary/core/IBaseDataObject.java index 92dfbabaae..d37989c2c4 100755 --- a/src/main/java/emissary/core/IBaseDataObject.java +++ b/src/main/java/emissary/core/IBaseDataObject.java @@ -6,8 +6,8 @@ import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; +import java.time.Instant; import java.util.Collection; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; @@ -814,17 +814,17 @@ enum MergePolicy { /** * Get the timestamp for when the object was created. This attribute will be used for data provenance. - * + * * @return date - the timestamp the object was created */ - Date getCreationTimestamp(); + Instant getCreationTimestamp(); /** * Set the timestamp for when the object was created * * @param creationTimestamp - the date the object was created */ - void setCreationTimestamp(Date creationTimestamp); + void setCreationTimestamp(Instant creationTimestamp); /** * Get the List of extracted records diff --git a/src/main/java/emissary/core/IBaseDataObjectHelper.java b/src/main/java/emissary/core/IBaseDataObjectHelper.java index d96394a519..6aa1486918 100644 --- a/src/main/java/emissary/core/IBaseDataObjectHelper.java +++ b/src/main/java/emissary/core/IBaseDataObjectHelper.java @@ -12,7 +12,6 @@ import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Optional; @@ -68,7 +67,7 @@ public static IBaseDataObject clone(final IBaseDataObject iBaseDataObject, final bdo.addAlternateView(entry.getKey(), entry.getValue()); } bdo.setPriority(iBaseDataObject.getPriority()); - bdo.setCreationTimestamp((Date) iBaseDataObject.getCreationTimestamp().clone()); + bdo.setCreationTimestamp(iBaseDataObject.getCreationTimestamp()); if (iBaseDataObject.getExtractedRecords() != null) { bdo.setExtractedRecords(iBaseDataObject.getExtractedRecords()); } diff --git a/src/main/java/emissary/directory/HeartbeatManager.java b/src/main/java/emissary/directory/HeartbeatManager.java index 9061e2b433..6093a0f460 100755 --- a/src/main/java/emissary/directory/HeartbeatManager.java +++ b/src/main/java/emissary/directory/HeartbeatManager.java @@ -15,7 +15,6 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Timer; @@ -115,7 +114,7 @@ public HeartbeatManager(final String directoryKey, @Nullable final List } // "smooth" execution every 30 seconds starting in 2 minutes - this.timer.schedule(new HeartbeatTask(), new Date(System.currentTimeMillis() + (this.initialDelaySeconds * 1000L)), + this.timer.schedule(new HeartbeatTask(), System.currentTimeMillis() + (this.initialDelaySeconds * 1000L), (this.intervalSeconds * 1000L)); } diff --git a/src/main/java/emissary/output/DropOffPlace.java b/src/main/java/emissary/output/DropOffPlace.java index 677a031d44..e29f6125fe 100755 --- a/src/main/java/emissary/output/DropOffPlace.java +++ b/src/main/java/emissary/output/DropOffPlace.java @@ -14,9 +14,10 @@ import emissary.util.ShortNameComparator; import java.io.IOException; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -229,11 +230,13 @@ public List agentProcessHeavyDuty(final List p if (outputCompletionPayloadSize && tld.hasContent()) { logger.info( "Finished DropOff for object {}, with external id: {}, with total processing time: {}ms, with filetype: {}, payload size: {} bytes", - tld.getInternalId(), this.dropOffUtil.getBestId(tld, tld), (new Date().getTime() - tld.getCreationTimestamp().getTime()), + tld.getInternalId(), this.dropOffUtil.getBestId(tld, tld), + Duration.between(Instant.now(), tld.getCreationTimestamp()).toMillis(), tld.getFileType(), tld.getChannelSize()); } else { logger.info("Finished DropOff for object {}, with external id: {}, with total processing time: {}ms, with filetype: {}", - tld.getInternalId(), this.dropOffUtil.getBestId(tld, tld), (new Date().getTime() - tld.getCreationTimestamp().getTime()), + tld.getInternalId(), this.dropOffUtil.getBestId(tld, tld), + Duration.between(Instant.now(), tld.getCreationTimestamp()).toMillis(), tld.getFileType()); } diff --git a/src/main/java/emissary/output/DropOffUtil.java b/src/main/java/emissary/output/DropOffUtil.java index ecf0795570..b779cb9c7f 100755 --- a/src/main/java/emissary/output/DropOffUtil.java +++ b/src/main/java/emissary/output/DropOffUtil.java @@ -163,10 +163,10 @@ protected void configure(@Nullable final Configurator configG) { */ public String generateBuildFileName() { if (this.uuidInOutputFilenames) { - return (prefix + getDateOrdinalWithTime(new Date()) + UUID.randomUUID()); + return (prefix + getDateOrdinalWithTime(Instant.now()) + UUID.randomUUID()); } else { // Using some constants plus yyyyJJJhhmmss plus random digit, letter, digit - return (prefix + getDateOrdinalWithTime(new Date()) + prng.nextInt(10) + ALPHABET[prng.nextInt(ALPHABET.length)] + prng.nextInt(10)); + return (prefix + getDateOrdinalWithTime(Instant.now()) + prng.nextInt(10) + ALPHABET[prng.nextInt(ALPHABET.length)] + prng.nextInt(10)); } } diff --git a/src/main/java/emissary/output/filter/JsonOutputFilter.java b/src/main/java/emissary/output/filter/JsonOutputFilter.java index 042b582d33..080fe96b66 100644 --- a/src/main/java/emissary/output/filter/JsonOutputFilter.java +++ b/src/main/java/emissary/output/filter/JsonOutputFilter.java @@ -25,11 +25,12 @@ import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; import com.fasterxml.jackson.databind.ser.std.MapProperty; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.apache.commons.collections4.CollectionUtils; import java.io.IOException; +import java.time.Instant; import java.util.Collection; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; @@ -83,6 +84,7 @@ protected void initFilenameGenerator() { protected void initJsonMapper() { jsonMapper = new ObjectMapper(); jsonMapper.registerModule(new IbdoModule()); + jsonMapper.registerModule(new JavaTimeModule()); jsonMapper.addMixIn(IBaseDataObject.class, emitPayload ? IbdoPayloadMixin.class : IbdoParameterMixin.class); // the id in addFilter must match the annotation for JsonFilter jsonMapper.setFilterProvider(new SimpleFilterProvider().addFilter("param_filter", new IbdoParameterFilter())); @@ -250,7 +252,7 @@ abstract static class IbdoMixin { abstract UUID getInternalId(); @JsonProperty("creationTimestamp") - abstract Date getCreationTimestamp(); + abstract Instant getCreationTimestamp(); @JsonProperty("shortName") abstract String shortName(); diff --git a/src/main/java/emissary/util/DateTimeFormatParserLegacy.java b/src/main/java/emissary/util/DateTimeFormatParserLegacy.java index 5949a3c053..de6de1565b 100644 --- a/src/main/java/emissary/util/DateTimeFormatParserLegacy.java +++ b/src/main/java/emissary/util/DateTimeFormatParserLegacy.java @@ -13,6 +13,7 @@ import java.util.List; @Deprecated +@SuppressWarnings("JavaUtilDate") public class DateTimeFormatParserLegacy { protected static final Logger logger = LoggerFactory.getLogger(DateTimeFormatParserLegacy.class); diff --git a/src/main/java/emissary/util/PayloadUtil.java b/src/main/java/emissary/util/PayloadUtil.java index fdfe6a57c9..615af36e36 100755 --- a/src/main/java/emissary/util/PayloadUtil.java +++ b/src/main/java/emissary/util/PayloadUtil.java @@ -13,8 +13,8 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.time.Instant; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -116,7 +116,7 @@ public static String getPayloadDisplayString(final IBaseDataObject payload) { final String fileName = payload.getFilename(); final String fileType = payload.getFileType(); final List currentForms = payload.getAllCurrentForms(); - final Date creationTimestamp = payload.getCreationTimestamp(); + final Instant creationTimestamp = payload.getCreationTimestamp(); sb.append("\n").append("filename: ").append(fileName).append("\n").append(" creationTimestamp: ").append(creationTimestamp).append("\n") .append(" currentForms: ").append(currentForms).append("\n").append(" filetype: ").append(fileType).append("\n") diff --git a/src/main/java/emissary/util/TimeUtil.java b/src/main/java/emissary/util/TimeUtil.java index b2d835e589..efe86c223f 100755 --- a/src/main/java/emissary/util/TimeUtil.java +++ b/src/main/java/emissary/util/TimeUtil.java @@ -14,7 +14,6 @@ import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAccessor; import java.time.zone.ZoneRulesException; -import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.Nullable; @@ -242,8 +241,8 @@ public static String getISO8601DateFormatString() { } - public static String getDateOrdinalWithTime(final Date d) { - return DATE_ORDINAL_WITH_TIME.format(d.toInstant().atZone(ZoneId.systemDefault())); + public static String getDateOrdinalWithTime(final Instant d) { + return DATE_ORDINAL_WITH_TIME.format(d.atZone(ZoneId.systemDefault())); } /** This class is not meant to be instantiated. */ diff --git a/src/main/java/emissary/util/WatcherThread.java b/src/main/java/emissary/util/WatcherThread.java index 4db06bc71f..d0621fa140 100755 --- a/src/main/java/emissary/util/WatcherThread.java +++ b/src/main/java/emissary/util/WatcherThread.java @@ -5,7 +5,7 @@ import java.io.IOException; import java.io.PrintStream; -import java.util.Date; +import java.time.Instant; import javax.annotation.Nullable; public class WatcherThread extends Thread { @@ -76,7 +76,7 @@ public static void main(String[] args) throws IOException { wt.setDelay(Integer.parseInt(args[0])); - System.out.println(name + " begins at " + new Date()); + System.out.println(name + " begins at " + Instant.now()); Process proc = Runtime.getRuntime().exec(args[1]); @@ -101,7 +101,7 @@ public static void main(String[] args) throws IOException { Thread.currentThread().interrupt(); } - System.out.println(name + " ends at " + new Date()); + System.out.println(name + " ends at " + Instant.now()); } diff --git a/src/test/java/emissary/core/BaseDataObjectTest.java b/src/test/java/emissary/core/BaseDataObjectTest.java index c23d5b1bef..0f5dc9ed75 100755 --- a/src/test/java/emissary/core/BaseDataObjectTest.java +++ b/src/test/java/emissary/core/BaseDataObjectTest.java @@ -28,11 +28,11 @@ import java.nio.ByteBuffer; import java.nio.channels.SeekableByteChannel; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -1123,7 +1123,7 @@ void testDefaultConstructor_setDateTime() { @Test void testDefaultConstructor_getSetDateTime() { // setup - final Date date = new Date(0); + final Instant date = Instant.now(); // test this.b.setCreationTimestamp(date); diff --git a/src/test/java/emissary/core/IBaseDataObjectDiffHelperTest.java b/src/test/java/emissary/core/IBaseDataObjectDiffHelperTest.java index f854ae3c30..7077201919 100644 --- a/src/test/java/emissary/core/IBaseDataObjectDiffHelperTest.java +++ b/src/test/java/emissary/core/IBaseDataObjectDiffHelperTest.java @@ -13,10 +13,10 @@ import java.nio.ByteBuffer; import java.nio.channels.SeekableByteChannel; import java.nio.charset.StandardCharsets; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Set; @@ -214,7 +214,7 @@ void testDiffPriority() { @Test void testDiffCreationTimestamp() { - ibdo1.setCreationTimestamp(new Date(1234567890)); + ibdo1.setCreationTimestamp(Instant.ofEpochSecond(1234567890)); final DiffCheckConfiguration options = DiffCheckConfiguration.configure().enableTimestamp().build(); verifyDiff(1, options); } diff --git a/src/test/java/emissary/core/IBaseDataObjectHelperTest.java b/src/test/java/emissary/core/IBaseDataObjectHelperTest.java index bf0373d437..aec9087289 100644 --- a/src/test/java/emissary/core/IBaseDataObjectHelperTest.java +++ b/src/test/java/emissary/core/IBaseDataObjectHelperTest.java @@ -15,9 +15,9 @@ import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -165,8 +165,8 @@ void testClonePriority() { @Test void testCloneCreationTimestamp() { - ibdo1.setCreationTimestamp(new Date(1234567890)); - verifyClone("getCreationTimestamp", ibdo1, IS_NOT_SAME, IS_EQUALS, EQUAL_WITHOUT_FULL_CLONE); + ibdo1.setCreationTimestamp(Instant.ofEpochSecond(1234567890)); + verifyClone("getCreationTimestamp", ibdo1, DONT_CHECK, IS_EQUALS, EQUAL_WITHOUT_FULL_CLONE); } @Test diff --git a/src/test/java/emissary/pickup/BreakableFilePickUpClient.java b/src/test/java/emissary/pickup/BreakableFilePickUpClient.java index 710074a17d..843d0be319 100755 --- a/src/test/java/emissary/pickup/BreakableFilePickUpClient.java +++ b/src/test/java/emissary/pickup/BreakableFilePickUpClient.java @@ -5,7 +5,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.util.Date; +import java.time.Instant; import java.util.Timer; import java.util.TimerTask; @@ -31,7 +31,7 @@ public void setBrokenDuringProcessing(boolean value) { actBrokenDuringProcessing = value; if (value == true) { Timer t = new Timer("BreakableFilePickupClientMonitor", true); - t.schedule(new TimeToActBrokenTask(), new Date(System.currentTimeMillis()), 10L); + t.schedule(new TimeToActBrokenTask(), Instant.now().toEpochMilli(), 10L); } } diff --git a/src/test/java/emissary/util/PayloadUtilTest.java b/src/test/java/emissary/util/PayloadUtilTest.java index 631e34c397..237a7dfe26 100644 --- a/src/test/java/emissary/util/PayloadUtilTest.java +++ b/src/test/java/emissary/util/PayloadUtilTest.java @@ -10,8 +10,8 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import java.time.Instant; import java.util.ArrayList; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -44,14 +44,17 @@ public static void teardown() { @Test void testOneLineString() { + + Instant now = Instant.now(); + // setup final String fn = "fname" + Family.SEP + "4"; final IBaseDataObject d = DataObjectFactory.getInstance("abc".getBytes(), fn, Form.UNKNOWN); d.appendTransformHistory("FOO.UNKNOWN.FOOPLACE.http://example.com:1234/FooPlace"); d.appendTransformHistory("BAR.UNKNOWN.BARPLACE.http://example.com:1234/BarPlace"); d.appendTransformHistory("BAR.BURP.BURPPLACE.http://example.com:1234/BurpPlace"); - d.setCreationTimestamp(new Date(0)); - final String expected = "att-4 FOO,BAR>>[UNKNOWN]//UNKNOWN//" + new Date(0); + d.setCreationTimestamp(now); + final String expected = "att-4 FOO,BAR>>[UNKNOWN]//UNKNOWN//" + now; // test final String answer = PayloadUtil.getPayloadDisplayString(d, true); @@ -63,12 +66,14 @@ void testOneLineString() { @Test void testOneLineStringOnTLD() { + Instant now = Instant.now(); + // setup final String fn = "fname"; final IBaseDataObject d = DataObjectFactory.getInstance("abc".getBytes(), fn, Form.UNKNOWN); - d.setCreationTimestamp(new Date(0)); + d.setCreationTimestamp(now); d.appendTransformHistory("BOGUSKEYELEMENT"); - final String expected = ">>[UNKNOWN]//UNKNOWN//" + new Date(0); + final String expected = ">>[UNKNOWN]//UNKNOWN//" + now; // test final String answer = PayloadUtil.getPayloadDisplayString(d, true); @@ -80,12 +85,15 @@ void testOneLineStringOnTLD() { @Test void testMultiLineString() { + + Instant now = Instant.now(); + // setup final String fn = "fname" + Family.SEP + "4"; final IBaseDataObject d = DataObjectFactory.getInstance("abc".getBytes(), fn, Form.UNKNOWN); d.appendTransformHistory("FOO.UNKNOWN.FOOPLACE.http://example.com:1234/FooPlace"); d.appendTransformHistory("BAR.UNKNOWN.BARPLACE.http://example.com:1234/BarPlace"); - d.setCreationTimestamp(new Date(0)); + d.setCreationTimestamp(now); // test final String answer = PayloadUtil.getPayloadDisplayString(d, false); @@ -93,7 +101,7 @@ void testMultiLineString() { // verify assertTrue(answer.contains("\n"), "Must be multi-line string"); assertTrue(answer.contains("filename: fname-att-4"), "Answer did not contain the correct filename"); - assertTrue(answer.contains("creationTimestamp: " + new Date(0)), "Answer did not contain the creationTimestamp"); + assertTrue(answer.contains("creationTimestamp: " + now), "Answer did not contain the creationTimestamp"); assertTrue(answer.contains("currentForms: [UNKNOWN]"), "Answer did not contain the currentForms"); assertTrue(answer.contains("filetype: UNKNOWN"), "Answer did not contain the correct filetype"); assertTrue(answer.contains("transform history (2)"), "Answer did not contain the transform history number"); @@ -111,7 +119,7 @@ void testReducedHistory() { d.appendTransformHistory("FOO.UNKNOWN.FOOPLACE.http://example.com:1234/FooPlace"); d.appendTransformHistory("BAR.UNKNOWN.BARPLACE.http://example.com:1234/BarPlace"); d.appendTransformHistory("TEST.DROPOFFPLACE.http://example.com:1234/DropOffPlace"); - d.setCreationTimestamp(new Date(0)); + d.setCreationTimestamp(Instant.now()); // test PayloadUtil.historyPreference.put("UNKNOWN", "REDUCED_HISTORY"); @@ -137,7 +145,7 @@ void testNoUrlHistory() { final IBaseDataObject d = DataObjectFactory.getInstance("abc".getBytes(), fn, Form.UNKNOWN); d.appendTransformHistory("FOO.UNKNOWN.FOOPLACE.http://example.com:1234/FooPlace"); d.appendTransformHistory("BAR.UNKNOWN.BARPLACE.http://example.com:1234/BarPlace"); - d.setCreationTimestamp(new Date(0)); + d.setCreationTimestamp(Instant.now()); // test PayloadUtil.historyPreference.put("UNKNOWN", "NO_URL"); @@ -162,7 +170,7 @@ void testHistoryDoesNotReduce() { final IBaseDataObject d = DataObjectFactory.getInstance("abc".getBytes(), fn, Form.UNKNOWN); d.appendTransformHistory("FOO.UNKNOWN.FOOPLACE.http://example.com:1234/FooPlace"); d.appendTransformHistory("BAR.UNKNOWN.BARPLACE.http://example.com:1234/BarPlace"); - d.setCreationTimestamp(new Date(0)); + d.setCreationTimestamp(Instant.now()); // test PayloadUtil.historyPreference.put("REDUCED", "REDUCED_HISTORY"); diff --git a/src/test/java/emissary/util/TimeUtilTest.java b/src/test/java/emissary/util/TimeUtilTest.java index 9d675accd3..9916ff5eb4 100644 --- a/src/test/java/emissary/util/TimeUtilTest.java +++ b/src/test/java/emissary/util/TimeUtilTest.java @@ -4,13 +4,13 @@ import org.junit.jupiter.api.Test; +import java.time.Instant; import java.time.LocalDateTime; import java.time.Month; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.zone.ZoneRulesException; -import java.util.Date; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; @@ -22,7 +22,7 @@ class TimeUtilTest extends UnitTest { private static final ZoneId GMT = ZoneId.of("GMT"); private static final ZoneId PARIS = ZoneId.of("Europe/Paris"); private static final LocalDateTime testLocalDate = LocalDateTime.of(2016, Month.DECEMBER, 25, 15, 30, 25); - private static final Date testUtilDate = Date.from(testLocalDate.toInstant(ZoneOffset.UTC)); + private static final Instant testUtilDate = testLocalDate.toInstant(ZoneOffset.UTC); private static final ZonedDateTime testZoneDate = ZonedDateTime.of(testLocalDate, GMT); @Test @@ -56,7 +56,7 @@ void testGetDateExceptionBadZone() { @Test void testGetDateAsISO8601Long() { - assertEquals("2016-12-25 15:30:25", TimeUtil.getDateAsISO8601(testUtilDate.getTime()), "GetDateAsISO8601Long"); + assertEquals("2016-12-25 15:30:25", TimeUtil.getDateAsISO8601(testUtilDate), "GetDateAsISO8601Long"); } @Deprecated