### Question:
Tasks { public static ProcessBuilder newProcess(String name) { return new ProcessBuilder(name); }  static ProcessBuilder newProcess(String name);  }### Answer:
@Test void ensureProcessBuilderWithSimpleTaskProducesCorrectGraph() { val task = new T("a"); val process = Tasks.newProcess("a").withContext(context).register(task).create(); val graph = scheduler.apply(process.getExecutionGraph()); assertEquals(graph.size(), 1); val t = graph.get(0).getTasks().get(0); assertNotNull(t, "task must not be null"); }
@Test void ensureFailingProcessConfigurationWorks() { val process = Tasks.newProcess("kernel:start:filesystem") .withContext(context) .register(new KernelModuleListReadPhase("kernel:lifecycle:module:list")) .register(new KernelFilesystemCreatePhase("kernel:lifecycle:filesystem:create")) .register(new KernelClassLoaderCreationPhase("kernel:lifecycle:classloader")) .task("kernel:lifecycle:module:list") .dependsOn("kernel:lifecycle:filesystem:create") .task("kernel:lifecycle:classloader") .dependsOn("kernel:lifecycle:module:list") .create(); val s = scheduler.apply(process.getExecutionGraph()); assertEquals(s.size(), 3, "must have 3 items"); }
@Test void ensureWithContextDoesntChangeExecutionGraph() { val taskA = new T("a"); val taskB = new T("b"); val taskC = new T("c"); val proc = Tasks.newProcess("s") .withContext(context) .register(taskA) .register(taskB) .register(taskC) .task("a") .dependsOn("b") .task("b") .dependsOn("c") .create(); val s = scheduler.apply(proc.getExecutionGraph()); assertEquals(s.size(), 3); assertEquals(s.get(0).getTasks().get(0).getValue().name, "c"); assertEquals(s.get(1).getTasks().get(0).getValue().name, "b"); assertEquals(s.get(2).getTasks().get(0).getValue().name, "a"); }
@Test void ensureSimpleLinearDependenciesWork() { val taskA = new T("a"); val taskB = new T("b"); val taskC = new T("c"); val proc = Tasks.newProcess("s") .register(taskA) .register(taskB) .register(taskC) .task("a") .dependsOn("b") .task("b") .dependsOn("c") .create(); val s = scheduler.apply(proc.getExecutionGraph()); assertEquals(s.size(), 3); assertEquals((s.get(0).getTasks().get(0).getValue()).name, "c"); assertEquals((s.get(1).getTasks().get(0).getValue()).name, "b"); assertEquals((s.get(2).getTasks().get(0).getValue()).name, "a"); }