private static Map<String, Set<Dependency>> checkOptionalFlags(
            Map<String, Set<Dependency>> bundledDependenciesByModule,
            Map<String, DependencyTree> dependenciesByModule) {

        final Map<String, Set<Dependency>> allViolations = new HashMap<>();

        for (String module : bundledDependenciesByModule.keySet()) {
            LOG.debug("Checking module '{}'.", module);
            if (!dependenciesByModule.containsKey(module)) {
                throw new IllegalStateException(
                        String.format(
                                "Module %s listed by shade-plugin, but not dependency-plugin.",
                                module));
            }

            final Collection<Dependency> bundledDependencies =
                    bundledDependenciesByModule.get(module);
            final DependencyTree dependencyTree = dependenciesByModule.get(module);

            final Set<Dependency> violations =
                    checkOptionalFlags(module, bundledDependencies, dependencyTree);

            if (violations.isEmpty()) {
                LOG.info("OK: {}", module);
            } else {
                allViolations.put(module, violations);
            }
        }

        return allViolations;
    }
@Test
    void testDirectBundledDependencyMustBeOptional() {
        final Dependency dependency = createMandatoryDependency("a");
        final Set<Dependency> bundled = Collections.singleton(dependency);
        final DependencyTree dependencyTree = new DependencyTree().addDirectDependency(dependency);

        final Set<Dependency> violations =
                ShadeOptionalChecker.checkOptionalFlags(MODULE, bundled, dependencyTree);

        assertThat(violations).containsExactly(dependency);
    }