From df9cf94b3e4811b579d404e0e58d005cc18df998 Mon Sep 17 00:00:00 2001
From: Ivan Frade <ifrade@google.com>
Date: Fri, 15 Nov 2024 13:14:47 -0800
Subject: [PATCH] RawParseUtils test: Use java.time to create PersonIdents

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
---
 .../RawParseUtils_ParsePersonIdentTest.java   | 35 ++++++++++---------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java
index 355bbbab1..e517889c8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_ParsePersonIdentTest.java
@@ -10,10 +10,13 @@
 
 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 void testParsePersonIdent_legalCases() {
 
 	@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 void testParsePersonIdent_fuzzyCases() {
 
 	@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 void testParsePersonIdent_incompleteCases() {
 		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
-- 
GitLab