@Test
  public void replacesTaskWithName() {
    final Map<String, ?> options = GUtil.map(Task.TASK_NAME, "task");
    final Task task = task("task");

    context.checking(
        new Expectations() {
          {
            one(taskFactory).createTask(project, options);
            will(returnValue(task));
          }
        });
    assertThat(container.replace("task"), sameInstance(task));
    assertThat(container.getByName("task"), sameInstance(task));
  }
  @Test
  public void addsTaskWithMap() {
    final Map<String, ?> options = GUtil.map("option", "value");
    final Task task = task("task");

    context.checking(
        new Expectations() {
          {
            one(taskFactory).createTask(project, options);
            will(returnValue(task));
          }
        });
    assertThat(container.add(options), sameInstance(task));
    assertThat(container.getByName("task"), sameInstance(task));
  }
  @Test
  public void canGetTaskByPath() {
    Task task = addTask("task");
    expectTaskLookupInOtherProject(":a:b:c", "task", task);

    assertThat(container.getByPath(":a:b:c:task"), sameInstance(task));
  }
  @Test
  public void canFindTaskByAbsolutePath() {
    Task task = task("task");
    expectTaskLookupInOtherProject(":", "task", task);

    assertThat(container.findByPath(":task"), sameInstance(task));
  }
  @Test
  public void canReplaceDuplicateTask() {
    addTask("task");

    final Task newTask = task("task");
    context.checking(
        new Expectations() {
          {
            one(taskFactory).createTask(project, GUtil.map(Task.TASK_NAME, "task"));
            will(returnValue(newTask));
          }
        });

    container.replace("task");
    assertThat(container.getByName("task"), sameInstance(newTask));
  }
 @Test
 public void getByPathFailsForUnknownTask() {
   try {
     container.getByPath("unknown");
     fail();
   } catch (UnknownTaskException e) {
     assertThat(e.getMessage(), equalTo("Task with path 'unknown' not found in <project>."));
   }
 }
  @Test
  public void findByPathReturnsNullForUnknownProject() {
    context.checking(
        new Expectations() {
          {
            allowing(project).findProject(":unknown");
            will(returnValue(null));
          }
        });

    assertThat(container.findByPath(":unknown:task"), nullValue());
  }
 private Task addTask(String name) {
   final Task task = task(name);
   final Map<String, ?> options = GUtil.map(Task.TASK_NAME, name);
   context.checking(
       new Expectations() {
         {
           one(taskFactory).createTask(project, options);
           will(returnValue(task));
         }
       });
   container.add(name);
   return task;
 }
  @Test
  public void cannotAddDuplicateTask() {
    final Task task = addTask("task");

    context.checking(
        new Expectations() {
          {
            one(taskFactory).createTask(project, GUtil.map(Task.TASK_NAME, "task"));
            will(returnValue(task("task")));
          }
        });

    try {
      container.add("task");
      fail();
    } catch (InvalidUserDataException e) {
      assertThat(
          e.getMessage(), equalTo("Cannot add [task2] as a task with that name already exists."));
    }

    assertThat(container.getByName("task"), sameInstance(task));
  }
示例#10
0
  @Test
  public void addsTaskWithNameAndConfigureClosure() {
    final Closure action = HelperUtil.toClosure("{ description = 'description' }");
    final Map<String, ?> options = GUtil.map(Task.TASK_NAME, "task");
    final Task task = task("task");

    context.checking(
        new Expectations() {
          {
            one(taskFactory).createTask(project, options);
            will(returnValue(task));
            one(task).configure(action);
            will(returnValue(task));
          }
        });
    assertThat(container.add("task", action), sameInstance(task));
  }
示例#11
0
 @Test
 public void resolveLocatesTaskByPath() {
   Task task = addTask("task");
   expectTaskLookupInOtherProject(":", "task", task);
   assertThat(container.resolveTask(new StringBuilder(":task")), sameInstance(task));
 }
示例#12
0
  @Test
  public void resolveLocatesTaskByName() {
    Task task = addTask("1");

    assertThat(container.resolveTask(1), sameInstance(task));
  }
示例#13
0
  @Test
  public void canGetTaskByName() {
    Task task = addTask("task");

    assertThat(container.getByPath("task"), sameInstance(task));
  }
示例#14
0
  @Test
  public void findByPathReturnsNullForUnknownTask() {
    expectTaskLookupInOtherProject(":other", "task", null);

    assertThat(container.findByPath(":other:task"), nullValue());
  }