follow-up to "Exclude repo from ChangeCacheKey..."
Simplify the unit tests by using repository mock instead of
instantiation of the 'InMemoryRepository' repository.
Change-Id: Ib2a53ad06e882d7bde6e63a1826a68aad9971104
diff --git a/src/test/java/com/googlesource/gerrit/modules/gitrefsfilter/ChangeCacheKeyTest.java b/src/test/java/com/googlesource/gerrit/modules/gitrefsfilter/ChangeCacheKeyTest.java
index eae3624..df68a5e 100644
--- a/src/test/java/com/googlesource/gerrit/modules/gitrefsfilter/ChangeCacheKeyTest.java
+++ b/src/test/java/com/googlesource/gerrit/modules/gitrefsfilter/ChangeCacheKeyTest.java
@@ -15,13 +15,11 @@
package com.googlesource.gerrit.modules.gitrefsfilter;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.Project.NameKey;
-import java.io.IOException;
-import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
-import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.junit.Test;
@@ -33,27 +31,20 @@
private static final NameKey TEST_REPO = Project.nameKey(REPO_NAME);
@Test
- public void shouldExcludeRepoFieldDuringEqualsCalculation() throws IOException {
+ public void shouldExcludeRepoFieldDuringEqualsCalculation() {
ChangeCacheKey cacheKey1 =
- ChangeCacheKey.create(newRepository(), ID, CHANGE_REVISION, TEST_REPO);
+ ChangeCacheKey.create(mock(Repository.class), ID, CHANGE_REVISION, TEST_REPO);
ChangeCacheKey cacheKey2 =
- ChangeCacheKey.create(newRepository(), ID, CHANGE_REVISION, TEST_REPO);
+ ChangeCacheKey.create(mock(Repository.class), ID, CHANGE_REVISION, TEST_REPO);
assertThat(cacheKey1).isEqualTo(cacheKey2);
}
@Test
- public void shouldExcludeRepoFieldDuringHashCodeCalculation() throws IOException {
- try (Repository repo1 = newRepository();
- Repository repo2 = newRepository()) {
- ChangeCacheKey cacheKey1 = ChangeCacheKey.create(repo1, ID, CHANGE_REVISION, TEST_REPO);
- ChangeCacheKey cacheKey2 = ChangeCacheKey.create(repo2, ID, CHANGE_REVISION, TEST_REPO);
- assertThat(cacheKey1.hashCode()).isEqualTo(cacheKey2.hashCode());
- }
- }
-
- private Repository newRepository() throws IOException {
- return new InMemoryRepository.Builder()
- .setRepositoryDescription(new DfsRepositoryDescription(REPO_NAME))
- .build();
+ public void shouldExcludeRepoFieldDuringHashCodeCalculation() {
+ ChangeCacheKey cacheKey1 =
+ ChangeCacheKey.create(mock(Repository.class), ID, CHANGE_REVISION, TEST_REPO);
+ ChangeCacheKey cacheKey2 =
+ ChangeCacheKey.create(mock(Repository.class), ID, CHANGE_REVISION, TEST_REPO);
+ assertThat(cacheKey1.hashCode()).isEqualTo(cacheKey2.hashCode());
}
}