mirror of
https://github.com/google/nomulus
synced 2026-08-21 06:36:15 +00:00
Refactor bsa, dns, batch, and reporting packages to java.time (#3031)
This commit migrates the BSA, DNS, batch, and reporting packages from Joda-Time to java.time. Key changes include: - Updated Sleeper, Clock, and BigqueryUtils to use java.time types natively. - Refactored models like RdeRevision and Tld to eliminate redundant Joda conversions, utilizing new DateTimeUtils static utilities for LocalDate. - Improved test safety by replacing dynamic Instant.now() calls with static parsed constants. - Migrated temporal arithmetic in test suites to use DateTimeUtils convenience methods (plusDays, minusDays). - Updated BigqueryUtils serialization to preserve millisecond precision and formatting for large years, ensuring consistency with previous Joda behavior. - Enhanced code readability by converting long concatenated strings to Java text blocks in LordnLogTest. - Resolved environmental test failures in SyncRegistrarsSheetTest by synchronizing the FakeClock with the JPA extension. - Updated project engineering standards (GEMINI.md) to prefer Truth's .hasValue() for Optional assertions. Verified with a clean full build and all relevant test suites passing.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package google.registry.util;
|
||||
|
||||
import static google.registry.util.DateTimeUtils.formatInstant;
|
||||
import static google.registry.util.DateTimeUtils.parseInstant;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import java.io.IOException;
|
||||
@@ -27,7 +28,7 @@ public class InstantTypeAdapter extends StringBaseTypeAdapter<Instant> {
|
||||
@Override
|
||||
protected Instant fromString(String stringValue) throws IOException {
|
||||
try {
|
||||
return DateTimeUtils.parseInstant(stringValue);
|
||||
return parseInstant(stringValue);
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
||||
@@ -19,16 +19,20 @@ import static google.registry.util.DateTimeUtils.END_INSTANT;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static google.registry.util.DateTimeUtils.START_INSTANT;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static google.registry.util.DateTimeUtils.earliestDateTimeOf;
|
||||
import static google.registry.util.DateTimeUtils.earliestOf;
|
||||
import static google.registry.util.DateTimeUtils.isAtOrAfter;
|
||||
import static google.registry.util.DateTimeUtils.isBeforeOrAt;
|
||||
import static google.registry.util.DateTimeUtils.latestDateTimeOf;
|
||||
import static google.registry.util.DateTimeUtils.latestOf;
|
||||
import static google.registry.util.DateTimeUtils.minusMonths;
|
||||
import static google.registry.util.DateTimeUtils.minusYears;
|
||||
import static google.registry.util.DateTimeUtils.parseInstant;
|
||||
import static google.registry.util.DateTimeUtils.plusMonths;
|
||||
import static google.registry.util.DateTimeUtils.plusYears;
|
||||
import static google.registry.util.DateTimeUtils.toDateTime;
|
||||
import static google.registry.util.DateTimeUtils.toInstant;
|
||||
import static google.registry.util.DateTimeUtils.toJodaInstant;
|
||||
import static google.registry.util.DateTimeUtils.toLocalDate;
|
||||
import static google.registry.util.DateTimeUtils.toSqlDate;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@@ -49,7 +53,7 @@ class DateTimeUtilsTest {
|
||||
@Test
|
||||
void testSuccess_earliestOf() {
|
||||
assertThat(earliestOf(START_OF_TIME, END_OF_TIME)).isEqualTo(START_OF_TIME);
|
||||
assertThat(DateTimeUtils.earliestDateTimeOf(sampleDates)).isEqualTo(START_OF_TIME);
|
||||
assertThat(earliestDateTimeOf(sampleDates)).isEqualTo(START_OF_TIME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,7 +65,7 @@ class DateTimeUtilsTest {
|
||||
@Test
|
||||
void testSuccess_latestOf() {
|
||||
assertThat(latestOf(START_OF_TIME, END_OF_TIME)).isEqualTo(END_OF_TIME);
|
||||
assertThat(DateTimeUtils.latestDateTimeOf(sampleDates)).isEqualTo(END_OF_TIME);
|
||||
assertThat(latestDateTimeOf(sampleDates)).isEqualTo(END_OF_TIME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,14 +140,12 @@ class DateTimeUtilsTest {
|
||||
|
||||
@Test
|
||||
void testFailure_earliestOfEmpty() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> DateTimeUtils.earliestDateTimeOf(ImmutableList.of()));
|
||||
assertThrows(IllegalArgumentException.class, () -> earliestDateTimeOf(ImmutableList.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFailure_latestOfEmpty() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> DateTimeUtils.latestDateTimeOf(ImmutableList.of()));
|
||||
assertThrows(IllegalArgumentException.class, () -> latestDateTimeOf(ImmutableList.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,11 +182,11 @@ class DateTimeUtilsTest {
|
||||
.isEqualTo(DateTime.parse("2024-03-27T10:15:30.105Z"));
|
||||
assertThat(toInstant(DateTime.parse("2024-03-27T10:15:30.105Z")))
|
||||
.isEqualTo(Instant.parse("2024-03-27T10:15:30.105Z"));
|
||||
assertThat(DateTimeUtils.toJodaInstant(Instant.parse("2024-03-27T10:15:30.105Z")))
|
||||
assertThat(toJodaInstant(Instant.parse("2024-03-27T10:15:30.105Z")))
|
||||
.isEqualTo(org.joda.time.Instant.parse("2024-03-27T10:15:30.105Z"));
|
||||
assertThat(DateTimeUtils.parseInstant("2024-03-27T10:15:30.105Z"))
|
||||
assertThat(parseInstant("2024-03-27T10:15:30.105Z"))
|
||||
.isEqualTo(Instant.parse("2024-03-27T10:15:30.105Z"));
|
||||
assertThat(DateTimeUtils.parseInstant("2024-03-27T10:15:30Z"))
|
||||
assertThat(parseInstant("2024-03-27T10:15:30Z"))
|
||||
.isEqualTo(Instant.parse("2024-03-27T10:15:30Z"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import static com.google.common.io.BaseEncoding.base64;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.google.common.testing.EqualsTester;
|
||||
@@ -27,7 +28,6 @@ import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -203,7 +203,7 @@ class PosixTarHeaderTest {
|
||||
new PosixTarHeader.Builder()
|
||||
.setName("(◕‿◕).txt")
|
||||
.setSize(31337)
|
||||
.setMtime(DateTime.now(DateTimeZone.UTC))
|
||||
.setMtime(DateTime.now(UTC))
|
||||
.build();
|
||||
byte[] bytes = header.getBytes();
|
||||
bytes[150] = '0';
|
||||
@@ -239,7 +239,7 @@ class PosixTarHeaderTest {
|
||||
new PosixTarHeader.Builder()
|
||||
.setName("(•︵•).txt") // Awwwww! It looks so sad...
|
||||
.setSize(123)
|
||||
.setMtime(DateTime.now(DateTimeZone.UTC))
|
||||
.setMtime(DateTime.now(UTC))
|
||||
.build())
|
||||
.testEquals();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user