mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(core): centralize millisecond epoch seconds (#7150)
This commit is contained in:
1 parent
0f94440442
commit
08d45041d5
41 files changed
+217
-136
No files matched your search
@@ -0,0 +1,28 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class EpochSecondsTest {
|
||||
|
||||
@Test
|
||||
void keepsMillisecondFractionAndDropsSubmillisecondPrecision() {
|
||||
assertEquals(1_790_312_384.592, EpochSeconds.fromInstant(
|
||||
Instant.ofEpochSecond(1_790_312_384L, 592_999_999L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void floorsNegativeSubmillisecondInstantToPreviousMillisecond() {
|
||||
assertEquals(-0.001, EpochSeconds.fromInstant(Instant.ofEpochSecond(-1, 999_999_999)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void retainsNullAndOverflowFailures() {
|
||||
assertThrows(NullPointerException.class, () -> EpochSeconds.fromInstant(null));
|
||||
assertThrows(ArithmeticException.class, () -> EpochSeconds.fromInstant(Instant.MAX));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user