Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add onFailure sugar method #283

@NathanEckert

Description

@NathanEckert

I am looking to do the following assertion:

    final ThreadTestEnv env = new ThreadTestEnv();
    ...
    await()
        .atMost(10, TimeUnit.SECONDS)
        .onFailure(env::printErrors)
        .untilAsserted(() -> {
          final Set<Object> values = runQuery();
          assertThat(values).containsExactlyInAnyOrder("notThere");
        });

With the onFailure code evaluating a single time when reaching the assertion timeout.

It possible to do so, but not with the fluent API: #258 (comment)

The workaround being:

    await()
        .atMost(10, TimeUnit.SECONDS)
        .conditionEvaluationListener(new ConditionEvaluationListener<>() {
          @Override
          public void onTimeout(TimeoutEvent timeoutEvent) {
            env.printErrors();
          }

          @Override
          public void conditionEvaluated(EvaluatedCondition<Object> condition) {

          }
        })
        .untilAsserted(() -> {
          final Set<Object> values = runQuery();
          assertThat(values).containsExactlyInAnyOrder("notThere");
        });

It is a feature that as almost been asked twice, but with some workaround:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions