]> source.dussan.org Git - jgit.git/commitdiff
RawParseUtils test: Use java.time to create PersonIdents 78/1204278/1
authorIvan Frade <ifrade@google.com>
Fri, 15 Nov 2024 21:14:47 +0000 (13:14 -0800)
committerIvan Frade <ifrade@google.com>
Tue, 19 Nov 2024 19:37:29 +0000 (11:37 -0800)
The constructor with long/int for time/tz is deprecated in favor of
Instant/ZoneId.

Update first the expectations in the tests to the new constructors, so
we know we are creating the same PersonIdents than before. We update
the code later, knowing there is no regression in e.g. format or
precision.

Change-Id: I05c759bdd4cf73b8afe79fae3c792f2f1300d1e6

org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java

index 355bbbab16aa9ca87278624b7fb236a2b3d2572e..e517889c83bf08646ff5cdfd9047365b64da3ad4 100644 (file)
 
 package org.eclipse.jgit.util;
 
+import static java.time.Instant.EPOCH;
+import static java.time.ZoneOffset.UTC;
 import static org.junit.Assert.assertEquals;
 
-import java.util.Date;
-import java.util.TimeZone;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
 
 import org.eclipse.jgit.lib.PersonIdent;
 import org.junit.Test;
@@ -22,8 +25,8 @@ public class RawParseUtils_ParsePersonIdentTest {
 
        @Test
        public void testParsePersonIdent_legalCases() {
-               final Date when = new Date(1234567890000L);
-               final TimeZone tz = TimeZone.getTimeZone("GMT-7");
+               Instant when = Instant.ofEpochMilli(1234567890000L);
+               ZoneId tz = ZoneOffset.ofHours(-7);
 
                assertPersonIdent("Me <me@example.com> 1234567890 -0700",
                                new PersonIdent("Me", "me@example.com", when, tz));
@@ -50,8 +53,8 @@ public class RawParseUtils_ParsePersonIdentTest {
 
        @Test
        public void testParsePersonIdent_fuzzyCases() {
-               final Date when = new Date(1234567890000L);
-               final TimeZone tz = TimeZone.getTimeZone("GMT-7");
+               Instant when = Instant.ofEpochMilli(1234567890000L);
+               ZoneId tz = ZoneOffset.ofHours(-7);
 
                assertPersonIdent(
                                "A U Thor <author@example.com>,  C O. Miter <comiter@example.com> 1234567890 -0700",
@@ -64,8 +67,8 @@ public class RawParseUtils_ParsePersonIdentTest {
 
        @Test
        public void testParsePersonIdent_incompleteCases() {
-               final Date when = new Date(1234567890000L);
-               final TimeZone tz = TimeZone.getTimeZone("GMT-7");
+               Instant when = Instant.ofEpochMilli(1234567890000L);
+               ZoneId tz = ZoneOffset.ofHours(-7);
 
                assertPersonIdent("Me <> 1234567890 -0700", new PersonIdent("Me", "",
                                when, tz));
@@ -76,26 +79,26 @@ public class RawParseUtils_ParsePersonIdentTest {
                assertPersonIdent(" <> 1234567890 -0700", new PersonIdent("", "", when,
                                tz));
 
-               assertPersonIdent("<>", new PersonIdent("", "", 0, 0));
+               assertPersonIdent("<>", new PersonIdent("", "", EPOCH, UTC));
 
-               assertPersonIdent(" <>", new PersonIdent("", "", 0, 0));
+               assertPersonIdent(" <>", new PersonIdent("", "", EPOCH, UTC));
 
                assertPersonIdent("<me@example.com>", new PersonIdent("",
-                               "me@example.com", 0, 0));
+                               "me@example.com", EPOCH, UTC));
 
                assertPersonIdent(" <me@example.com>", new PersonIdent("",
-                               "me@example.com", 0, 0));
+                               "me@example.com", EPOCH, UTC));
 
-               assertPersonIdent("Me <>", new PersonIdent("Me", "", 0, 0));
+               assertPersonIdent("Me <>", new PersonIdent("Me", "", EPOCH, UTC));
 
                assertPersonIdent("Me <me@example.com>", new PersonIdent("Me",
-                               "me@example.com", 0, 0));
+                               "me@example.com", EPOCH, UTC));
 
                assertPersonIdent("Me <me@example.com> 1234567890", new PersonIdent(
-                               "Me", "me@example.com", 0, 0));
+                               "Me", "me@example.com", EPOCH, UTC));
 
                assertPersonIdent("Me <me@example.com> 1234567890 ", new PersonIdent(
-                               "Me", "me@example.com", 0, 0));
+                               "Me", "me@example.com", EPOCH, UTC));
        }
 
        @Test