Add TimestampedObserver.
Add simplest toString().
MODIFY
src/main/java/org/apache/commons/io/input/TimestampedObserver.java
src/main/java/org/apache/commons/io/input/TimestampedObserver.java
@@ -86,4 +86,9 @@ public Instant getOpenInstant() {
return openInstant;
}
+ @Override
+ public String toString() {
+ return "TimestampedObserver [openInstant=" + openInstant + ", closeInstant=" + closeInstant + "]";
+ }
+
}

MODIFY
src/test/java/org/apache/commons/io/input/TimestampedObserverTest.java
src/test/java/org/apache/commons/io/input/TimestampedObserverTest.java
package org.apache.commons.io.input;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
@@ -37,6 +38,8 @@ public void test() throws IOException, InterruptedException {
final Instant before = Instant.now();
Thread.sleep(20); // Some OS' clock granularity may be high.
final TimestampedObserver timestampedObserver = new TimestampedObserver();
+ // toString() should not blow up before close().
+ assertNotNull(timestampedObserver.toString());
assertTrue(timestampedObserver.getOpenInstant().isAfter(before));
assertTrue(timestampedObserver.getOpenToNowDuration().toNanos() > 0);
assertNull(timestampedObserver.getCloseInstant());
@@ -51,6 +54,7 @@ public void test() throws IOException, InterruptedException {
assertTrue(timestampedObserver.getOpenToNowDuration().toNanos() > 0);
assertTrue(timestampedObserver.getCloseInstant().isAfter(timestampedObserver.getOpenInstant()));
assertTrue(timestampedObserver.getOpenToCloseDuration().toNanos() > 0);
+ assertNotNull(timestampedObserver.toString());
}
@Test
@@ -62,7 +66,8 @@ public void testExample() throws IOException, InterruptedException {
timestampedObserver)) {
//
}
- System.out.printf("IO duration: %s%n", timestampedObserver.getOpenToCloseDuration());
+ // System.out.printf("IO duration: %s%n", timestampedObserver);
+ // System.out.printf("IO duration: %s%n", timestampedObserver.getOpenToCloseDuration());
}
}

[IO-706] Add TimestampedObserver.

Add simplest toString().