ProductConfig { public boolean uniqueAttachIds() { Set<String> attachIDs = new HashSet<>(); for (Product product : products) { if (!attachIDs.contains(product.getAttachId())) { attachIDs.add(product.getAttachId()); } else { return false; } } return true; } ProductConfig(List<Product> userConfig, Collection<DependencySeed> projectSeeds); boolean uniqueAttachIds(); List<Product> getProducts();  }
@Test public void testUniqueAttachIds() throws Exception { projectSeeds.add(productSeed("product.id.1")); projectSeeds.add(productSeed("product.id.2")); projectSeeds.add(productSeed("product.id.3")); List<Product> userConfig = Arrays.asList(new Product("product.id.2"), new Product("product.id.3", "extra")); subject = new ProductConfig(userConfig, projectSeeds); assertEquals(true, subject.uniqueAttachIds()); }
@Test public void testDuplicateAttachId() throws Exception { projectSeeds.add(productSeed("product.id.1")); projectSeeds.add(productSeed("product.id.2")); subject = new ProductConfig(null, projectSeeds); assertEquals(false, subject.uniqueAttachIds()); }
@Test public void testDuplicateExplicitAttachId() throws Exception { projectSeeds.add(productSeed("product.id.1")); projectSeeds.add(productSeed("product.id.2")); projectSeeds.add(productSeed("product.id.3")); List<Product> userConfig = Arrays.asList(new Product("product.id.1", "attach"), new Product("product.id.2"), new Product("product.id.3", "attach")); subject = new ProductConfig(userConfig, projectSeeds); assertEquals(false, subject.uniqueAttachIds()); }