@Test
public void testTriggerInstanceEndTime() throws Exception {

  final List<DependencyInstance> dependencyInstanceList = new ArrayList<>();
  Date expectedEndTime = getDate(3, 2, 3);
  dependencyInstanceList
      .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE, getDate(2, 2,
          2), getDate(3, 2, 3)));
  dependencyInstanceList
      .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE, getDate(2, 2,
          2), getDate(2, 2, 3)));
  TriggerInstance ti = null;
  ti = new TriggerInstance("1", null, "1", 1,
      "test", dependencyInstanceList, -1, null);
  assertThat(ti.getEndTime()).isEqualTo(expectedEndTime.getTime());
  dependencyInstanceList.clear();
  dependencyInstanceList
      .add(createTestDependencyInstance(Status.RUNNING, CancellationCause.NONE, getDate(2, 2,
          2), null));
  ti = new TriggerInstance("1", null, "1", 1,
      "test", dependencyInstanceList, -1, null);
  assertThat(ti.getEndTime()).isEqualTo(0);
  dependencyInstanceList.clear();
  expectedEndTime = getDate(3, 2, 3);
  dependencyInstanceList
      .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE, getDate(2, 2,
          3), null));
  dependencyInstanceList
      .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE, getDate(3, 2,
          2), null));
  dependencyInstanceList
      .add(createTestDependencyInstance(Status.SUCCEEDED, CancellationCause.NONE, getDate(2, 2,
          2), expectedEndTime));
  ti = new TriggerInstance("1", null, "1", 1,
      "test", dependencyInstanceList, -1, null);
  assertThat(ti.getEndTime()).isEqualTo(expectedEndTime.getTime());
  dependencyInstanceList.clear();
  ti = new TriggerInstance("1", null, "1", 1,
      "test", dependencyInstanceList, -1, null);
  assertThat(ti.getEndTime()).isEqualTo(0);
  dependencyInstanceList.clear();
}