diff options
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/tasks/ListTasksTask.java | 25 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/tasks/ListTasksTaskTest.java | 44 |
2 files changed, 60 insertions, 9 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/tasks/ListTasksTask.java b/sonar-batch/src/main/java/org/sonar/batch/tasks/ListTasksTask.java index 26146c17dce..dd08729b2cf 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/tasks/ListTasksTask.java +++ b/sonar-batch/src/main/java/org/sonar/batch/tasks/ListTasksTask.java @@ -27,10 +27,10 @@ public class ListTasksTask implements Task { public static final String COMMAND = "list-tasks"; public static final TaskDefinition DEFINITION = TaskDefinition.create() - .setDescription("List available tasks") - .setName("List Tasks") - .setCommand(COMMAND) - .setTask(ListTasksTask.class); + .setDescription("List available tasks") + .setName("List Tasks") + .setCommand(COMMAND) + .setTask(ListTasksTask.class); private final Tasks taskManager; @@ -39,13 +39,20 @@ public class ListTasksTask implements Task { } public void execute() { - System.out.println(); - System.out.println("Available tasks:"); - System.out.println(); + logBlankLine(); + log("Available tasks:"); + logBlankLine(); for (TaskDefinition taskDef : taskManager.getTaskDefinitions()) { - System.out.println(" - " + taskDef.getCommand() + ": " + taskDef.getDescription()); + log(" - " + taskDef.getCommand() + ": " + taskDef.getDescription()); } - System.out.println(); + logBlankLine(); } + void log(String s) { + System.out.println(s); + } + + void logBlankLine() { + System.out.println(); + } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/tasks/ListTasksTaskTest.java b/sonar-batch/src/test/java/org/sonar/batch/tasks/ListTasksTaskTest.java new file mode 100644 index 00000000000..d66c0c688ed --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/tasks/ListTasksTaskTest.java @@ -0,0 +1,44 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.batch.tasks; + +import org.junit.Test; +import org.sonar.api.task.TaskDefinition; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class ListTasksTaskTest { + @Test + public void should_list_available_tasks() { + TaskDefinition def = TaskDefinition.create().setCommand("purge").setName("Purge").setDescription("Purge database"); + Tasks tasks = mock(Tasks.class); + when(tasks.getTaskDefinitions()).thenReturn(new TaskDefinition[]{def}); + ListTasksTask task = spy(new ListTasksTask(tasks)); + + task.execute(); + + verify(task, times(1)).log("Available tasks:"); + verify(task, times(1)).log(" - purge: Purge database"); + } +} |