@Test
  public void testTasks() throws Exception {
    assertThat(person.listTasks().get().size).isEqualTo(0);

    CTask task = new CTask("test", DateTime.now(), true);
    person.add(task).get();
    assertThat(person.listTasks().get().size).isEqualTo(1);

    task.complete().get();
    assertThat(task.status).isEqualTo(TaskStatus.COMPLETED);
    assertThat(person.listTasks().get().size).isEqualTo(0);
    assertThat(person.listTasks(TaskStatus.COMPLETED).get().size).isEqualTo(1);

    task.reopen().get();
    assertThat(task.status).isEqualTo(TaskStatus.OPEN);
    assertThat(person.listTasks().get().size).isEqualTo(1);

    task.delete().get();
    assertThat(person.listTasks().get().size).isEqualTo(0);
  }
Example #2
0
  /**
   * Action to do when this agent reaches the target of current task.
   *
   * <p>This method is called when this agent goes to state <em>TARGET_REACHED</em>. If current task
   * is <tt> TASK_GIVE_MEDICPAKS</tt>, agent must give medic packs, but in other case, it calls to
   * parent's method.
   *
   * <p><em> It's very useful to overload this method. </em>
   *
   * @param _CurrentTask
   */
  protected void PerformTargetReached(CTask _CurrentTask) {

    switch (_CurrentTask.getType()) {
      case CTask.TASK_NONE:
        break;

      case CTask.TASK_GIVE_MEDICPAKS:
        int iPacks = _CurrentTask.getPacksDelivered();
        super.PerformTargetReached(_CurrentTask);
        if (iPacks != _CurrentTask.getPacksDelivered())
          System.out.println(
              getLocalName()
                  + ": Medic has left "
                  + (_CurrentTask.getPacksDelivered() - iPacks)
                  + " Medic Packs");
        else System.out.println(getLocalName() + ": Medic cannot leave Medic Packs");
        break;

      default:
        super.PerformTargetReached(_CurrentTask);
        break;
    }
  }