BaseProtectionTreeComparator extends ViewerComparator { @Override public int compare(Viewer viewer, Object o1, Object o2) { int result = 0; if (o1 instanceof SafeguardGroup && o2 instanceof SafeguardGroup) { result = compareModulesOrImplementationHints((SafeguardGroup) o1, (SafeguardGroup) o2); } else if (o1 instanceof BpRequirementGroup && o2 instanceof BpRequirementGroup) { result = compareModulesOrImplementationHints((BpRequirementGroup) o1, (BpRequirementGroup) o2); } else if (o1 instanceof Safeguard && o2 instanceof Safeguard) { SecurityLevel sl1 = ((Safeguard) o1).getSecurityLevel(); SecurityLevel sl2 = ((Safeguard) o2).getSecurityLevel(); result = SecurityLevel.compare(sl1, sl2); } else if (o1 instanceof BpRequirement && o2 instanceof BpRequirement) { SecurityLevel sl1 = ((BpRequirement) o1).getSecurityLevel(); SecurityLevel sl2 = ((BpRequirement) o2).getSecurityLevel(); result = SecurityLevel.compare(sl1, sl2); } if (result == 0) { result = super.compare(viewer, o1, o2); } return result; } BaseProtectionTreeComparator(); @Override int category(Object element); @Override int compare(Viewer viewer, Object o1, Object o2);  }
@Test public void compareSafeguardGroupsIsReflexive() { SafeguardGroup group; group = new SafeguardGroup(null); group.setTitel("titile"); Assert.assertEquals(EQ, underTest.compare(null, group, group)); group.setIdentifier("identifier"); Assert.assertEquals(EQ, underTest.compare(null, group, group)); }
@Test public void compareNestedSafeguardGroupsIsReflexive() { SafeguardGroup group; group = new SafeguardGroup(new SafeguardGroup(null)); group.setTitel("titile"); Assert.assertEquals(EQ, underTest.compare(null, group, group)); group.setIdentifier("identifier"); Assert.assertEquals(EQ, underTest.compare(null, group, group)); }
@Test public void compareSafeguardGroupsIsInvertible() { SafeguardGroup parent = new SafeguardGroup(null); parent.setTitel("Prozess-Bausteine"); SafeguardGroup group1 = new SafeguardGroup(parent); group1.setTitel("APP"); group1.setIdentifier("APP"); SafeguardGroup group2 = new SafeguardGroup(null); group2.setTitel("ISMS"); group2.setIdentifier("ISMS"); Assert.assertEquals(-underTest.compare(null, group2, group1), underTest.compare(null, group1, group2)); }
@Test public void compareSafeguardGroupsIsTransitive() { SafeguardGroup parent = new SafeguardGroup(null); parent.setTitel("Prozess-Bausteine"); SafeguardGroup group1 = new SafeguardGroup(parent); group1.setTitel("ISMS"); group1.setIdentifier("ISMS"); SafeguardGroup group2 = new SafeguardGroup(null); group2.setTitel("OPS"); group2.setIdentifier("OPS"); SafeguardGroup group3 = new SafeguardGroup(parent); group3.setTitel("NET"); group3.setIdentifier("NET"); Assert.assertEquals(LT, underTest.compare(null, group1, group2)); Assert.assertEquals(LT, underTest.compare(null, group2, group3)); Assert.assertEquals("a<b and b<c should imply a<c", LT, underTest.compare(null, group1, group3)); }