Fix JGitHealthCheckTest by wrapping ref-update with test context The [1] change introduces the validation of a test context that is needed for all ref-updates. Adjust the test case to adhere to the new requirements. [1] https://gerrit-review.googlesource.com/c/gerrit/+/357956 Change-Id: I25a446b558f30115be60d5d6bf5d5d501f3cc1e5
diff --git a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/JGitHealthCheckTest.java b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/JGitHealthCheckTest.java index 5c1fd73..b589dcc 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/healthcheck/JGitHealthCheckTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/healthcheck/JGitHealthCheckTest.java
@@ -15,6 +15,7 @@ package com.googlesource.gerrit.plugins.healthcheck; import static com.google.common.truth.Truth.assertThat; +import static com.google.gerrit.testing.TestActionRefUpdateContext.testRefAction; import static com.googlesource.gerrit.plugins.healthcheck.HealthCheckConfig.DEFAULT_CONFIG; import static com.googlesource.gerrit.plugins.healthcheck.check.HealthCheckNames.JGIT; import static org.eclipse.jgit.lib.RefUpdate.Result.NEW; @@ -130,17 +131,20 @@ } private void createCommit(InMemoryRepositoryManager.Repo repo, String ref) throws IOException { - try (ObjectInserter oi = repo.newObjectInserter()) { - CommitBuilder cb = new CommitBuilder(); - cb.setTreeId(oi.insert(Constants.OBJ_TREE, new byte[] {})); - cb.setAuthor(personIdent); - cb.setCommitter(personIdent); - cb.setMessage("Test commit\n"); - ObjectId id = oi.insert(cb); - oi.flush(); - RefUpdate ru = repo.updateRef(ref); - ru.setNewObjectId(id); - assertThat(ru.update()).isEqualTo(NEW); - } + testRefAction( + () -> { + try (ObjectInserter oi = repo.newObjectInserter()) { + CommitBuilder cb = new CommitBuilder(); + cb.setTreeId(oi.insert(Constants.OBJ_TREE, new byte[] {})); + cb.setAuthor(personIdent); + cb.setCommitter(personIdent); + cb.setMessage("Test commit\n"); + ObjectId id = oi.insert(cb); + oi.flush(); + RefUpdate ru = repo.updateRef(ref); + ru.setNewObjectId(id); + assertThat(ru.update()).isEqualTo(NEW); + } + }); } }