AbstractQueryChangesTest: Open TestRepository in try-with-resource

Since [1], included in JGit 5.3.0, TestRepository is AutoCloseable and
should be managed by try-with-resource.

[1] https://git.eclipse.org/r/#/c/134912

Change-Id: I77b0b5b8f49972f289d9e3cf0a7289e4904d5018
This commit is contained in:
David Pursehouse
2019-05-30 09:23:19 +09:00
parent 3b2df0674b
commit b37f59c372

View File

@@ -1958,22 +1958,23 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
assertQuery("draftby:" + userId, change);
assertQuery("commentby:" + userId);
TestRepository<Repo> allUsers = new TestRepository<>(repoManager.openRepository(allUsersName));
try (TestRepository<Repo> allUsers =
new TestRepository<>(repoManager.openRepository(allUsersName))) {
Ref draftsRef = allUsers.getRepository().exactRef(RefNames.refsDraftComments(id, userId));
assertThat(draftsRef).isNotNull();
Ref draftsRef = allUsers.getRepository().exactRef(RefNames.refsDraftComments(id, userId));
assertThat(draftsRef).isNotNull();
ReviewInput rin = ReviewInput.dislike();
rin.drafts = DraftHandling.PUBLISH_ALL_REVISIONS;
gApi.changes().id(id.get()).current().review(rin);
ReviewInput rin = ReviewInput.dislike();
rin.drafts = DraftHandling.PUBLISH_ALL_REVISIONS;
gApi.changes().id(id.get()).current().review(rin);
assertQuery("draftby:" + userId);
assertQuery("commentby:" + userId, change);
assertThat(allUsers.getRepository().exactRef(draftsRef.getName())).isNull();
assertQuery("draftby:" + userId);
assertQuery("commentby:" + userId, change);
assertThat(allUsers.getRepository().exactRef(draftsRef.getName())).isNull();
// Re-add drafts ref and ensure it gets filtered out during indexing.
allUsers.update(draftsRef.getName(), draftsRef.getObjectId());
assertThat(allUsers.getRepository().exactRef(draftsRef.getName())).isNotNull();
// Re-add drafts ref and ensure it gets filtered out during indexing.
allUsers.update(draftsRef.getName(), draftsRef.getObjectId());
assertThat(allUsers.getRepository().exactRef(draftsRef.getName())).isNotNull();
}
indexer.index(project, id);
assertQuery("draftby:" + userId);
@@ -3028,16 +3029,18 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
String destination4 = "refs/heads/master\trepo3";
String destination5 = "refs/heads/other\trepo1";
TestRepository<Repo> allUsers = new TestRepository<>(repoManager.openRepository(allUsersName));
String refsUsers = RefNames.refsUsers(userId);
allUsers.branch(refsUsers).commit().add("destinations/destination1", destination1).create();
allUsers.branch(refsUsers).commit().add("destinations/destination2", destination2).create();
allUsers.branch(refsUsers).commit().add("destinations/destination3", destination3).create();
allUsers.branch(refsUsers).commit().add("destinations/destination4", destination4).create();
allUsers.branch(refsUsers).commit().add("destinations/destination5", destination5).create();
try (TestRepository<Repo> allUsers =
new TestRepository<>(repoManager.openRepository(allUsersName))) {
String refsUsers = RefNames.refsUsers(userId);
allUsers.branch(refsUsers).commit().add("destinations/destination1", destination1).create();
allUsers.branch(refsUsers).commit().add("destinations/destination2", destination2).create();
allUsers.branch(refsUsers).commit().add("destinations/destination3", destination3).create();
allUsers.branch(refsUsers).commit().add("destinations/destination4", destination4).create();
allUsers.branch(refsUsers).commit().add("destinations/destination5", destination5).create();
Ref userRef = allUsers.getRepository().exactRef(refsUsers);
assertThat(userRef).isNotNull();
Ref userRef = allUsers.getRepository().exactRef(refsUsers);
assertThat(userRef).isNotNull();
}
assertQuery("destination:destination1", change1);
assertQuery("destination:destination2", change2);
@@ -3058,12 +3061,14 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests {
+ "query3\tproject:repo branch:stable\n"
+ "query4\tproject:repo branch:other";
TestRepository<Repo> allUsers = new TestRepository<>(repoManager.openRepository(allUsersName));
String refsUsers = RefNames.refsUsers(userId);
allUsers.branch(refsUsers).commit().add("queries", queries).create();
try (TestRepository<Repo> allUsers =
new TestRepository<>(repoManager.openRepository(allUsersName))) {
String refsUsers = RefNames.refsUsers(userId);
allUsers.branch(refsUsers).commit().add("queries", queries).create();
Ref userRef = allUsers.getRepository().exactRef(refsUsers);
assertThat(userRef).isNotNull();
Ref userRef = allUsers.getRepository().exactRef(refsUsers);
assertThat(userRef).isNotNull();
}
assertThatQueryException("query:foo").hasMessageThat().isEqualTo("Unknown named query: foo");