SubmoduleOp: Change type of newSubscriptions to Set
Originally suggested by Dave in the review of I1eaf452d549939764 though as this required some more changes in the SubmoduleSectionParser and its mock test this is separated out. Change-Id: I3208b6c1ba8c97b8ad65bbe5080bb5f0e2125ab8
This commit is contained in:
@@ -160,7 +160,7 @@ public class SubmoduleOp {
|
||||
Sets.newHashSet(schema.submoduleSubscriptions()
|
||||
.bySuperProject(destBranch));
|
||||
|
||||
List<SubmoduleSubscription> newSubscriptions;
|
||||
Set<SubmoduleSubscription> newSubscriptions;
|
||||
TreeWalk tw = TreeWalk.forPath(db, GIT_MODULES, mergeTip.getTree());
|
||||
if (tw != null
|
||||
&& (FileMode.REGULAR_FILE.equals(tw.getRawMode(0)) ||
|
||||
@@ -177,7 +177,7 @@ public class SubmoduleOp {
|
||||
newSubscriptions = subSecParserFactory.create(bbc, thisServer, target)
|
||||
.parseAllSections();
|
||||
} else {
|
||||
newSubscriptions = Collections.emptyList();
|
||||
newSubscriptions = Collections.emptySet();
|
||||
}
|
||||
|
||||
Set<SubmoduleSubscription> alreadySubscribeds = new HashSet<>();
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.util;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.SubmoduleSubscription;
|
||||
@@ -26,8 +27,7 @@ import org.eclipse.jgit.lib.Constants;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* It parses from a configuration file submodule sections.
|
||||
@@ -69,8 +69,8 @@ public class SubmoduleSectionParser {
|
||||
this.superProjectBranch = superProjectBranch;
|
||||
}
|
||||
|
||||
public List<SubmoduleSubscription> parseAllSections() {
|
||||
List<SubmoduleSubscription> parsedSubscriptions = new ArrayList<>();
|
||||
public Set<SubmoduleSubscription> parseAllSections() {
|
||||
Set<SubmoduleSubscription> parsedSubscriptions = Sets.newHashSet();
|
||||
for (final String id : bbc.getSubsections("submodule")) {
|
||||
final SubmoduleSubscription subscription = parse(id);
|
||||
if (subscription != null) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.SubmoduleSubscription;
|
||||
@@ -34,10 +35,10 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
|
||||
@@ -87,7 +88,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
|
||||
new Branch.NameKey(new Project.NameKey("super-project"),
|
||||
"refs/heads/master");
|
||||
|
||||
List<SubmoduleSubscription> expectedSubscriptions = new ArrayList<>();
|
||||
Set<SubmoduleSubscription> expectedSubscriptions = Sets.newHashSet();
|
||||
expectedSubscriptions
|
||||
.add(new SubmoduleSubscription(superBranchNameKey, new Branch.NameKey(
|
||||
new Project.NameKey("a"), "refs/heads/master"), "a"));
|
||||
@@ -134,7 +135,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
|
||||
new Branch.NameKey(new Project.NameKey("super-project"),
|
||||
"refs/heads/master");
|
||||
|
||||
List<SubmoduleSubscription> expectedSubscriptions = new ArrayList<>();
|
||||
Set<SubmoduleSubscription> expectedSubscriptions = Sets.newHashSet();
|
||||
expectedSubscriptions
|
||||
.add(new SubmoduleSubscription(superBranchNameKey, new Branch.NameKey(
|
||||
new Project.NameKey("a"), "refs/heads/master"), "a"));
|
||||
@@ -159,9 +160,10 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
|
||||
sectionsToReturn.put("a", new SubmoduleSection("ssh://review.source.com/a",
|
||||
"a", "."));
|
||||
|
||||
Set<SubmoduleSubscription> expectedSubscriptions = Collections.emptySet();
|
||||
execute(new Branch.NameKey(new Project.NameKey("super-project"),
|
||||
"refs/heads/master"), sectionsToReturn, new HashMap<String, String>(),
|
||||
new ArrayList<SubmoduleSubscription>());
|
||||
expectedSubscriptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,9 +172,10 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
|
||||
sectionsToReturn.put("a", new SubmoduleSection("ssh://localhost/a", "a",
|
||||
"."));
|
||||
|
||||
Set<SubmoduleSubscription> expectedSubscriptions = Collections.emptySet();
|
||||
execute(new Branch.NameKey(new Project.NameKey("super-project"),
|
||||
"refs/heads/master"), sectionsToReturn, new HashMap<String, String>(),
|
||||
new ArrayList<SubmoduleSubscription>());
|
||||
expectedSubscriptions);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,15 +184,16 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
|
||||
sectionsToReturn.put("project", new SubmoduleSection(
|
||||
"ssh://localhost/company/tools/project", "project", "."));
|
||||
|
||||
Set<SubmoduleSubscription> expectedSubscriptions = Collections.emptySet();
|
||||
execute(new Branch.NameKey(new Project.NameKey("super-project"),
|
||||
"refs/heads/master"), sectionsToReturn, new HashMap<String, String>(),
|
||||
new ArrayList<SubmoduleSubscription>());
|
||||
expectedSubscriptions);
|
||||
}
|
||||
|
||||
private void execute(final Branch.NameKey superProjectBranch,
|
||||
final Map<String, SubmoduleSection> sectionsToReturn,
|
||||
final Map<String, String> reposToBeFound,
|
||||
final List<SubmoduleSubscription> expectedSubscriptions) throws Exception {
|
||||
final Set<SubmoduleSubscription> expectedSubscriptions) throws Exception {
|
||||
expect(bbc.getSubsections("submodule"))
|
||||
.andReturn(sectionsToReturn.keySet());
|
||||
|
||||
@@ -231,7 +235,7 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase {
|
||||
new SubmoduleSectionParser(projectCache, bbc, THIS_SERVER,
|
||||
superProjectBranch);
|
||||
|
||||
List<SubmoduleSubscription> returnedSubscriptions = ssp.parseAllSections();
|
||||
Set<SubmoduleSubscription> returnedSubscriptions = ssp.parseAllSections();
|
||||
|
||||
doVerify();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user