@Test public void failsWhenUnknownTaskNameIsProvided() { final Task task1 = task("t1"); final Task task2 = task("t2"); context.checking( new Expectations() { { one(project).getTasksByName("b3", true); will(returnValue(toSet())); one(taskContainer).getAll(); will(returnValue(toSet(task1, task2))); one(subProjectTaskContainer).getAll(); will(returnValue(toSet())); } }); BuildExecuter executer = new TaskNameResolvingBuildExecuter(toList("b3")); try { executer.select(gradle); fail(); } catch (TaskSelectionException e) { assertThat(e.getMessage(), equalTo("Task 'b3' not found in [project].")); } }
@Test public void failsWhenUnknownTaskPathIsProvided() { context.checking( new Expectations() { { one(project).findProject("a"); will(returnValue(null)); } }); BuildExecuter executer = new TaskNameResolvingBuildExecuter(toList("a:b", "name2")); try { executer.select(gradle); fail(); } catch (TaskSelectionException e) { assertThat(e.getMessage(), equalTo("Project 'a' not found in [project].")); } }
@Test public void createsDescription() { context.checking( new Expectations() { { one(project).getDefaultTasks(); will(returnValue(toList("a", "b"))); Task task = context.mock(Task.class); atLeast(1).of(project).getTasksByName("a", true); will(returnValue(toSet(task))); atLeast(1).of(project).getTasksByName("b", true); will(returnValue(toSet(task))); } }); BuildExecuter executer = new ProjectDefaultsBuildExecuter(); executer.select(project); assertThat(executer.getDisplayName(), equalTo("project default tasks 'a', 'b'")); }
@Test public void failsWhenNoProjectDefaultTasksSpecified() { context.checking( new Expectations() { { one(project).getDefaultTasks(); will(returnValue(toList())); } }); BuildExecuter executer = new ProjectDefaultsBuildExecuter(); try { executer.select(project); fail(); } catch (InvalidUserDataException e) { assertThat( e.getMessage(), equalTo("No tasks have been specified and [project] has not defined any default tasks.")); } }
@Test public void usesProjectDefaultTasksFromProject() { context.checking( new Expectations() { { one(project).getDefaultTasks(); will(returnValue(toList("a", "b"))); Task task = context.mock(Task.class); atLeast(1).of(project).getTasksByName("a", true); will(returnValue(toSet(task))); atLeast(1).of(project).getTasksByName("b", true); will(returnValue(toSet(task))); one(taskExecuter).addTasks(toSet(task)); one(taskExecuter).addTasks(toSet(task)); one(taskExecuter).execute(); } }); BuildExecuter executer = new ProjectDefaultsBuildExecuter(); executer.select(project); executer.execute(taskExecuter); }