diff --git a/pom.xml b/pom.xml index b73b170..5937dbb 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,7 @@ com.tngtech.archunit archunit - 1.4.2 + 1.5.0 test diff --git a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java index 243bde2..4601b04 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java @@ -19,6 +19,7 @@ import static org.assertj.core.error.AnyElementShouldMatch.anyElementShouldMatch; import static org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch; import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfy; +import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfyAny; import static org.assertj.core.error.ShouldBeAnArray.shouldBeAnArray; import static org.assertj.core.error.ShouldBeEmpty.shouldBeEmpty; import static org.assertj.core.error.ShouldBeNullOrEmpty.shouldBeNullOrEmpty; @@ -155,6 +156,32 @@ private void assertAnyMatch(Predicate predicate, PredicateDescr } } + @Override + public SELF anySatisfy(Consumer requirements) { + return executeAssertion(() -> assertAnySatisfy(requirements)); + } + + @Override + public SELF anySatisfy(ThrowingConsumer requirements) { + return executeAssertion(() -> assertAnySatisfy(requirements)); + } + + private void assertAnySatisfy(Consumer requirements) { + isNotNull(); + requireNonNull(requirements, "The Consumer expressing the assertions requirements must not be null"); + + MutableList unsatisfiedRequirements = Lists.mutable.empty(); + for (ELEMENT element : actual) { + Optional result = failsRequirements(requirements, element); + if (result.isEmpty()) { + return; // element satisfied the requirements + } + unsatisfiedRequirements.add(result.get()); + } + + throw assertionError(elementsShouldSatisfyAny(actual, unsatisfiedRequirements, info)); + } + @Override protected void assertContains(ELEMENT[] values) { isNotNull(); diff --git a/src/main/java/org/assertj/eclipse/collections/api/BooleanIterableAssert.java b/src/main/java/org/assertj/eclipse/collections/api/BooleanIterableAssert.java index 54bbe3f..0bab85f 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/BooleanIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/BooleanIterableAssert.java @@ -19,6 +19,7 @@ import static org.assertj.core.error.AnyElementShouldMatch.anyElementShouldMatch; import static org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch; import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfy; +import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfyAny; import static org.assertj.core.error.ShouldContain.shouldContain; import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; import static org.assertj.core.error.ShouldNotContain.shouldNotContain; @@ -31,7 +32,9 @@ import org.eclipse.collections.api.RichIterable; import org.eclipse.collections.api.block.predicate.primitive.BooleanPredicate; import org.eclipse.collections.api.block.procedure.primitive.BooleanProcedure; +import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.primitive.BooleanLists; +import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.list.primitive.BooleanList; import org.eclipse.collections.api.list.primitive.ImmutableBooleanList; @@ -102,6 +105,26 @@ private void assertAnyMatch(BooleanPredicate predicate, PredicateDescription pre } } + public BooleanIterableAssert anySatisfy(BooleanProcedure requirements) { + return executeAssertion(() -> assertAnySatisfy(requirements)); + } + + private void assertAnySatisfy(BooleanProcedure requirements) { + isNotNull(); + requireNonNull(requirements, "The BooleanProcedure expressing the assertions requirements must not be null"); + + MutableList unsatisfiedRequirements = Lists.mutable.empty(); + if (actual.anySatisfy(element -> { + Optional result = failsRequirements(requirements, element); + result.ifPresent(unsatisfiedRequirements::add); + return result.isEmpty(); + })) { + return; + } + + throw assertionError(elementsShouldSatisfyAny(actual, unsatisfiedRequirements, info)); + } + public BooleanIterableAssert contains(boolean... values) { return executeAssertion(() -> { isNotNull(); diff --git a/src/main/java/org/assertj/eclipse/collections/api/ByteIterableAssert.java b/src/main/java/org/assertj/eclipse/collections/api/ByteIterableAssert.java index ce21b33..22cca35 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/ByteIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/ByteIterableAssert.java @@ -19,6 +19,7 @@ import static org.assertj.core.error.AnyElementShouldMatch.anyElementShouldMatch; import static org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch; import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfy; +import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfyAny; import static org.assertj.core.error.ShouldContain.shouldContain; import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; import static org.assertj.core.error.ShouldNotContain.shouldNotContain; @@ -31,7 +32,9 @@ import org.eclipse.collections.api.RichIterable; import org.eclipse.collections.api.block.predicate.primitive.BytePredicate; import org.eclipse.collections.api.block.procedure.primitive.ByteProcedure; +import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.primitive.ByteLists; +import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.list.primitive.ByteList; import org.eclipse.collections.api.list.primitive.ImmutableByteList; @@ -103,6 +106,26 @@ private void assertAnyMatch(BytePredicate predicate, PredicateDescription predic } } + public ByteIterableAssert anySatisfy(ByteProcedure requirements) { + return executeAssertion(() -> assertAnySatisfy(requirements)); + } + + private void assertAnySatisfy(ByteProcedure requirements) { + isNotNull(); + requireNonNull(requirements, "The ByteProcedure expressing the assertions requirements must not be null"); + + MutableList unsatisfiedRequirements = Lists.mutable.empty(); + if (actual.anySatisfy(element -> { + Optional result = failsRequirements(requirements, element); + result.ifPresent(unsatisfiedRequirements::add); + return result.isEmpty(); + })) { + return; + } + + throw assertionError(elementsShouldSatisfyAny(actual, unsatisfiedRequirements, info)); + } + public ByteIterableAssert contains(byte... values) { return executeAssertion(() -> { isNotNull(); diff --git a/src/main/java/org/assertj/eclipse/collections/api/CharIterableAssert.java b/src/main/java/org/assertj/eclipse/collections/api/CharIterableAssert.java index 9d454f9..b1ddcf2 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/CharIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/CharIterableAssert.java @@ -19,6 +19,7 @@ import static org.assertj.core.error.AnyElementShouldMatch.anyElementShouldMatch; import static org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch; import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfy; +import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfyAny; import static org.assertj.core.error.ShouldContain.shouldContain; import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; import static org.assertj.core.error.ShouldNotContain.shouldNotContain; @@ -31,7 +32,9 @@ import org.eclipse.collections.api.RichIterable; import org.eclipse.collections.api.block.predicate.primitive.CharPredicate; import org.eclipse.collections.api.block.procedure.primitive.CharProcedure; +import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.primitive.CharLists; +import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.list.primitive.CharList; import org.eclipse.collections.api.list.primitive.ImmutableCharList; @@ -102,6 +105,26 @@ private void assertAnyMatch(CharPredicate predicate, PredicateDescription predic } } + public CharIterableAssert anySatisfy(CharProcedure requirements) { + return executeAssertion(() -> assertAnySatisfy(requirements)); + } + + private void assertAnySatisfy(CharProcedure requirements) { + isNotNull(); + requireNonNull(requirements, "The CharProcedure expressing the assertions requirements must not be null"); + + MutableList unsatisfiedRequirements = Lists.mutable.empty(); + if (actual.anySatisfy(element -> { + Optional result = failsRequirements(requirements, element); + result.ifPresent(unsatisfiedRequirements::add); + return result.isEmpty(); + })) { + return; + } + + throw assertionError(elementsShouldSatisfyAny(actual, unsatisfiedRequirements, info)); + } + public CharIterableAssert contains(char... values) { return executeAssertion(() -> { isNotNull(); diff --git a/src/main/java/org/assertj/eclipse/collections/api/DoubleIterableAssert.java b/src/main/java/org/assertj/eclipse/collections/api/DoubleIterableAssert.java index 3fdce8a..0bbb4dd 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/DoubleIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/DoubleIterableAssert.java @@ -19,6 +19,7 @@ import static org.assertj.core.error.AnyElementShouldMatch.anyElementShouldMatch; import static org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch; import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfy; +import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfyAny; import static org.assertj.core.error.ShouldContain.shouldContain; import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; import static org.assertj.core.error.ShouldNotContain.shouldNotContain; @@ -31,7 +32,9 @@ import org.assertj.core.presentation.PredicateDescription; import org.eclipse.collections.api.DoubleIterable; import org.eclipse.collections.api.RichIterable; +import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.primitive.DoubleLists; +import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.list.primitive.DoubleList; import org.eclipse.collections.api.list.primitive.ImmutableDoubleList; @@ -102,6 +105,26 @@ private void assertAnyMatch(DoublePredicate predicate, PredicateDescription pred } } + public DoubleIterableAssert anySatisfy(DoubleConsumer requirements) { + return executeAssertion(() -> assertAnySatisfy(requirements)); + } + + private void assertAnySatisfy(DoubleConsumer requirements) { + isNotNull(); + requireNonNull(requirements, "The DoubleConsumer expressing the assertions requirements must not be null"); + + MutableList unsatisfiedRequirements = Lists.mutable.empty(); + if (actual.anySatisfy(element -> { + Optional result = failsRequirements(requirements, element); + result.ifPresent(unsatisfiedRequirements::add); + return result.isEmpty(); + })) { + return; + } + + throw assertionError(elementsShouldSatisfyAny(actual, unsatisfiedRequirements, info)); + } + public DoubleIterableAssert contains(double... values) { return executeAssertion(() -> { isNotNull(); diff --git a/src/main/java/org/assertj/eclipse/collections/api/FloatIterableAssert.java b/src/main/java/org/assertj/eclipse/collections/api/FloatIterableAssert.java index c41d603..52be6b8 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/FloatIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/FloatIterableAssert.java @@ -19,6 +19,7 @@ import static org.assertj.core.error.AnyElementShouldMatch.anyElementShouldMatch; import static org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch; import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfy; +import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfyAny; import static org.assertj.core.error.ShouldContain.shouldContain; import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; import static org.assertj.core.error.ShouldNotContain.shouldNotContain; @@ -31,7 +32,9 @@ import org.eclipse.collections.api.RichIterable; import org.eclipse.collections.api.block.predicate.primitive.FloatPredicate; import org.eclipse.collections.api.block.procedure.primitive.FloatProcedure; +import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.primitive.FloatLists; +import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.list.primitive.FloatList; import org.eclipse.collections.api.list.primitive.ImmutableFloatList; @@ -102,6 +105,26 @@ private void assertAnyMatch(FloatPredicate predicate, PredicateDescription predi } } + public FloatIterableAssert anySatisfy(FloatProcedure requirements) { + return executeAssertion(() -> assertAnySatisfy(requirements)); + } + + private void assertAnySatisfy(FloatProcedure requirements) { + isNotNull(); + requireNonNull(requirements, "The FloatProcedure expressing the assertions requirements must not be null"); + + MutableList unsatisfiedRequirements = Lists.mutable.empty(); + if (actual.anySatisfy(element -> { + Optional result = failsRequirements(requirements, element); + result.ifPresent(unsatisfiedRequirements::add); + return result.isEmpty(); + })) { + return; + } + + throw assertionError(elementsShouldSatisfyAny(actual, unsatisfiedRequirements, info)); + } + public FloatIterableAssert contains(float... values) { return executeAssertion(() -> { isNotNull(); diff --git a/src/main/java/org/assertj/eclipse/collections/api/IntIterableAssert.java b/src/main/java/org/assertj/eclipse/collections/api/IntIterableAssert.java index 8f7be81..f68158d 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/IntIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/IntIterableAssert.java @@ -19,6 +19,7 @@ import static org.assertj.core.error.AnyElementShouldMatch.anyElementShouldMatch; import static org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch; import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfy; +import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfyAny; import static org.assertj.core.error.ShouldContain.shouldContain; import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; import static org.assertj.core.error.ShouldNotContain.shouldNotContain; @@ -31,8 +32,9 @@ import org.assertj.core.presentation.PredicateDescription; import org.eclipse.collections.api.IntIterable; import org.eclipse.collections.api.RichIterable; -import org.eclipse.collections.api.block.predicate.primitive.BooleanPredicate; +import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.primitive.IntLists; +import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.list.primitive.ImmutableIntList; import org.eclipse.collections.api.list.primitive.IntList; @@ -103,6 +105,26 @@ private void assertAnyMatch(IntPredicate predicate, PredicateDescription predica } } + public IntIterableAssert anySatisfy(IntConsumer requirements) { + return executeAssertion(() -> assertAnySatisfy(requirements)); + } + + private void assertAnySatisfy(IntConsumer requirements) { + isNotNull(); + requireNonNull(requirements, "The IntConsumer expressing the assertions requirements must not be null"); + + MutableList unsatisfiedRequirements = Lists.mutable.empty(); + if (actual.anySatisfy(element -> { + Optional result = failsRequirements(requirements, element); + result.ifPresent(unsatisfiedRequirements::add); + return result.isEmpty(); + })) { + return; + } + + throw assertionError(elementsShouldSatisfyAny(actual, unsatisfiedRequirements, info)); + } + public IntIterableAssert contains(int... values) { return executeAssertion(() -> { isNotNull(); diff --git a/src/main/java/org/assertj/eclipse/collections/api/LongIterableAssert.java b/src/main/java/org/assertj/eclipse/collections/api/LongIterableAssert.java index e509960..2c3bd17 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/LongIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/LongIterableAssert.java @@ -19,6 +19,7 @@ import static org.assertj.core.error.AnyElementShouldMatch.anyElementShouldMatch; import static org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch; import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfy; +import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfyAny; import static org.assertj.core.error.ShouldContain.shouldContain; import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; import static org.assertj.core.error.ShouldNotContain.shouldNotContain; @@ -31,7 +32,10 @@ import org.assertj.core.presentation.PredicateDescription; import org.eclipse.collections.api.LongIterable; import org.eclipse.collections.api.RichIterable; +import org.eclipse.collections.api.block.procedure.primitive.BooleanProcedure; +import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.primitive.LongLists; +import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.list.primitive.ImmutableLongList; import org.eclipse.collections.api.list.primitive.LongList; @@ -102,6 +106,26 @@ private void assertAnyMatch(LongPredicate predicate, PredicateDescription predic } } + public LongIterableAssert anySatisfy(LongConsumer requirements) { + return executeAssertion(() -> assertAnySatisfy(requirements)); + } + + private void assertAnySatisfy(LongConsumer requirements) { + isNotNull(); + requireNonNull(requirements, "The LongConsumer expressing the assertions requirements must not be null"); + + MutableList unsatisfiedRequirements = Lists.mutable.empty(); + if (actual.anySatisfy(element -> { + Optional result = failsRequirements(requirements, element); + result.ifPresent(unsatisfiedRequirements::add); + return result.isEmpty(); + })) { + return; + } + + throw assertionError(elementsShouldSatisfyAny(actual, unsatisfiedRequirements, info)); + } + public LongIterableAssert contains(long... values) { return executeAssertion(() -> { isNotNull(); diff --git a/src/main/java/org/assertj/eclipse/collections/api/ShortIterableAssert.java b/src/main/java/org/assertj/eclipse/collections/api/ShortIterableAssert.java index e68161c..8442794 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/ShortIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/ShortIterableAssert.java @@ -19,6 +19,7 @@ import static org.assertj.core.error.AnyElementShouldMatch.anyElementShouldMatch; import static org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch; import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfy; +import static org.assertj.core.error.ElementsShouldSatisfy.elementsShouldSatisfyAny; import static org.assertj.core.error.ShouldContain.shouldContain; import static org.assertj.core.error.ShouldContainAnyOf.shouldContainAnyOf; import static org.assertj.core.error.ShouldNotContain.shouldNotContain; @@ -31,7 +32,9 @@ import org.eclipse.collections.api.ShortIterable; import org.eclipse.collections.api.block.predicate.primitive.ShortPredicate; import org.eclipse.collections.api.block.procedure.primitive.ShortProcedure; +import org.eclipse.collections.api.factory.Lists; import org.eclipse.collections.api.factory.primitive.ShortLists; +import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.list.primitive.ImmutableShortList; import org.eclipse.collections.api.list.primitive.ShortList; @@ -102,6 +105,26 @@ private void assertAnyMatch(ShortPredicate predicate, PredicateDescription predi } } + public ShortIterableAssert anySatisfy(ShortProcedure requirements) { + return executeAssertion(() -> assertAnySatisfy(requirements)); + } + + private void assertAnySatisfy(ShortProcedure requirements) { + isNotNull(); + requireNonNull(requirements, "The ShortProcedure expressing the assertions requirements must not be null"); + + MutableList unsatisfiedRequirements = Lists.mutable.empty(); + if (actual.anySatisfy(element -> { + Optional result = failsRequirements(requirements, element); + result.ifPresent(unsatisfiedRequirements::add); + return result.isEmpty(); + })) { + return; + } + + throw assertionError(elementsShouldSatisfyAny(actual, unsatisfiedRequirements, info)); + } + public ShortIterableAssert contains(short... values) { return executeAssertion(() -> { isNotNull(); diff --git a/src/test/java/org/assertj/eclipse/collections/api/primitive/PrimitiveIterableAssert_AnySatisfy_Test.java b/src/test/java/org/assertj/eclipse/collections/api/primitive/PrimitiveIterableAssert_AnySatisfy_Test.java new file mode 100644 index 0000000..38c464c --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/primitive/PrimitiveIterableAssert_AnySatisfy_Test.java @@ -0,0 +1,259 @@ +/* + * Copyright 2025-2026 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.assertj.eclipse.collections.api.primitive; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; + +import org.assertj.eclipse.collections.api.BooleanIterableAssert; +import org.assertj.eclipse.collections.api.ByteIterableAssert; +import org.assertj.eclipse.collections.api.CharIterableAssert; +import org.assertj.eclipse.collections.api.DoubleIterableAssert; +import org.assertj.eclipse.collections.api.FloatIterableAssert; +import org.assertj.eclipse.collections.api.IntIterableAssert; +import org.assertj.eclipse.collections.api.LongIterableAssert; +import org.assertj.eclipse.collections.api.ShortIterableAssert; +import org.assertj.eclipse.collections.api.SoftAssertions; +import org.junit.jupiter.api.Nested; + +class PrimitiveIterableAssert_AnySatisfy_Test { + + @Nested + class BooleanTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BOOLEAN) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(true, false, true).anySatisfy(value -> assertThat(value).isTrue())); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BOOLEAN) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anySatisfy(value -> assertThat(value).isTrue())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BOOLEAN) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(false, false, false).anySatisfy(value -> assertThat(value).isTrue())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BOOLEAN) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anySatisfy(value -> { + })); + } + } + + @Nested + class ByteTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BYTE) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements((byte) 2, (byte) 3, (byte) 4).anySatisfy(value -> assertThat(value).isEven())); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BYTE) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anySatisfy(value -> assertThat(value).isEven())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BYTE) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements((byte) 1, (byte) 3, (byte) 5).anySatisfy(value -> assertThat(value).isEven())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BYTE) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anySatisfy(value -> assertThat(value).isGreaterThanOrEqualTo((byte) 0))); + } + } + + @Nested + class CharTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.CHAR) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements('a', 'Z', 'c').anySatisfy(value -> assertThat(value).isLowerCase())); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.CHAR) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anySatisfy(value -> assertThat(value).isLowerCase())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.CHAR) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements('A', 'Y', 'Z').anySatisfy(value -> assertThat(value).isLowerCase())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.CHAR) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anySatisfy(value -> assertThat(value).isGreaterThanOrEqualTo((char) 0))); + } + } + + @Nested + class DoubleTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.DOUBLE) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(2.0, -1.0, 4.0).anySatisfy(value -> assertThat(value).isPositive())); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.DOUBLE) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anySatisfy(value -> assertThat(value).isPositive())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.DOUBLE) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(-2.0, -1.0, -4.0).anySatisfy(value -> assertThat(value).isPositive())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.DOUBLE) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anySatisfy(value -> assertThat(value).isGreaterThanOrEqualTo(0.0))); + } + } + + @Nested + class FloatTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.FLOAT) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(2.0f, -1.0f, 4.0f).anySatisfy(value -> assertThat(value).isPositive())); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.FLOAT) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anySatisfy(value -> assertThat(value).isPositive())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.FLOAT) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(-2.0f, -1.0f, -4.0f).anySatisfy(value -> assertThat(value).isPositive())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.FLOAT) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anySatisfy(value -> assertThat(value).isGreaterThanOrEqualTo(0.0f))); + } + } + + @Nested + class IntTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.INT) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(2, 3, 4).anySatisfy(value -> assertThat(value).isEven())); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.INT) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anySatisfy(value -> assertThat(value).isEven())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.INT) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(1, 3, 5).anySatisfy(value -> assertThat(value).isEven())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.INT) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anySatisfy(value -> assertThat(value).isGreaterThanOrEqualTo(0))); + } + } + + @Nested + class LongTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.LONG) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(2L, 3L, 4L).anySatisfy(value -> assertThat(value).isEven())); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.LONG) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anySatisfy(value -> assertThat(value).isEven())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.LONG) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(1L, 3L, 5L).anySatisfy(value -> assertThat(value).isEven())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.LONG) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anySatisfy(value -> assertThat(value).isGreaterThanOrEqualTo(0L))); + } + } + + @Nested + class ShortTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.SHORT) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements((short) 2, (short) 3, (short) 4).anySatisfy(value -> assertThat(value).isEven())); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.SHORT) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anySatisfy(value -> assertThat(value).isEven())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.SHORT) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements((short) 1, (short) 3, (short) 5).anySatisfy(value -> assertThat(value).isEven())) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.SHORT) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anySatisfy(value -> assertThat(value).isGreaterThanOrEqualTo((short) 0))); + } + } +} diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_AnySatisfy_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_AnySatisfy_Test.java new file mode 100644 index 0000000..8fe3859 --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_AnySatisfy_Test.java @@ -0,0 +1,73 @@ +/* + * Copyright 2025-2026 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.assertj.eclipse.collections.api.richiterable; + +import java.util.function.Consumer; + +import org.assertj.core.api.ThrowingConsumer; +import org.assertj.eclipse.collections.api.SoftAssertions; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; + +class AbstractRichIterableAssert_AnySatisfy_Test { + @RichIterableParameterizedTest + void passes(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").anySatisfy((Consumer) s -> + assertThat(s).contains("9"))); + } + + @RichIterableParameterizedTest + void failsEmpty(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anySatisfy((Consumer) s -> + assertThat(s).hasSize(3))) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @RichIterableParameterizedTest + void fails(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").anySatisfy((Consumer) s -> + assertThat(s).hasSize(4))) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @SuppressWarnings("RedundantCast") + @RichIterableParameterizedTest + void passesThrowingConsumer(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").anySatisfy((ThrowingConsumer) s -> + assertThat(s).contains("9"))); + } + + @SuppressWarnings("RedundantCast") + @RichIterableParameterizedTest + void failsThrowingConsumer(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").anySatisfy((ThrowingConsumer) s -> + assertThat(s).hasSize(4))) + .withMessageContaining("to satisfy the given assertions requirements but none did"); + } + + @RichIterableParameterizedTest + void softAssertionPasses(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly, "TOS", "TNG", "DS9", "VOY", "ENT").anySatisfy((Consumer) s -> + assertThat(s).contains("9"))); + } +}