GraphBuilder { static Collection<Graph> buildGraphs(Map<String, Module> modules) throws ProcessorException { LinkedList<Graph> graphs = new LinkedList<>(); for (Module module : modules.values()) { if (module.isCompleted) { Graph graph = buildGraph(modules, module); validateGraph(graph); graphs.add(graph); } } return graphs; }    }
@Test public void graphBuilder_nonCompletedInput_emptyGraph() { try { Collection<Graph> graphs = GraphBuilder.buildGraphs(Collections.<String, Module>emptyMap()); assertTrue(graphs.isEmpty()); } catch (ProcessorException e) { fail(); } }
@Test public void graphBuilder_emptyModule_graph() throws ProcessorException { Module module = getFakeModule("ModuleName", null, null, true); Collection<Graph> graphs = GraphBuilder.buildGraphs(singletonMap(module.canonicalModuleName, module)); assertEquals(graphs.size(), 1); }
@Test public void graphBuilder_repeatInclude_throwError() { try { String moduleName = "ModuleName"; String includeModuleName = "IncludeModule"; Include include = getFakeInclude(includeModuleName); Module includeModule = getFakeModule(includeModuleName, null, null, false); Module fakeModule = getFakeModule(moduleName, null, Arrays.asList(include, include), true); Map<String, Module> modules = new HashMap<>(); modules.put(fakeModule.canonicalModuleName, fakeModule); modules.put(includeModule.canonicalModuleName, includeModule); GraphBuilder.buildGraphs(modules); fail(); } catch (ProcessorException ignored) { } }
@Test public void graphBuilder_repeatProvide_throwError() { try { String moduleName = "ModuleName"; String includeModuleName = "IncludeModule"; Collection<Provide> repeatProvide = singleton(getFakeProvide("P", "n", null)); Module includeModule = getFakeModule(includeModuleName, repeatProvide, null, false); Collection<Include> includes = singleton(getFakeInclude(includeModuleName)); Module fakeModule = getFakeModule(moduleName, repeatProvide, includes, true); Map<String, Module> modules = new HashMap<>(); modules.put(fakeModule.canonicalModuleName, fakeModule); modules.put(includeModule.canonicalModuleName, includeModule); GraphBuilder.buildGraphs(modules); fail(); } catch (ProcessorException ignored) { } }
@Test public void graphBuilder_unknownDependency_throwError() { try { String moduleName = "ModuleName"; Collection<Provide> provides = singleton(getFakeProvide("P", "n", singleton(new Dependency("Unknown", "?")))); Module fakeModule = getFakeModule(moduleName, provides, null, true); GraphBuilder.buildGraphs(singletonMap(moduleName, fakeModule)); fail(); } catch (ProcessorException ignored) { } }
@Test public void graphBuilder_cycleDependency_throwError() { try { String moduleName = "ModuleName"; List<Provide> provides = Arrays.asList( getFakeProvide("P1", "", singleton(new Dependency("P2", ""))), getFakeProvide("P2", "", singleton(new Dependency("P3", ""))), getFakeProvide("P3", "", singleton(new Dependency("P1", "")))); Module fakeModule = getFakeModule(moduleName, provides, null, true); GraphBuilder.buildGraphs(singletonMap(moduleName, fakeModule)); fail(); } catch (ProcessorException ignored) { } }