Use available PathOwners constructors in tests
New PathOwners constructors were added [1] but the
tests in owners-common weren't adapted.
Use the available constructor.
[1]: https://gerrit-review.googlesource.com/c/plugins/owners/+/337422
Issue: Bug 16685
Change-Id: I5178cc40430a2cea3233a16f9dcb8709c0ee922a
diff --git a/owners-common/src/test/java/com/googlesource/gerrit/owners/common/Config.java b/owners-common/src/test/java/com/googlesource/gerrit/owners/common/Config.java
index f298164..d6fb4e7 100644
--- a/owners-common/src/test/java/com/googlesource/gerrit/owners/common/Config.java
+++ b/owners-common/src/test/java/com/googlesource/gerrit/owners/common/Config.java
@@ -21,13 +21,9 @@
import com.google.common.base.Charsets;
import com.google.gerrit.entities.Patch;
import com.google.gerrit.server.git.GitRepositoryManager;
-import com.google.gerrit.server.patch.PatchList;
import com.google.gerrit.server.patch.PatchListEntry;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
import java.util.Optional;
-import java.util.stream.Collectors;
import org.eclipse.jgit.lib.Repository;
import org.junit.Ignore;
import org.powermock.api.easymock.PowerMock;
@@ -38,7 +34,6 @@
protected Repository repository;
protected Repository parentRepository1;
protected Repository parentRepository2;
- protected PatchList patchList;
protected ConfigurationParser parser;
protected TestAccounts accounts = new TestAccounts();
protected Optional<String> branch = Optional.of("master");
@@ -81,17 +76,6 @@
.anyTimes();
}
- void creatingPatch(String... fileNames) {
- creatingPatchList(Arrays.asList(fileNames));
- }
-
- void creatingPatchList(List<String> names) {
- patchList = PowerMock.createMock(PatchList.class);
- List<PatchListEntry> entries =
- names.stream().map(name -> expectEntry(name)).collect(Collectors.toList());
- expect(patchList.getPatches()).andReturn(entries);
- }
-
PatchListEntry expectEntry(String name) {
PatchListEntry entry = PowerMock.createMock(PatchListEntry.class);
expect(entry.getNewName()).andReturn(name).anyTimes();
diff --git a/owners-common/src/test/java/com/googlesource/gerrit/owners/common/PathOwnersTest.java b/owners-common/src/test/java/com/googlesource/gerrit/owners/common/PathOwnersTest.java
index e8b4167..ac865ed 100644
--- a/owners-common/src/test/java/com/googlesource/gerrit/owners/common/PathOwnersTest.java
+++ b/owners-common/src/test/java/com/googlesource/gerrit/owners/common/PathOwnersTest.java
@@ -70,7 +70,7 @@
repository,
Collections.EMPTY_LIST,
branch,
- patchList,
+ Set.of(CLASSIC_FILE_TXT),
EXPAND_GROUPS);
Set<Account.Id> ownersSet = owners.get().get(CLASSIC_OWNERS);
assertEquals(2, ownersSet.size());
@@ -90,7 +90,7 @@
repository,
EMPTY_LIST,
branch,
- patchList,
+ Set.of(CLASSIC_FILE_TXT),
DO_NOT_EXPAND_GROUPS);
Set<String> ownersSet = owners.getFileGroupOwners().get(CLASSIC_FILE_TXT);
assertEquals(2, ownersSet.size());
@@ -110,7 +110,7 @@
repository,
EMPTY_LIST,
Optional.empty(),
- patchList,
+ Set.of(CLASSIC_FILE_TXT),
EXPAND_GROUPS);
Set<Account.Id> ownersSet = owners.get().get(CLASSIC_OWNERS);
assertEquals(0, ownersSet.size());
@@ -121,12 +121,17 @@
expectConfig("OWNERS", createConfig(true, owners(USER_C_EMAIL_COM)));
expectConfig(CLASSIC_OWNERS, createConfig(true, owners(USER_A_EMAIL_COM, USER_B_EMAIL_COM)));
- creatingPatchList(Arrays.asList("classic/file.txt"));
replayAll();
PathOwners owners2 =
new PathOwners(
- accounts, repositoryManager, repository, EMPTY_LIST, branch, patchList, EXPAND_GROUPS);
+ accounts,
+ repositoryManager,
+ repository,
+ EMPTY_LIST,
+ branch,
+ Set.of("classic/file.txt"),
+ EXPAND_GROUPS);
Set<Account.Id> ownersSet2 = owners2.get().get(CLASSIC_OWNERS);
// in this case we are inheriting the acct3 from /OWNERS
@@ -145,12 +150,17 @@
createConfig(true, owners(), suffixMatcher(".sql", USER_A_EMAIL_COM, USER_B_EMAIL_COM)));
String fileName = "file.sql";
- creatingPatchList(Collections.singletonList(fileName));
replayAll();
PathOwners owners =
new PathOwners(
- accounts, repositoryManager, repository, EMPTY_LIST, branch, patchList, EXPAND_GROUPS);
+ accounts,
+ repositoryManager,
+ repository,
+ EMPTY_LIST,
+ branch,
+ Set.of(fileName),
+ EXPAND_GROUPS);
Map<String, Set<Account.Id>> fileOwners = owners.getFileOwners();
assertEquals(1, fileOwners.size());
@@ -172,7 +182,6 @@
createConfig(true, owners(), suffixMatcher(".sql", USER_A_EMAIL_COM, USER_B_EMAIL_COM)));
String fileName = "file.sql";
- creatingPatchList(Collections.singletonList(fileName));
mockParentRepository(parentRepository1NameKey, parentRepository1);
replayAll();
@@ -184,7 +193,7 @@
repository,
Arrays.asList(parentRepository1NameKey),
branch,
- patchList,
+ Set.of(fileName),
EXPAND_GROUPS);
Map<String, Set<Account.Id>> fileOwners = owners.getFileOwners();
@@ -213,7 +222,6 @@
String sqlFileName = "file.sql";
String javaFileName = "file.java";
- creatingPatchList(Arrays.asList(sqlFileName, javaFileName));
mockParentRepository(parentRepository1NameKey, parentRepository1);
mockParentRepository(parentRepository2NameKey, parentRepository2);
@@ -226,7 +234,7 @@
repository,
Arrays.asList(parentRepository1NameKey, parentRepository2NameKey),
branch,
- patchList,
+ Set.of(sqlFileName, javaFileName),
EXPAND_GROUPS);
Map<String, Set<Account.Id>> fileOwners = owners.getFileOwners();
@@ -254,12 +262,17 @@
expectConfig("dir/OWNERS", createConfig(true, owners(USER_B_EMAIL_COM)));
expectConfig("dir/subdir/OWNERS", createConfig(true, owners(USER_A_EMAIL_COM)));
- creatingPatchList(Arrays.asList("dir/subdir/file.txt"));
replayAll();
PathOwners owners =
new PathOwners(
- accounts, repositoryManager, repository, EMPTY_LIST, branch, patchList, EXPAND_GROUPS);
+ accounts,
+ repositoryManager,
+ repository,
+ EMPTY_LIST,
+ branch,
+ Set.of("dir/subdir/file.txt"),
+ EXPAND_GROUPS);
Set<Account.Id> ownersSet = owners.get().get("dir/subdir/OWNERS");
assertEquals(3, ownersSet.size());
@@ -282,7 +295,6 @@
expectNoConfig("OWNERS");
expectConfig(CLASSIC_OWNERS, createConfig(false, owners(owners)));
- creatingPatchList(Arrays.asList(CLASSIC_FILE_TXT));
replayAll();
}
}
diff --git a/owners-common/src/test/java/com/googlesource/gerrit/owners/common/RegexTest.java b/owners-common/src/test/java/com/googlesource/gerrit/owners/common/RegexTest.java
index 8fea7ed..72a6d84 100644
--- a/owners-common/src/test/java/com/googlesource/gerrit/owners/common/RegexTest.java
+++ b/owners-common/src/test/java/com/googlesource/gerrit/owners/common/RegexTest.java
@@ -28,7 +28,6 @@
import static org.powermock.api.easymock.PowerMock.replayAll;
import com.google.gerrit.entities.Account;
-import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -141,21 +140,25 @@
expectConfig("OWNERS", parentConfig);
expectConfig("project/OWNERS", childConfig);
- creatingPatchList(
- Arrays.asList(
- "project/file.txt", // matches exact in
- // project owners d,e
- "file1.txt", // no matches so nothing for this
- "project/afile2.sql", // matches two matchers so we have b,c,d
- "project/bfile.txt", // no matching
- "projectalfa", // matches PartialRegex
- "project/file.sql")); // only .sql matching b,c
replayAll();
// function under test
PathOwners owners =
new PathOwners(
- accounts, repositoryManager, repository, EMPTY_LIST, branch, patchList, EXPAND_GROUPS);
+ accounts,
+ repositoryManager,
+ repository,
+ EMPTY_LIST,
+ branch,
+ Set.of(
+ "project/file.txt", // matches exact in
+ // project owners d,e
+ "file1.txt", // no matches so nothing for this
+ "project/afile2.sql", // matches two matchers so we have b,c,d
+ "project/bfile.txt", // no matching
+ "projectalfa", // matches PartialRegex
+ "project/file.sql"), // only .sql matching b,c
+ EXPAND_GROUPS);
// assertions on classic owners
Set<Account.Id> ownersSet = owners.get().get("project/OWNERS");
@@ -253,12 +256,17 @@
expectConfig("OWNERS", configString);
expectNoConfig("project/OWNERS");
- creatingPatch("project/file.sql", "another.txt");
replayAll();
PathOwners owners =
new PathOwners(
- accounts, repositoryManager, repository, EMPTY_LIST, branch, patchList, EXPAND_GROUPS);
+ accounts,
+ repositoryManager,
+ repository,
+ EMPTY_LIST,
+ branch,
+ Set.of("project/file.sql", "another.txt"),
+ EXPAND_GROUPS);
Set<String> ownedFiles = owners.getFileOwners().keySet();
assertThat(ownedFiles).containsExactly("project/file.sql");