Skip to content

anyOf and allOf variants for multiple ThrowingConsumer parameters #2764

@onacit

Description

@onacit

Feature summary

I need to assert with satisfiesAnyOf for each element in an iterable.

This may be a collection version of #1304 .

List<Some> some = getSome();

// Now each some.other should be asserted by any of multiple conditions.

some.stream.map(Some::getOther).forEach(o -> {
    assertThat(o).satisfiesAnyOf(
        o1 -> assertThat(o1).isNull(),
        o1 -> assertThat(o1).isNotNull().extracting(Other::getId).isEqualTo(x);     
    );
});

assertThat(some)
    .extracting(Some::getOther)
    .allSatisfy(o -> {
        assertThat(o).satisfiesAnyOf(
            o1 -> assertThat(o1).isNull(),
            o1 -> assertThat(o1).isNotNull().extracting(Other::getId).isEqualTo(x);     
        );
    });

Example

List<Some> some = getSome();
assertThat(some)
    .isNotEmpty()
    .extracting(Some::getOther)
    .allSatisfyAnyOf( // or eachSatisfiesAnyOf
        o -> {},
        o -> {}
    );        

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions