CodemapToLevel { public static Level transform(Codemap codemap, String levelName) { Level level = new Level(levelName); for (CodePackage packet : codemap.packages()) { Component component = componentFor(packet, level); if (component == null) continue; component.incrementSizeBy(packet.size()); } for (PackageDep packageDep : codemap.packageDeps()) { Component fromComponent = componentFor(packageDep.from, level); if (fromComponent == null) continue; Component toComponent = componentFor(packageDep.to, level); if (toComponent == null) continue; if (fromComponent == toComponent) continue; ComponentDep componentDep = level.dependency(fromComponent, toComponent); componentDep.incrementStrengthBy(packageDep.strength()); } return level; }  static Level transform(Codemap codemap, String levelName);  }
@Test public void lower_level() { String levelName = "animal.domestic"; Level level = transform(codemap, levelName); log.info("produced level '{}':\n{}", levelName, level.formatted()); Component cat = new Component("cat"); Component dog = new Component("dog"); Component fish = new Component("fish"); assertThat(level.name).isEqualTo(levelName); assertThat(level.components).containsExactly(cat, dog, fish); assertThat(level.dependencies).containsExactly( new ComponentDep(cat, fish), new ComponentDep(dog, cat) ); assertThat(level.dependency(cat, fish).strength).isEqualTo(1); assertThat(level.dependency(dog, cat).strength).isEqualTo(2); assertThat(level.component("cat").size).isGreaterThan(level.component("dog").size); assertThat(level.component("dog").size).isEqualTo(level.component("fish").size); }
@Test public void upper_level() { String levelName = "animal"; Level level = transform(codemap, levelName); log.info("produced level '{}':\n{}", levelName, level.formatted()); Component domestic = new Component("domestic"); Component rodent = new Component("rodent"); assertThat(level.name).isEqualTo(levelName); assertThat(level.components).containsExactly(domestic, rodent); assertThat(level.dependencies).containsExactly( new ComponentDep(domestic, rodent) ); assertThat(level.dependency(domestic, rodent).strength).isEqualTo(2); assertThat(level.component("domestic").size).isGreaterThan(level.component("rodent").size); }
@Test public void top_level() { String levelName = ""; Level level = transform(codemap, levelName); log.info("produced level '{}':\n{}", levelName, level.formatted()); Component animal = new Component("animal"); Component ghost = new Component("ghost"); Component plant = new Component("plant"); assertThat(level.name).isEqualTo(levelName); assertThat(level.components).containsExactly(animal, ghost, plant); assertThat(level.dependencies).containsExactly( new ComponentDep(animal, plant), new ComponentDep(plant, animal) ); assertThat(level.dependency(animal, plant).strength).isEqualTo(2); assertThat(level.dependency(plant, animal).strength).isEqualTo(1); assertThat(level.component("animal").size).isGreaterThan(level.component("plant").size); }
@Test public void atypical_level() { String levelName = "animal.rodent"; Level level = transform(codemap, levelName); log.info("produced level '{}':\n{}", levelName, level.formatted()); Component root = new Component("[root]"); Component mouse = new Component("mouse"); assertThat(level.name).isEqualTo(levelName); assertThat(level.components).containsExactly(root, mouse); assertThat(level.dependencies).isEmpty(); }