@Test
public void testStatusFromTaskEntities() throws Exception {

  // Pending stage
  Collection<HostRoleCommandEntity> tasks =
      getTaskEntities(HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING, HostRoleStatus.PENDING);
  CalculatedStatus status = CalculatedStatus.statusFromTaskEntities(tasks, false);
  assertEquals(HostRoleStatus.PENDING, status.getStatus());
  assertEquals(0.0, status.getPercent(), 0.1);
  // failed stage
  tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.FAILED, HostRoleStatus.ABORTED,
      HostRoleStatus.ABORTED, HostRoleStatus.ABORTED);
  status = CalculatedStatus.statusFromTaskEntities(tasks, false);
  assertEquals(HostRoleStatus.FAILED, status.getStatus());
  assertEquals(100.0, status.getPercent(), 0.1);
  // failed skippable stage
  tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.FAILED, HostRoleStatus.FAILED,
      HostRoleStatus.FAILED, HostRoleStatus.FAILED);
  status = CalculatedStatus.statusFromTaskEntities(tasks, true);
  assertEquals(HostRoleStatus.COMPLETED, status.getStatus());
  assertEquals(100.0, status.getPercent(), 0.1);
  // timed out stage
  tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.TIMEDOUT,
      HostRoleStatus.TIMEDOUT, HostRoleStatus.TIMEDOUT, HostRoleStatus.TIMEDOUT);
  status = CalculatedStatus.statusFromTaskEntities(tasks, false);
  assertEquals(HostRoleStatus.TIMEDOUT, status.getStatus());
  assertEquals(100.0, status.getPercent(), 0.1);
  // timed out skippable stage
  tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.TIMEDOUT,
      HostRoleStatus.FAILED, HostRoleStatus.TIMEDOUT, HostRoleStatus.TIMEDOUT);
  status = CalculatedStatus.statusFromTaskEntities(tasks, true);
  assertEquals(HostRoleStatus.COMPLETED, status.getStatus());
  assertEquals(100.0, status.getPercent(), 0.1);
  // aborted stage
  tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.ABORTED, HostRoleStatus.ABORTED,
      HostRoleStatus.ABORTED, HostRoleStatus.ABORTED);
  status = CalculatedStatus.statusFromTaskEntities(tasks, false);
  assertEquals(HostRoleStatus.ABORTED, status.getStatus());
  assertEquals(100.0, status.getPercent(), 0.1);
  // aborted skippable stage (same as non-skippable)
  tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.ABORTED, HostRoleStatus.ABORTED,
      HostRoleStatus.ABORTED, HostRoleStatus.ABORTED);
  status = CalculatedStatus.statusFromTaskEntities(tasks, true);
  assertEquals(HostRoleStatus.ABORTED, status.getStatus());
  assertEquals(100.0, status.getPercent(), 0.1);
  // in progress stage
  tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.PENDING,
      HostRoleStatus.PENDING, HostRoleStatus.PENDING);
  status = CalculatedStatus.statusFromTaskEntities(tasks, false);
  assertEquals(HostRoleStatus.IN_PROGRESS, status.getStatus());
  assertEquals(40.0, status.getPercent(), 0.1);
  // completed stage
  tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED,
      HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED);
  status = CalculatedStatus.statusFromTaskEntities(tasks, false);
  assertEquals(HostRoleStatus.COMPLETED, status.getStatus());
  assertEquals(100.0, status.getPercent(), 0.1);
  // holding stage
  tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.HOLDING,
      HostRoleStatus.PENDING, HostRoleStatus.PENDING);
  status = CalculatedStatus.statusFromTaskEntities(tasks, false);
  assertEquals(HostRoleStatus.HOLDING, status.getStatus());
  assertEquals(54.0, status.getPercent(), 0.1);
  // holding failed stage
  tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.HOLDING_FAILED,
      HostRoleStatus.PENDING, HostRoleStatus.PENDING);
  status = CalculatedStatus.statusFromTaskEntities(tasks, false);
  assertEquals(HostRoleStatus.HOLDING_FAILED, status.getStatus());
  assertEquals(54.0, status.getPercent(), 0.1);
  // holding timed out stage
  tasks = getTaskEntities(HostRoleStatus.COMPLETED, HostRoleStatus.COMPLETED, HostRoleStatus.HOLDING_TIMEDOUT,
      HostRoleStatus.PENDING, HostRoleStatus.PENDING);
  status = CalculatedStatus.statusFromTaskEntities(tasks, false);
  assertEquals(HostRoleStatus.HOLDING_TIMEDOUT, status.getStatus());
  assertEquals(54.0, status.getPercent(), 0.1);
}