public Result waitForConditionAndFinish(Config config, Supplier<Boolean> conditionCheck)
      throws IOException {
    return waitForConditionsAndFinish(config, conditionCheck);
  }
@Test
  public void testFinishAfterCondition() throws IOException {
    // Arrange
    AtomicInteger callCount = new AtomicInteger();
    int totalCalls = 3;
    Supplier<Boolean> checker = () -> callCount.incrementAndGet() >= totalCalls;

    when(client.getJobStatus(any(), any(), any()))
        .thenReturn(JobState.RUNNING)
        .thenThrow(new IOException())
        .thenReturn(JobState.RUNNING)
        .thenReturn(JobState.CANCELLING)
        .thenReturn(JobState.CANCELLED);

    // Act
    Result result = new PipelineOperator(client).waitForConditionAndFinish(DEFAULT_CONFIG, checker);

    // Assert
    verify(client, atLeast(totalCalls))
        .getJobStatus(projectCaptor.capture(), regionCaptor.capture(), jobIdCaptor.capture());
    verify(client).drainJob(projectCaptor.capture(), regionCaptor.capture(), jobIdCaptor.capture());

    Set<String> allProjects = new HashSet<>(projectCaptor.getAllValues());
    Set<String> allRegions = new HashSet<>(regionCaptor.getAllValues());
    Set<String> allJobIds = new HashSet<>(jobIdCaptor.getAllValues());

    assertThat(allProjects).containsExactly(PROJECT);
    assertThat(allRegions).containsExactly(REGION);
    assertThat(allJobIds).containsExactly(JOB_ID);
    assertThat(result).isEqualTo(Result.CONDITION_MET);
  }