Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
  @Test
  public void addsTaskWithNameAndType() {
    final Map<String, ?> options = GUtil.map(Task.TASK_NAME, "task", Task.TASK_TYPE, Task.class);
    final Task task = task("task");

    context.checking(
        new Expectations() {
          {
            one(taskFactory).createTask(project, options);
            will(returnValue(task));
          }
        });
    assertThat(container.add("task", Task.class), sameInstance(task));
  }
Exemplo n.º 3
0
  @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));
  }
Exemplo n.º 4
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));
  }
Exemplo n.º 5
0
  @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));
  }