EffectivityConfigSpec extends ProductConfigSpec { @Override public PartLink filterPartLink(List<PartLink> path) { if(configuration !=null){ PartLink nominalLink = path.get(path.size()-1); if(nominalLink.isOptional()){ String pathAsString = Tools.getPathAsString(path); if(!configuration.isOptionalLinkRetained(pathAsString)) { return null; } retainedOptionalUsageLinks.add(pathAsString); } for(PartSubstituteLink substituteLink:nominalLink.getSubstitutes()){ List<PartLink> substitutePath = new ArrayList<>(path); substitutePath.set(substitutePath.size()-1,substituteLink); String substitutePathAsString = Tools.getPathAsString(substitutePath); if(configuration.hasSubstituteLink(substitutePathAsString)){ retainedSubstituteLinks.add(substitutePathAsString); return substituteLink; } } return nominalLink; }else{ return filterNominalPartLink(path); } } EffectivityConfigSpec(ConfigurationItem configurationItem);  EffectivityConfigSpec(ProductConfiguration configuration); ConfigurationItem getConfigurationItem(); @Override PartIteration filterPartIteration(PartMaster partMaster); @Override PartLink filterPartLink(List<PartLink> path);  }
@Test public void filterPartLinkTest(){ when(link3.isOptional()).thenReturn(true); PartLink result = effectivityConfigSpec.filterPartLink(Arrays.asList(link1,link2,link3)); Assert.assertNull(result); when(configuration.isOptionalLinkRetained(anyString())).thenReturn(true); when(link3.getSubstitutes()).thenReturn(new ArrayList<>()); result = effectivityConfigSpec.filterPartLink(Arrays.asList(link1,link2,link3)); Assert.assertEquals(link3, result); when(configuration.hasSubstituteLink(anyString())).thenReturn(true); when(link2.getSubstitutes()).thenReturn(Arrays.asList(pSLink1,pSLink2,pSLink3)); when(link2.isOptional()).thenReturn(true); result = effectivityConfigSpec.filterPartLink(Arrays.asList(link1,link2)); Assert.assertEquals(pSLink1,result); when(configuration.hasSubstituteLink(anyString())).thenReturn(false); when(link2.getSubstitutes()).thenReturn(Arrays.asList(pSLink2,pSLink3)); when(link2.isOptional()).thenReturn(true); result = effectivityConfigSpec.filterPartLink(Arrays.asList(link1,link2)); Assert.assertEquals(link2,result); when(link1.isOptional()).thenReturn(false); when(link1.getSubstitutes()).thenReturn(new ArrayList<>()); result = effectivityConfigSpec.filterPartLink(Arrays.asList(link1)); Assert.assertEquals(link1,result); when(configuration.hasSubstituteLink(anyString())).thenReturn(true); when(link1.getSubstitutes()).thenReturn(Arrays.asList(pSLink3)); result = effectivityConfigSpec.filterPartLink(Arrays.asList(link1)); Assert.assertEquals(pSLink3,result); HashSet<String> retainedUsageLinks = (HashSet) Whitebox.getInternalState(effectivityConfigSpec, "retainedOptionalUsageLinks"); HashSet<String> retainedSubstituteLinks = (HashSet) Whitebox.getInternalState(effectivityConfigSpec, "retainedSubstituteLinks"); Assert.assertFalse(retainedUsageLinks.isEmpty()); Assert.assertEquals(2,retainedUsageLinks.size()); Assert.assertEquals(2,retainedSubstituteLinks.size()); Whitebox.setInternalState(effectivityConfigSpec,"configuration",null); result = effectivityConfigSpec.filterPartLink(Arrays.asList(link1)); Assert.assertEquals(link1, result); when(link1.isOptional()).thenReturn(true); result = effectivityConfigSpec.filterPartLink(Arrays.asList(link1)); Assert.assertNull(result); }