/**
   * One test for all for faster execution.
   *
   * @throws Exception
   */
  public void testCanRun() throws Exception {
    // init slave
    LabelAtom slaveLabel = new LabelAtom("slave");
    LabelAtom masterLabel = new LabelAtom("master");

    DumbSlave slave = this.createSlave(slaveLabel);
    SlaveComputer c = slave.getComputer();
    c.connect(false).get(); // wait until it's connected
    if (c.isOffline()) {
      fail("Slave failed to go online: " + c.getLog());
    }

    BuildBlockerQueueTaskDispatcher dispatcher = new BuildBlockerQueueTaskDispatcher();

    String blockingJobName = "blockingJob";

    Shell shell = new Shell("sleep 1");

    Future<FreeStyleBuild> future1 = createBlockingProject("xxx", shell, masterLabel);
    Future<FreeStyleBuild> future2 = createBlockingProject(blockingJobName, shell, masterLabel);
    Future<FreeStyleBuild> future3 = createBlockingProject("yyy", shell, slaveLabel);
    // add project to slave
    FreeStyleProject project = this.createFreeStyleProject();
    project.setAssignedLabel(slaveLabel);

    Queue.BuildableItem item =
        new Queue.BuildableItem(
            new Queue.WaitingItem(Calendar.getInstance(), project, new ArrayList<Action>()));

    CauseOfBlockage causeOfBlockage = dispatcher.canRun(item);

    assertNull(causeOfBlockage);

    BuildBlockerProperty property = new BuildBlockerProperty();

    property.setBlockingJobs(".*ocki.*");

    project.addProperty(property);

    causeOfBlockage = dispatcher.canRun(item);
    assertNotNull(causeOfBlockage);

    assertEquals(
        "Blocking job " + blockingJobName + " is running.", causeOfBlockage.getShortDescription());

    while (!(future1.isDone() && future2.isDone() && future3.isDone())) {
      // wait until jobs are done.
    }
  }
 @Override
 public CauseOfBlockage canTake(Task task) {
   return CauseOfBlockage.fromMessage(null);
 }