@SafeVarargs
  private static StackModule createStackModule(String stackName, String stackVersion, Optional<? extends List<RepositoryInfo>> stackRepos,
                                        List<RepositoryInfo>... serviceRepoLists) throws AmbariException {
    StackDirectory sd = mock(StackDirectory.class);
    List<ServiceDirectory> serviceDirectories = Lists.newArrayList();
    for (List<RepositoryInfo> serviceRepoList: serviceRepoLists) {
      StackServiceDirectory svd = mock(StackServiceDirectory.class);
      RepositoryXml serviceRepoXml = mock(RepositoryXml.class);
      when(svd.getRepoFile()).thenReturn(serviceRepoXml);
      when(serviceRepoXml.getRepositories()).thenReturn(serviceRepoList);
      ServiceMetainfoXml serviceMetainfoXml = mock(ServiceMetainfoXml.class);
      when(serviceMetainfoXml.isValid()).thenReturn(true);
      ServiceInfo serviceInfo = mock(ServiceInfo.class);
      when(serviceInfo.isValid()).thenReturn(true);
      when(serviceInfo.getName()).thenReturn(UUID.randomUUID().toString()); // unique service names
      when(serviceMetainfoXml.getServices()).thenReturn(Lists.newArrayList(serviceInfo));
      when(svd.getMetaInfoFile()).thenReturn(serviceMetainfoXml);
      serviceDirectories.add(svd);
    }
    if (stackRepos.isPresent()) {
      RepositoryXml stackRepoXml = mock(RepositoryXml.class);
      when(sd.getRepoFile()).thenReturn(stackRepoXml);
      when(stackRepoXml.getRepositories()).thenReturn(stackRepos.get());
    }
    when(sd.getServiceDirectories()).thenReturn(serviceDirectories);
    when(sd.getStackDirName()).thenReturn(stackName);
    when(sd.getDirectory()).thenReturn(new File(stackVersion));
    StackContext ctx = mock(StackContext.class);
    StackModule sm = new StackModule(sd, ctx);
    sm.resolve(null,
        ImmutableMap.of(String.format("%s:%s", stackName, stackVersion), sm),
        ImmutableMap.of(), ImmutableMap.of());
    return sm;
  }
If two add-on services define the same repo, the repo should be disregarded.
This applies per os, so the same repo can be defined for multiple os'es (e.g redhat5 and redhat6)
@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/stack/StackModuleTest.java