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 0ffd2a7..243bde2 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java @@ -16,6 +16,7 @@ package org.assertj.eclipse.collections.api; import static java.util.Objects.requireNonNull; +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.ShouldBeAnArray.shouldBeAnArray; @@ -136,6 +137,24 @@ private static Optional failsRequirements(Consumer predicate) { + return executeAssertion(() -> assertAnyMatch(predicate, PredicateDescription.GIVEN)); + } + + @Override + public SELF anyMatch(Predicate predicate, String predicateDescription) { + return executeAssertion(() -> assertAnyMatch(predicate, new PredicateDescription(predicateDescription))); + } + + private void assertAnyMatch(Predicate predicate, PredicateDescription predicateDescription) { + isNotNull(); + requireNonNull(predicate, "The predicate to evaluate should not be null"); + if (actual.noneSatisfy(predicate::test)) { + throw assertionError(anyElementShouldMatch(actual, predicateDescription)); + } + } + @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 2b9d983..54bbe3f 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/BooleanIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/BooleanIterableAssert.java @@ -16,6 +16,7 @@ package org.assertj.eclipse.collections.api; import static java.util.Objects.requireNonNull; +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.ShouldContain.shouldContain; @@ -85,6 +86,22 @@ private static Optional failsRequirements(BooleanProcedu return Optional.empty(); } + public BooleanIterableAssert anyMatch(BooleanPredicate predicate) { + return executeAssertion(() -> assertAnyMatch(predicate, PredicateDescription.GIVEN)); + } + + public BooleanIterableAssert anyMatch(BooleanPredicate predicate, String predicateDescription) { + return executeAssertion(() -> assertAnyMatch(predicate, new PredicateDescription(predicateDescription))); + } + + private void assertAnyMatch(BooleanPredicate predicate, PredicateDescription predicateDescription) { + isNotNull(); + requireNonNull(predicate, "The predicate to evaluate should not be null"); + if (actual.noneSatisfy(predicate)) { + throw assertionError(anyElementShouldMatch(actual, predicateDescription)); + } + } + 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 b8268de..ce21b33 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/ByteIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/ByteIterableAssert.java @@ -16,6 +16,7 @@ package org.assertj.eclipse.collections.api; import static java.util.Objects.requireNonNull; +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.ShouldContain.shouldContain; @@ -86,6 +87,22 @@ private static Optional failsRequirements(ByteProcedure return Optional.empty(); } + public ByteIterableAssert anyMatch(BytePredicate predicate) { + return executeAssertion(() -> assertAnyMatch(predicate, PredicateDescription.GIVEN)); + } + + public ByteIterableAssert anyMatch(BytePredicate predicate, String predicateDescription) { + return executeAssertion(() -> assertAnyMatch(predicate, new PredicateDescription(predicateDescription))); + } + + private void assertAnyMatch(BytePredicate predicate, PredicateDescription predicateDescription) { + isNotNull(); + requireNonNull(predicate, "The predicate to evaluate should not be null"); + if (actual.noneSatisfy(predicate)) { + throw assertionError(anyElementShouldMatch(actual, predicateDescription)); + } + } + 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 1b87603..9d454f9 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/CharIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/CharIterableAssert.java @@ -16,6 +16,7 @@ package org.assertj.eclipse.collections.api; import static java.util.Objects.requireNonNull; +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.ShouldContain.shouldContain; @@ -85,6 +86,22 @@ private static Optional failsRequirements(CharProcedure return Optional.empty(); } + public CharIterableAssert anyMatch(CharPredicate predicate) { + return executeAssertion(() -> assertAnyMatch(predicate, PredicateDescription.GIVEN)); + } + + public CharIterableAssert anyMatch(CharPredicate predicate, String predicateDescription) { + return executeAssertion(() -> assertAnyMatch(predicate, new PredicateDescription(predicateDescription))); + } + + private void assertAnyMatch(CharPredicate predicate, PredicateDescription predicateDescription) { + isNotNull(); + requireNonNull(predicate, "The predicate to evaluate should not be null"); + if (actual.noneSatisfy(predicate)) { + throw assertionError(anyElementShouldMatch(actual, predicateDescription)); + } + } + 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 d3b6a93..3fdce8a 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/DoubleIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/DoubleIterableAssert.java @@ -16,6 +16,7 @@ package org.assertj.eclipse.collections.api; import static java.util.Objects.requireNonNull; +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.ShouldContain.shouldContain; @@ -85,6 +86,22 @@ private static Optional failsRequirements(DoubleConsumer return Optional.empty(); } + public DoubleIterableAssert anyMatch(DoublePredicate predicate) { + return executeAssertion(() -> assertAnyMatch(predicate, PredicateDescription.GIVEN)); + } + + public DoubleIterableAssert anyMatch(DoublePredicate predicate, String predicateDescription) { + return executeAssertion(() -> assertAnyMatch(predicate, new PredicateDescription(predicateDescription))); + } + + private void assertAnyMatch(DoublePredicate predicate, PredicateDescription predicateDescription) { + isNotNull(); + requireNonNull(predicate, "The predicate to evaluate should not be null"); + if (actual.noneSatisfy(predicate::test)) { + throw assertionError(anyElementShouldMatch(actual, predicateDescription)); + } + } + 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 9c24601..c41d603 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/FloatIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/FloatIterableAssert.java @@ -16,6 +16,7 @@ package org.assertj.eclipse.collections.api; import static java.util.Objects.requireNonNull; +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.ShouldContain.shouldContain; @@ -85,6 +86,22 @@ private static Optional failsRequirements(FloatProcedure return Optional.empty(); } + public FloatIterableAssert anyMatch(FloatPredicate predicate) { + return executeAssertion(() -> assertAnyMatch(predicate, PredicateDescription.GIVEN)); + } + + public FloatIterableAssert anyMatch(FloatPredicate predicate, String predicateDescription) { + return executeAssertion(() -> assertAnyMatch(predicate, new PredicateDescription(predicateDescription))); + } + + private void assertAnyMatch(FloatPredicate predicate, PredicateDescription predicateDescription) { + isNotNull(); + requireNonNull(predicate, "The predicate to evaluate should not be null"); + if (actual.noneSatisfy(predicate)) { + throw assertionError(anyElementShouldMatch(actual, predicateDescription)); + } + } + 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 8a8e036..8f7be81 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/IntIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/IntIterableAssert.java @@ -16,6 +16,7 @@ package org.assertj.eclipse.collections.api; import static java.util.Objects.requireNonNull; +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.ShouldContain.shouldContain; @@ -30,6 +31,7 @@ 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.primitive.IntLists; import org.eclipse.collections.api.list.primitive.ImmutableIntList; import org.eclipse.collections.api.list.primitive.IntList; @@ -85,6 +87,22 @@ private static Optional failsRequirements(IntConsumer re return Optional.empty(); } + public IntIterableAssert anyMatch(IntPredicate predicate) { + return executeAssertion(() -> assertAnyMatch(predicate, PredicateDescription.GIVEN)); + } + + public IntIterableAssert anyMatch(IntPredicate predicate, String predicateDescription) { + return executeAssertion(() -> assertAnyMatch(predicate, new PredicateDescription(predicateDescription))); + } + + private void assertAnyMatch(IntPredicate predicate, PredicateDescription predicateDescription) { + isNotNull(); + requireNonNull(predicate, "The predicate to evaluate should not be null"); + if (actual.noneSatisfy(predicate::test)) { + throw assertionError(anyElementShouldMatch(actual, predicateDescription)); + } + } + 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 ce8c9a0..e509960 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/LongIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/LongIterableAssert.java @@ -16,6 +16,7 @@ package org.assertj.eclipse.collections.api; import static java.util.Objects.requireNonNull; +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.ShouldContain.shouldContain; @@ -85,6 +86,22 @@ private static Optional failsRequirements(LongConsumer r return Optional.empty(); } + public LongIterableAssert anyMatch(LongPredicate predicate) { + return executeAssertion(() -> assertAnyMatch(predicate, PredicateDescription.GIVEN)); + } + + public LongIterableAssert anyMatch(LongPredicate predicate, String predicateDescription) { + return executeAssertion(() -> assertAnyMatch(predicate, new PredicateDescription(predicateDescription))); + } + + private void assertAnyMatch(LongPredicate predicate, PredicateDescription predicateDescription) { + isNotNull(); + requireNonNull(predicate, "The predicate to evaluate should not be null"); + if (actual.noneSatisfy(predicate::test)) { + throw assertionError(anyElementShouldMatch(actual, predicateDescription)); + } + } + 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 9f1fbbf..e68161c 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/ShortIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/ShortIterableAssert.java @@ -16,6 +16,7 @@ package org.assertj.eclipse.collections.api; import static java.util.Objects.requireNonNull; +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.ShouldContain.shouldContain; @@ -85,6 +86,22 @@ private static Optional failsRequirements(ShortProcedure return Optional.empty(); } + public ShortIterableAssert anyMatch(ShortPredicate predicate) { + return executeAssertion(() -> assertAnyMatch(predicate, PredicateDescription.GIVEN)); + } + + public ShortIterableAssert anyMatch(ShortPredicate predicate, String predicateDescription) { + return executeAssertion(() -> assertAnyMatch(predicate, new PredicateDescription(predicateDescription))); + } + + private void assertAnyMatch(ShortPredicate predicate, PredicateDescription predicateDescription) { + isNotNull(); + requireNonNull(predicate, "The predicate to evaluate should not be null"); + if (actual.noneSatisfy(predicate)) { + throw assertionError(anyElementShouldMatch(actual, predicateDescription)); + } + } + public ShortIterableAssert contains(short... values) { return executeAssertion(() -> { isNotNull(); diff --git a/src/test/java/org/assertj/eclipse/collections/api/primitive/PrimitiveIterableAssert_AnyMatch_Test.java b/src/test/java/org/assertj/eclipse/collections/api/primitive/PrimitiveIterableAssert_AnyMatch_Test.java new file mode 100644 index 0000000..600b2ac --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/primitive/PrimitiveIterableAssert_AnyMatch_Test.java @@ -0,0 +1,361 @@ +/* + * 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.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_AnyMatch_Test { + + @Nested + class BooleanTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BOOLEAN) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(false, true, false).anyMatch(value -> value)); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BOOLEAN) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anyMatch(value -> value)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BOOLEAN) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(false, false, false).anyMatch(value -> value)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BOOLEAN) + void passesWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(false, true, false).anyMatch(value -> value, "is true")); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BOOLEAN) + void failsWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(false, false, false).anyMatch(value -> value, "is true")) + .withMessageContaining("to match 'is true' predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BOOLEAN) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anyMatch(value -> true)); + } + } + + @Nested + class ByteTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BYTE) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements((byte) 1, (byte) 2, (byte) 3).anyMatch(value -> value % 2 == 0)); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BYTE) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anyMatch(value -> value % 2 == 0)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BYTE) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements((byte) 1, (byte) 3, (byte) 5).anyMatch(value -> value % 2 == 0)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BYTE) + void passesWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements((byte) 1, (byte) 2, (byte) 3).anyMatch(value -> value % 2 == 0, "is even")); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BYTE) + void failsWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements((byte) 1, (byte) 3, (byte) 5).anyMatch(value -> value % 2 == 0, "is even")) + .withMessageContaining("to match 'is even' predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.BYTE) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anyMatch(value -> value >= 0)); + } + } + + @Nested + class CharTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.CHAR) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements('a', 'B', 'c').anyMatch(value -> value >= 'A' && value <= 'Z')); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.CHAR) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anyMatch(value -> value >= 'A' && value <= 'Z')) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.CHAR) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements('a', 'b', 'c').anyMatch(value -> value >= 'A' && value <= 'Z')) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.CHAR) + void passesWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements('a', 'B', 'c').anyMatch(value -> value >= 'A' && value <= 'Z', "is uppercase")); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.CHAR) + void failsWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements('a', 'b', 'c').anyMatch(value -> value >= 'A' && value <= 'Z', "is uppercase")) + .withMessageContaining("to match 'is uppercase' predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.CHAR) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anyMatch(value -> value >= 0)); + } + } + + @Nested + class DoubleTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.DOUBLE) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(-1.0, 2.0, -3.0).anyMatch(value -> value > 0)); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.DOUBLE) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anyMatch(value -> value > 0)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.DOUBLE) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(-1.0, -2.0, -3.0).anyMatch(value -> value > 0)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.DOUBLE) + void passesWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(-1.0, 2.0, -3.0).anyMatch(value -> value > 0, "is positive")); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.DOUBLE) + void failsWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(-1.0, -2.0, -3.0).anyMatch(value -> value > 0, "is positive")) + .withMessageContaining("to match 'is positive' predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.DOUBLE) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anyMatch(value -> value >= 0)); + } + } + + @Nested + class FloatTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.FLOAT) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(-1.0f, 2.0f, -3.0f).anyMatch(value -> value > 0)); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.FLOAT) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anyMatch(value -> value > 0)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.FLOAT) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(-1.0f, -2.0f, -3.0f).anyMatch(value -> value > 0)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.FLOAT) + void passesWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(-1.0f, 2.0f, -3.0f).anyMatch(value -> value > 0, "is positive")); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.FLOAT) + void failsWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(-1.0f, -2.0f, -3.0f).anyMatch(value -> value > 0, "is positive")) + .withMessageContaining("to match 'is positive' predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.FLOAT) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anyMatch(value -> value >= 0)); + } + } + + @Nested + class IntTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.INT) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(1, 2, 3).anyMatch(value -> value % 2 == 0)); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.INT) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anyMatch(value -> value % 2 == 0)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.INT) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(1, 3, 5).anyMatch(value -> value % 2 == 0)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.INT) + void passesWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(1, 2, 3).anyMatch(value -> value % 2 == 0, "is even")); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.INT) + void failsWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(1, 3, 5).anyMatch(value -> value % 2 == 0, "is even")) + .withMessageContaining("to match 'is even' predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.INT) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anyMatch(value -> value >= 0)); + } + } + + @Nested + class LongTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.LONG) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(1L, 2L, 3L).anyMatch(value -> value % 2 == 0)); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.LONG) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anyMatch(value -> value % 2 == 0)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.LONG) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(1L, 3L, 5L).anyMatch(value -> value % 2 == 0)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.LONG) + void passesWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements(1L, 2L, 3L).anyMatch(value -> value % 2 == 0, "is even")); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.LONG) + void failsWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements(1L, 3L, 5L).anyMatch(value -> value % 2 == 0, "is even")) + .withMessageContaining("to match 'is even' predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.LONG) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anyMatch(value -> value >= 0)); + } + } + + @Nested + class ShortTest { + @PrimitiveIterableParameterizedTest(type = PrimitiveType.SHORT) + void passes(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements((short) 1, (short) 2, (short) 3).anyMatch(value -> value % 2 == 0)); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.SHORT) + void failsEmpty(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anyMatch(value -> value % 2 == 0)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.SHORT) + void fails(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements((short) 1, (short) 3, (short) 5).anyMatch(value -> value % 2 == 0)) + .withMessageContaining("to match given predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.SHORT) + void passesWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements((short) 1, (short) 2, (short) 3).anyMatch(value -> value % 2 == 0, "is even")); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.SHORT) + void failsWithDescription(PrimitiveIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements((short) 1, (short) 3, (short) 5).anyMatch(value -> value % 2 == 0, "is even")) + .withMessageContaining("to match 'is even' predicate but none did."); + } + + @PrimitiveIterableParameterizedTest(type = PrimitiveType.SHORT) + void softAssertionPasses(PrimitiveIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromSize(softly, 3).anyMatch(value -> value >= 0)); + } + } +} diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_AnyMatch_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_AnyMatch_Test.java new file mode 100644 index 0000000..81b0fac --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_AnyMatch_Test.java @@ -0,0 +1,61 @@ +/* + * 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 org.assertj.eclipse.collections.api.SoftAssertions; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; + +class AbstractRichIterableAssert_AnyMatch_Test { + @RichIterableParameterizedTest + void passes(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").anyMatch(s -> s.equals("DS9"))); + } + + @RichIterableParameterizedTest + void failsEmpty(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().anyMatch(s -> s.length() == 3)) + .withMessageContaining("to match given predicate but none did."); + } + + @RichIterableParameterizedTest + void fails(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").anyMatch(s -> s.length() == 4)) + .withMessageContaining("to match given predicate but none did."); + } + + @RichIterableParameterizedTest + void passesWithDescription(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").anyMatch(s -> s.equals("DS9"), "is DS9")); + } + + @RichIterableParameterizedTest + void failsWithDescription(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").anyMatch(s -> s.length() == 4, "has length 4")) + .withMessageContaining("to match 'has length 4' predicate but none did."); + } + + @RichIterableParameterizedTest + void softAssertionPasses(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly, "TOS", "TNG", "DS9", "VOY", "ENT").anyMatch(s -> s.equals("DS9"))); + } +}