Skip to content
Snippets Groups Projects
Commit df9cf94b authored by Ivan Frade's avatar Ivan Frade
Browse files

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
parent 336ab76c
No related branches found
No related tags found
No related merge requests found
...@@ -10,10 +10,13 @@ ...@@ -10,10 +10,13 @@
package org.eclipse.jgit.util; package org.eclipse.jgit.util;
import static java.time.Instant.EPOCH;
import static java.time.ZoneOffset.UTC;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.util.Date; import java.time.Instant;
import java.util.TimeZone; import java.time.ZoneId;
import java.time.ZoneOffset;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
import org.junit.Test; import org.junit.Test;
...@@ -22,8 +25,8 @@ public class RawParseUtils_ParsePersonIdentTest { ...@@ -22,8 +25,8 @@ public class RawParseUtils_ParsePersonIdentTest {
@Test @Test
public void testParsePersonIdent_legalCases() { public void testParsePersonIdent_legalCases() {
final Date when = new Date(1234567890000L); Instant when = Instant.ofEpochMilli(1234567890000L);
final TimeZone tz = TimeZone.getTimeZone("GMT-7"); ZoneId tz = ZoneOffset.ofHours(-7);
assertPersonIdent("Me <me@example.com> 1234567890 -0700", assertPersonIdent("Me <me@example.com> 1234567890 -0700",
new PersonIdent("Me", "me@example.com", when, tz)); new PersonIdent("Me", "me@example.com", when, tz));
...@@ -50,8 +53,8 @@ public void testParsePersonIdent_legalCases() { ...@@ -50,8 +53,8 @@ public void testParsePersonIdent_legalCases() {
@Test @Test
public void testParsePersonIdent_fuzzyCases() { public void testParsePersonIdent_fuzzyCases() {
final Date when = new Date(1234567890000L); Instant when = Instant.ofEpochMilli(1234567890000L);
final TimeZone tz = TimeZone.getTimeZone("GMT-7"); ZoneId tz = ZoneOffset.ofHours(-7);
assertPersonIdent( assertPersonIdent(
"A U Thor <author@example.com>, C O. Miter <comiter@example.com> 1234567890 -0700", "A U Thor <author@example.com>, C O. Miter <comiter@example.com> 1234567890 -0700",
...@@ -64,8 +67,8 @@ public void testParsePersonIdent_fuzzyCases() { ...@@ -64,8 +67,8 @@ public void testParsePersonIdent_fuzzyCases() {
@Test @Test
public void testParsePersonIdent_incompleteCases() { public void testParsePersonIdent_incompleteCases() {
final Date when = new Date(1234567890000L); Instant when = Instant.ofEpochMilli(1234567890000L);
final TimeZone tz = TimeZone.getTimeZone("GMT-7"); ZoneId tz = ZoneOffset.ofHours(-7);
assertPersonIdent("Me <> 1234567890 -0700", new PersonIdent("Me", "", assertPersonIdent("Me <> 1234567890 -0700", new PersonIdent("Me", "",
when, tz)); when, tz));
...@@ -76,26 +79,26 @@ public void testParsePersonIdent_incompleteCases() { ...@@ -76,26 +79,26 @@ public void testParsePersonIdent_incompleteCases() {
assertPersonIdent(" <> 1234567890 -0700", new PersonIdent("", "", when, assertPersonIdent(" <> 1234567890 -0700", new PersonIdent("", "", when,
tz)); 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("", assertPersonIdent("<me@example.com>", new PersonIdent("",
"me@example.com", 0, 0)); "me@example.com", EPOCH, UTC));
assertPersonIdent(" <me@example.com>", new PersonIdent("", 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", 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( 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( assertPersonIdent("Me <me@example.com> 1234567890 ", new PersonIdent(
"Me", "me@example.com", 0, 0)); "Me", "me@example.com", EPOCH, UTC));
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment