コード例 #1
1
 @Test
 public void shouldHaveNoSpecifiedButUnrealizedDependencies() {
   List<String> unrealized = new ArrayList<>();
   packageDependencies
       .keySet()
       .stream()
       .map(Package::getPackage)
       .forEach(
           sourcePackage ->
               dependenciesOf(sourcePackage)
                   .stream()
                   .filter(
                       dependency ->
                           !packageDependencies.get(sourcePackage.getName()).contains(dependency))
                   .forEach(target -> unrealized.add(sourcePackage + " -> " + target)));
   if (!unrealized.isEmpty()) fail("unrealized dependencies:\n" + String.join("\n", unrealized));
 }
コード例 #2
1
 @Test
 public void shouldHaveOnlyDefinedDependencies() {
   List<String> unexpected = new ArrayList<>();
   packageDependencies
       .keySet()
       .stream()
       .map(Package::getPackage)
       .forEach(
           sourcePackage -> {
             List<String> allowed = dependenciesOf(sourcePackage);
             String source = sourcePackage.getName();
             packageDependencies
                 .get(source)
                 .stream()
                 .filter(target -> !source.equals(target))
                 .filter(target -> !allowed.contains(target))
                 .filter(target -> !isAlwaysAllowed(target))
                 .forEach(target -> unexpected.add(source + " -> " + target));
           });
   if (!unexpected.isEmpty()) fail("unexpected dependencies:\n" + String.join("\n", unexpected));
 }