aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.junit/src/org/eclipse
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2024-11-04 15:23:47 -0800
committerIvan Frade <ifrade@google.com>2024-12-13 13:23:12 -0800
commit320a95e37d3f791b0d16ff7753bc1d7b68b0681f (patch)
treef853bb9f777bc933e8f06a5478968d7943ab2d6a /org.eclipse.jgit.junit/src/org/eclipse
parent9cf0a1f174886f844f61d056d4c3383415d27b9e (diff)
downloadjgit-320a95e37d3f791b0d16ff7753bc1d7b68b0681f.tar.gz
jgit-320a95e37d3f791b0d16ff7753bc1d7b68b0681f.zip
TestRepository: Deprecate #getDate and use #getInstant instead
Errorprone recomments to use the more modern java.time API instead of the java.util.Date family of classes. This removes all uses of TestRepository#getDate and replace them with getInstant. The method is marked as deprecated and doesn't have any other usages. Change-Id: I84ea63abf781d0d3c7c2724891fd2ef7afc2db1d
Diffstat (limited to 'org.eclipse.jgit.junit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java33
1 files changed, 24 insertions, 9 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
index c6cdfafe84..33ec042930 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.time.Instant;
+import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -198,7 +199,9 @@ public class TestRepository<R extends Repository> implements AutoCloseable {
*
* @return current date.
* @since 4.2
+ * @deprecated Use {@link #getInstant()} instead.
*/
+ @Deprecated
public Date getDate() {
return new Date(mockSystemReader.getCurrentTime());
}
@@ -210,18 +213,30 @@ public class TestRepository<R extends Repository> implements AutoCloseable {
* @since 6.8
*/
public Instant getInstant() {
- return Instant.ofEpochMilli(mockSystemReader.getCurrentTime());
+ return mockSystemReader.now();
}
/**
* Get timezone
*
* @return timezone used for default identities.
+ * @deprecated Use {@link #getTimeZoneId()} instead.
*/
+ @Deprecated
public TimeZone getTimeZone() {
return mockSystemReader.getTimeZone();
}
+
+ /**
+ * Get timezone
+ *
+ * @return timezone used for default identities.
+ */
+ public ZoneId getTimeZoneId() {
+ return mockSystemReader.getTimeZoneId();
+ }
+
/**
* Adjust the current time that will used by the next commit.
*
@@ -233,14 +248,14 @@ public class TestRepository<R extends Repository> implements AutoCloseable {
}
/**
- * Set the author and committer using {@link #getDate()}.
+ * Set the author and committer using {@link #getInstant()}.
*
* @param c
* the commit builder to store.
*/
public void setAuthorAndCommitter(org.eclipse.jgit.lib.CommitBuilder c) {
- c.setAuthor(new PersonIdent(defaultAuthor, getDate()));
- c.setCommitter(new PersonIdent(defaultCommitter, getDate()));
+ c.setAuthor(new PersonIdent(defaultAuthor, getInstant()));
+ c.setCommitter(new PersonIdent(defaultCommitter, getInstant()));
}
/**
@@ -488,8 +503,8 @@ public class TestRepository<R extends Repository> implements AutoCloseable {
c = new org.eclipse.jgit.lib.CommitBuilder();
c.setTreeId(tree);
c.setParentIds(parents);
- c.setAuthor(new PersonIdent(defaultAuthor, getDate()));
- c.setCommitter(new PersonIdent(defaultCommitter, getDate()));
+ c.setAuthor(new PersonIdent(defaultAuthor, getInstant()));
+ c.setCommitter(new PersonIdent(defaultCommitter, getInstant()));
c.setMessage("");
ObjectId id;
try (ObjectInserter ins = inserter) {
@@ -529,7 +544,7 @@ public class TestRepository<R extends Repository> implements AutoCloseable {
final TagBuilder t = new TagBuilder();
t.setObjectId(dst);
t.setTag(name);
- t.setTagger(new PersonIdent(defaultCommitter, getDate()));
+ t.setTagger(new PersonIdent(defaultCommitter, getInstant()));
t.setMessage("");
ObjectId id;
try (ObjectInserter ins = inserter) {
@@ -798,7 +813,7 @@ public class TestRepository<R extends Repository> implements AutoCloseable {
b.setParentId(head);
b.setTreeId(merger.getResultTreeId());
b.setAuthor(commit.getAuthorIdent());
- b.setCommitter(new PersonIdent(defaultCommitter, getDate()));
+ b.setCommitter(new PersonIdent(defaultCommitter, getInstant()));
b.setMessage(commit.getFullMessage());
ObjectId result;
try (ObjectInserter ins = inserter) {
@@ -1408,7 +1423,7 @@ public class TestRepository<R extends Repository> implements AutoCloseable {
c.setAuthor(author);
if (committer != null) {
if (updateCommitterTime)
- committer = new PersonIdent(committer, getDate());
+ committer = new PersonIdent(committer, getInstant());
c.setCommitter(committer);
}