### Question:
TopLevelNameSpaceMapperCalculator implements NameSpaceMapperCalculator { @Override public List<NameSpaceMapping> computeNameSpaceMapping(Collection<? extends Element> elements) { List<Tuple<String, String>> canonicalTypes = typesWithPackageNames(elements); LOG.fine(() -> "calculating namespaces for: " + canonicalTypes); Set<String> topPackages = NameSpaceHelper.topPackages( canonicalTypes.stream().map(Tuple::getFirst).collect(Collectors.toList()) ); LOG.finest(() -> "top Packages are: " + topPackages); Map<String,Set<String>> topPackagesWitchTypes = canonicalTypes.stream() .filter( x -> topPackages.contains(x.getFirst())) .collect(Collectors.groupingBy( Tuple::getFirst, Collectors.mapping(Tuple::getSecond, Collectors.toSet()))); Map<String,Integer> typesCount = new HashMap<>(); for (Set<String> x : topPackagesWitchTypes.values()) for (String y : x) { final int oldCount = typesCount.get(y) == null ? 0 : typesCount.get(y); typesCount.put(y, oldCount + 1); } LOG.finest( () -> "Types Count: " + typesCount); if (typesCount.values().stream().anyMatch(x -> x >1)) { LOG.info(() -> "Same names in top packages"); return new ArrayList<>(); } List<NameSpaceMapping> computedNamesSpaces = topPackages.stream().map( x -> NameSpaceMappingBuilder.of(x,"")).collect(Collectors.toList()); LOG.fine( () -> "Default NameSpace mapping is " + computedNamesSpaces); return computedNamesSpaces; }  @Override List<NameSpaceMapping> computeNameSpaceMapping(Collection<? extends Element> elements);  }### Answer:
@Test void testOnePackage() { assertEquals( Collections.singletonList(NameSpaceMappingBuilder.of("a.b", "")), new TopLevelNameSpaceMapperCalculator().computeNameSpaceMapping(createDataSet("a.b.X", "a.b.Y")) ); }
@Test void testTwoPackageClashing_NoMapping() { assertEquals( new ArrayList<>(), new TopLevelNameSpaceMapperCalculator().computeNameSpaceMapping(createDataSet("a.b.X", "a.c.X")) ); }
@Test void testTwoPackage() { assertEquals( Lists.newArrayList( NameSpaceMappingBuilder.of("a.b",""), NameSpaceMappingBuilder.of("a.c","") ), new TopLevelNameSpaceMapperCalculator().computeNameSpaceMapping(createDataSet("a.b.X", "a.c.Y", "a.c.Z")) ); }