From 5322a158ea9d6e72d68edd838dbe2a0c1fb190e4 Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Wed, 27 May 2026 07:15:02 -0400 Subject: [PATCH 01/14] Add hasSizeGreaterThan method to AbstractRichIterableAssert --- .../api/AbstractRichIterableAssert.java | 28 +++++++++++++ .../eclipse/collections/api/Assertions.java | 14 +++++++ ...terableAssert_HasSizeGreaterThan_Test.java | 40 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThan_Test.java 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 a7aef79..4e6a047 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 org.assertj.core.error.ShouldHaveSize.shouldHaveSize; +import static org.assertj.core.error.ShouldHaveSizeGreaterThan.shouldHaveSizeGreaterThan; import static org.assertj.core.util.Preconditions.checkArgument; import java.util.Objects; @@ -108,6 +109,33 @@ public SELF hasSize(int expected) { throw assertionError(shouldHaveSize(actual, actualSize, expected)); } + /** + * Verifies that the number of values in the actual RichIterable is greater than the given boundary. + *

+ * Example: + *

{@code // assertion will pass
+   * assertThat(Lists.immutable.of("TOS", "TNG", "DS9")).hasSizeGreaterThan(2);
+   *
+   * // assertion will fail
+   * assertThat(Lists.immutable.of("TOS", "TNG", "DS9")).hasSizeGreaterThan(3);
+   * }
+ * + * @param boundary the given value to compare the actual size to. + * @return {@code this} assertion object. + * @throws AssertionError if the number of values of the actual iterable is not greater than the boundary. + */ + @Override + public SELF hasSizeGreaterThan(int boundary) { + isNotNull(); + + int actualSize = actual.size(); + if (actualSize > boundary) { + return myself; + } + + throw assertionError(shouldHaveSizeGreaterThan(actual, actualSize, boundary)); + } + /** * Helper method that filters via Eclipse Collections to avoid creating any JCL collections. * diff --git a/src/main/java/org/assertj/eclipse/collections/api/Assertions.java b/src/main/java/org/assertj/eclipse/collections/api/Assertions.java index 086c37e..a9389bc 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/Assertions.java +++ b/src/main/java/org/assertj/eclipse/collections/api/Assertions.java @@ -46,6 +46,13 @@ public static BagAssert assertThat(Bag actual) { return new BagAssert<>(actual); } + /** + * Creates a new instance of {@link ListIterableAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + * @param The type of the elements in the list + */ public static ListIterableAssert assertThat(ListIterable actual) { return new ListIterableAssert<>(actual); } @@ -73,6 +80,13 @@ public static SetIterableAssert assertThat(SetIterable actual) { return new SetIterableAssert<>(actual); } + /** + * Creates a new instance of {@link StackIterableAssert}. + * + * @param actual the actual value. + * @return the created assertion object. + * @param The type of the elements in the stack + */ public static StackIterableAssert assertThat(StackIterable actual) { return new StackIterableAssert<>(actual); } diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThan_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThan_Test.java new file mode 100644 index 0000000..7f8f284 --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThan_Test.java @@ -0,0 +1,40 @@ +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_HasSizeGreaterThan_Test { + @RichIterableParameterizedTest + void passes(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeGreaterThan(3)); + } + + @RichIterableParameterizedTest + void failsEmpty(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().hasSizeGreaterThan(3)) + .withMessageContaining(String.format("to be greater than %s but was 0", 3)); + } + + @RichIterableParameterizedTest + void failsEquals(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeGreaterThan(5)) + .withMessageContaining(String.format("to be greater than %s but was 5", 5)); + } + + @RichIterableParameterizedTest + void failsLessThan(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeGreaterThan(7)) + .withMessageContaining(String.format("to be greater than %s but was 5", 7)); + } + + @RichIterableParameterizedTest + void softAssertionPasses(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly, "TOS", "TNG", "DS9", "VOY", "ENT").hasSizeGreaterThan(2)); + } +} From 706d438b780587a52e92839bd72690ce944484b1 Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Wed, 27 May 2026 07:34:30 -0400 Subject: [PATCH 02/14] Add hasSizeGreaterThanOrEqualTo method to AbstractRichIterableAssert --- .../api/AbstractRichIterableAssert.java | 30 ++++++++++++++ ...sert_HasSizeGreaterThanOrEqualTo_Test.java | 39 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThanOrEqualTo_Test.java 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 4e6a047..9e622cd 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java @@ -17,6 +17,7 @@ import static org.assertj.core.error.ShouldHaveSize.shouldHaveSize; import static org.assertj.core.error.ShouldHaveSizeGreaterThan.shouldHaveSizeGreaterThan; +import static org.assertj.core.error.ShouldHaveSizeGreaterThanOrEqualTo.shouldHaveSizeGreaterThanOrEqualTo; import static org.assertj.core.util.Preconditions.checkArgument; import java.util.Objects; @@ -136,6 +137,35 @@ public SELF hasSizeGreaterThan(int boundary) { throw assertionError(shouldHaveSizeGreaterThan(actual, actualSize, boundary)); } + /** + * Verifies that the number of values in the actual group is greater than or equal to the given boundary. + *

+ * Example: + *

{@code // assertions will pass
+   * assertThat(Lists.immutable.of("TOS", "TNG", "DS9")).hasSizeGreaterThanOrEqualTo(3);
+   * assertThat(Lists.immutable.of("TNG", "DS9")).hasSizeGreaterThanOrEqualTo(1);
+   *
+   * // assertions will fail
+   * assertThat(Lists.immutable.of("TNG", "DS9")).hasSizeGreaterThanOrEqualTo(3);
+   * assertThat(Lists.immutable.of("TOS", "TNG", "DS9")).hasSizeGreaterThanOrEqualTo(4);
+   * }
+ * + * @param boundary the given value to compare the actual size to. + * @return {@code this} assertion object. + * @throws AssertionError if the number of values of the actual group is not greater than or equal to the boundary. + */ + @Override + public SELF hasSizeGreaterThanOrEqualTo(int boundary) { + isNotNull(); + + int actualSize = actual.size(); + if (actualSize >= boundary) { + return myself; + } + + throw assertionError(shouldHaveSizeGreaterThanOrEqualTo(actual, actualSize, boundary)); + } + /** * Helper method that filters via Eclipse Collections to avoid creating any JCL collections. * diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThanOrEqualTo_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThanOrEqualTo_Test.java new file mode 100644 index 0000000..cd24392 --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThanOrEqualTo_Test.java @@ -0,0 +1,39 @@ +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_HasSizeGreaterThanOrEqualTo_Test { + @RichIterableParameterizedTest + void passes(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeGreaterThanOrEqualTo(3)); + } + + @RichIterableParameterizedTest + void passesEquals(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeGreaterThanOrEqualTo(5)); + } + + @RichIterableParameterizedTest + void failsEmpty(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().hasSizeGreaterThanOrEqualTo(3)) + .withMessageContaining(String.format("to be greater than or equal to %s but was 0", 3)); + } + + @RichIterableParameterizedTest + void failsLessThan(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeGreaterThanOrEqualTo(7)) + .withMessageContaining(String.format("to be greater than or equal to %s but was 5", 7)); + } + + @RichIterableParameterizedTest + void softAssertionPasses(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly, "TOS", "TNG", "DS9", "VOY", "ENT").hasSizeGreaterThanOrEqualTo(2)); + } +} From 9fb5b5b96c9f13c60d2ed12e0b167bf3ba247e20 Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Wed, 27 May 2026 07:36:07 -0400 Subject: [PATCH 03/14] Add license --- ...leAssert_HasSizeGreaterThanOrEqualTo_Test.java | 15 +++++++++++++++ ...ichIterableAssert_HasSizeGreaterThan_Test.java | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThanOrEqualTo_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThanOrEqualTo_Test.java index cd24392..ffc8fff 100644 --- a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThanOrEqualTo_Test.java +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThanOrEqualTo_Test.java @@ -1,3 +1,18 @@ +/* + * 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; diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThan_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThan_Test.java index 7f8f284..38450ad 100644 --- a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThan_Test.java +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeGreaterThan_Test.java @@ -1,3 +1,18 @@ +/* + * 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; From 861056c6ba4da6285cb54adf1e9330431d76f975 Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Wed, 27 May 2026 08:02:51 -0400 Subject: [PATCH 04/14] Add isEmpty to AbstractRichIterableAssert --- .../api/AbstractRichIterableAssert.java | 12 +++++ ...stractRichIterableAssert_IsEmpty_Test.java | 49 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_IsEmpty_Test.java 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 9e622cd..aafd658 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java @@ -15,6 +15,7 @@ */ package org.assertj.eclipse.collections.api; +import static org.assertj.core.error.ShouldBeEmpty.shouldBeEmpty; import static org.assertj.core.error.ShouldHaveSize.shouldHaveSize; import static org.assertj.core.error.ShouldHaveSizeGreaterThan.shouldHaveSizeGreaterThan; import static org.assertj.core.error.ShouldHaveSizeGreaterThanOrEqualTo.shouldHaveSizeGreaterThanOrEqualTo; @@ -166,6 +167,17 @@ public SELF hasSizeGreaterThanOrEqualTo(int boundary) { throw assertionError(shouldHaveSizeGreaterThanOrEqualTo(actual, actualSize, boundary)); } + @Override + public void isEmpty() { + isNotNull(); + + if (actual.isEmpty()) { + return; + } + + throw assertionError(shouldBeEmpty(actual)); + } + /** * Helper method that filters via Eclipse Collections to avoid creating any JCL collections. * diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_IsEmpty_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_IsEmpty_Test.java new file mode 100644 index 0000000..2a72c64 --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_IsEmpty_Test.java @@ -0,0 +1,49 @@ +/* + * 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 static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; + +import org.assertj.eclipse.collections.api.SoftAssertions; + +class AbstractRichIterableAssert_IsEmpty_Test { + + @RichIterableParameterizedTest + void passes(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromEmpty().isEmpty()); + } + + @RichIterableParameterizedTest + void failsNonEmpty(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").isEmpty()) + .withMessageContaining("Expecting empty but was:"); + } + + @RichIterableParameterizedTest + void failsNullInput(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromNull().isEmpty()) + .withMessageContaining("Expecting actual not to be null"); + } + + @RichIterableParameterizedTest + void softAssertionPasses(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly).isEmpty()); + } +} From 2a73802f5a0d79152af6d6bc176871120134ec98 Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Wed, 27 May 2026 09:03:30 -0400 Subject: [PATCH 05/14] Javadoc --- .../eclipse/collections/api/AbstractRichIterableAssert.java | 3 +++ 1 file changed, 3 insertions(+) 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 aafd658..f1d78b1 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java @@ -167,6 +167,9 @@ public SELF hasSizeGreaterThanOrEqualTo(int boundary) { throw assertionError(shouldHaveSizeGreaterThanOrEqualTo(actual, actualSize, boundary)); } + /** + * Verifies that the actual RichIterable is empty. + */ @Override public void isEmpty() { isNotNull(); From 44da131e2b02dfa39f9b6a8de077660c1cac6cfa Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Wed, 27 May 2026 19:32:12 -0400 Subject: [PATCH 06/14] Add isNotEmpty method to AbstractRichIterableAssert --- .../api/AbstractRichIterableAssert.java | 20 ++++++++ ...actRichIterableAssert_IsNotEmpty_Test.java | 49 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_IsNotEmpty_Test.java 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 f1d78b1..f2486ab 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.ShouldHaveSize.shouldHaveSize; import static org.assertj.core.error.ShouldHaveSizeGreaterThan.shouldHaveSizeGreaterThan; import static org.assertj.core.error.ShouldHaveSizeGreaterThanOrEqualTo.shouldHaveSizeGreaterThanOrEqualTo; +import static org.assertj.core.error.ShouldNotBeEmpty.shouldNotBeEmpty; import static org.assertj.core.util.Preconditions.checkArgument; import java.util.Objects; @@ -169,6 +170,8 @@ public SELF hasSizeGreaterThanOrEqualTo(int boundary) { /** * Verifies that the actual RichIterable is empty. + * + * @throws AssertionError if the actual RichIterable is not empty. */ @Override public void isEmpty() { @@ -181,6 +184,23 @@ public void isEmpty() { throw assertionError(shouldBeEmpty(actual)); } + /** + * Verifies that the actual RichIterable is not empty. + * + * @return {@code this} assertion object. + * @throws AssertionError if the actual RichIterable is empty. + */ + @Override + public SELF isNotEmpty() { + isNotNull(); + + if (!actual.isEmpty()) { + return myself; + } + + throw assertionError(shouldNotBeEmpty()); + } + /** * Helper method that filters via Eclipse Collections to avoid creating any JCL collections. * diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_IsNotEmpty_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_IsNotEmpty_Test.java new file mode 100644 index 0000000..56a87d3 --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_IsNotEmpty_Test.java @@ -0,0 +1,49 @@ +/* + * 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 static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; + +import org.assertj.eclipse.collections.api.SoftAssertions; + +class AbstractRichIterableAssert_IsNotEmpty_Test { + + @RichIterableParameterizedTest + void passes(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").isNotEmpty()); + } + + @RichIterableParameterizedTest + void failsEmpty(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().isNotEmpty()) + .withMessageContaining("Expecting actual not to be empty"); + } + + @RichIterableParameterizedTest + void failsNullInput(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromNull().isNotEmpty()) + .withMessageContaining("Expecting actual not to be null"); + } + + @RichIterableParameterizedTest + void softAssertionPasses(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly, "TOS", "TNG", "DS9", "VOY", "ENT").isNotEmpty()); + } +} From ed9cc71a618c784de215bc2ca553cc94f6e7ed6c Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Wed, 27 May 2026 19:32:52 -0400 Subject: [PATCH 07/14] Use better method --- .../eclipse/collections/api/AbstractRichIterableAssert.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f2486ab..fab9397 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java @@ -194,7 +194,7 @@ public void isEmpty() { public SELF isNotEmpty() { isNotNull(); - if (!actual.isEmpty()) { + if (actual.notEmpty()) { return myself; } From f2af327309a13ce72418b2706b4b999220af084d Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Tue, 2 Jun 2026 08:33:13 -0400 Subject: [PATCH 08/14] Add isNullOrEmpty method to AbstractRichIterableAssert --- .../api/AbstractRichIterableAssert.java | 15 ++++++ ...RichIterableAssert_IsNullOrEmpty_Test.java | 48 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_IsNullOrEmpty_Test.java 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 fab9397..bcbe697 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 org.assertj.core.error.ShouldBeEmpty.shouldBeEmpty; +import static org.assertj.core.error.ShouldBeNullOrEmpty.shouldBeNullOrEmpty; import static org.assertj.core.error.ShouldHaveSize.shouldHaveSize; import static org.assertj.core.error.ShouldHaveSizeGreaterThan.shouldHaveSizeGreaterThan; import static org.assertj.core.error.ShouldHaveSizeGreaterThanOrEqualTo.shouldHaveSizeGreaterThanOrEqualTo; @@ -201,6 +202,20 @@ public SELF isNotEmpty() { throw assertionError(shouldNotBeEmpty()); } + /** + * Verifies that the actual RichIterable is null or empty. + * + * @throws AssertionError if the actual RichIterable is not null or not empty. + */ + @Override + public void isNullOrEmpty() { + if (actual == null || actual.isEmpty()) { + return; + } + + throw assertionError(shouldBeNullOrEmpty(actual)); + } + /** * Helper method that filters via Eclipse Collections to avoid creating any JCL collections. * diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_IsNullOrEmpty_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_IsNullOrEmpty_Test.java new file mode 100644 index 0000000..7f08ec5 --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_IsNullOrEmpty_Test.java @@ -0,0 +1,48 @@ +/* + * 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 static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; + +import org.assertj.eclipse.collections.api.SoftAssertions; + +class AbstractRichIterableAssert_IsNullOrEmpty_Test { + + @RichIterableParameterizedTest + void passesEmpty(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromEmpty().isNullOrEmpty()); + } + + @RichIterableParameterizedTest + void passesNull(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromNull().isNullOrEmpty()); + } + + @RichIterableParameterizedTest + void failsNonEmpty(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").isNullOrEmpty()) + .withMessageContaining("Expecting null or empty but was:"); + } + + @RichIterableParameterizedTest + void softAssertionPasses(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly).isNullOrEmpty()); + } +} From e854444af65e1ca18e37ff39bb7649e32e420eff Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Tue, 2 Jun 2026 08:41:45 -0400 Subject: [PATCH 09/14] Add hasSizeLessThan method to AbstractRichIterableAssert --- .../api/AbstractRichIterableAssert.java | 29 ++++++++++ ...chIterableAssert_HasSizeLessThan_Test.java | 54 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeLessThan_Test.java 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 bcbe697..e646f41 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java @@ -20,6 +20,7 @@ import static org.assertj.core.error.ShouldHaveSize.shouldHaveSize; import static org.assertj.core.error.ShouldHaveSizeGreaterThan.shouldHaveSizeGreaterThan; import static org.assertj.core.error.ShouldHaveSizeGreaterThanOrEqualTo.shouldHaveSizeGreaterThanOrEqualTo; +import static org.assertj.core.error.ShouldHaveSizeLessThan.shouldHaveSizeLessThan; import static org.assertj.core.error.ShouldNotBeEmpty.shouldNotBeEmpty; import static org.assertj.core.util.Preconditions.checkArgument; @@ -169,6 +170,34 @@ public SELF hasSizeGreaterThanOrEqualTo(int boundary) { throw assertionError(shouldHaveSizeGreaterThanOrEqualTo(actual, actualSize, boundary)); } + /** + * Verifies that the number of values in the actual RichIterable is less than the given boundary. + *

+ * Example: + *

{@code
+   * // assertion will pass
+   * assertThat(Lists.immutable.of(1, 2, 3)).hasSizeLessThan(4);
+   *
+   * // assertion will fail
+   * assertThat(Lists.immutable.of(1, 2, 3)).hasSizeLessThan(3);
+   * }
+ * + * @param boundary the given value to compare the actual size to. + * @return {@code this} assertion object. + * @throws AssertionError if the number of values of the actual RichIterable is not less than the boundary. + */ + @Override + public SELF hasSizeLessThan(int boundary) { + isNotNull(); + + int actualSize = actual.size(); + if (actualSize < boundary) { + return myself; + } + + throw assertionError(shouldHaveSizeLessThan(actual, actualSize, boundary)); + } + /** * Verifies that the actual RichIterable is empty. * diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeLessThan_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeLessThan_Test.java new file mode 100644 index 0000000..f742acf --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeLessThan_Test.java @@ -0,0 +1,54 @@ +/* + * 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_HasSizeLessThan_Test { + @RichIterableParameterizedTest + void passes(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeLessThan(7)); + } + + @RichIterableParameterizedTest + void passesEmpty(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromEmpty().hasSizeLessThan(3)); + } + + @RichIterableParameterizedTest + void failsEquals(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeLessThan(5)) + .withMessageContaining(String.format("to be less than %s but was 5", 5)); + } + + @RichIterableParameterizedTest + void failsGreaterThan(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeLessThan(3)) + .withMessageContaining(String.format("to be less than %s but was 5", 3)); + } + + @RichIterableParameterizedTest + void softAssertionPasses(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly, "TOS", "TNG", "DS9", "VOY", "ENT").hasSizeLessThan(7)); + } +} From ce4c5fc7a4a011226e8a3a7c88a40a70460716b2 Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Tue, 2 Jun 2026 09:00:56 -0400 Subject: [PATCH 10/14] Add hasSizeLessThanOrEqualTo method to AbstractRichIterableAssert --- .../api/AbstractRichIterableAssert.java | 30 +++++++++++ ...eAssert_HasSizeLessThanOrEqualTo_Test.java | 53 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeLessThanOrEqualTo_Test.java 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 e646f41..4cb6d62 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java @@ -21,6 +21,7 @@ import static org.assertj.core.error.ShouldHaveSizeGreaterThan.shouldHaveSizeGreaterThan; import static org.assertj.core.error.ShouldHaveSizeGreaterThanOrEqualTo.shouldHaveSizeGreaterThanOrEqualTo; import static org.assertj.core.error.ShouldHaveSizeLessThan.shouldHaveSizeLessThan; +import static org.assertj.core.error.ShouldHaveSizeLessThanOrEqualTo.shouldHaveSizeLessThanOrEqualTo; import static org.assertj.core.error.ShouldNotBeEmpty.shouldNotBeEmpty; import static org.assertj.core.util.Preconditions.checkArgument; @@ -198,6 +199,35 @@ public SELF hasSizeLessThan(int boundary) { throw assertionError(shouldHaveSizeLessThan(actual, actualSize, boundary)); } + /** + * Verifies that the number of values in the actual RichIterable is less than or equal to the given boundary. + *

+ * Example: + *

{@code
+   * // assertions will pass
+   * assertThat(Lists.immutable.of("TOS", "TNG", "DS9")).hasSizeLessThanOrEqualTo(5)
+   *                                   .hasSizeLessThanOrEqualTo(3);
+   *
+   * // assertion will fail
+   * assertThat(Lists.immutable.of("TOS", "TNG", "DS9")).hasSizeLessThanOrEqualTo(2);
+   * }
+ * + * @param boundary the given value to compare the actual size to. + * @return {@code this} assertion object. + * @throws AssertionError if the number of values of the actual RichIterable is not less than or equal to the boundary. + */ + @Override + public SELF hasSizeLessThanOrEqualTo(int boundary) { + isNotNull(); + + int actualSize = actual.size(); + if (actualSize <= boundary) { + return myself; + } + + throw assertionError(shouldHaveSizeLessThanOrEqualTo(actual, actualSize, boundary)); + } + /** * Verifies that the actual RichIterable is empty. * diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeLessThanOrEqualTo_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeLessThanOrEqualTo_Test.java new file mode 100644 index 0000000..beb4c4f --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeLessThanOrEqualTo_Test.java @@ -0,0 +1,53 @@ +/* + * 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_HasSizeLessThanOrEqualTo_Test { + @RichIterableParameterizedTest + void passes(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeLessThanOrEqualTo(7)); + } + + @RichIterableParameterizedTest + void passesEquals(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeLessThanOrEqualTo(5)); + } + + @RichIterableParameterizedTest + void passesEmpty(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromEmpty().hasSizeLessThanOrEqualTo(3)); + } + + @RichIterableParameterizedTest + void failsGreaterThan(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeLessThanOrEqualTo(3)) + .withMessageContaining(String.format("to be less than or equal to %s but was 5", 3)); + } + + @RichIterableParameterizedTest + void softAssertionPasses(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly, "TOS", "TNG", "DS9", "VOY", "ENT").hasSizeLessThanOrEqualTo(7)); + } +} From b6cec3064a053c23f624bca91c7bd58a38661723 Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Tue, 2 Jun 2026 19:19:13 -0400 Subject: [PATCH 11/14] Add hasSameSizeAs methods to AbstractRichIterableAssert --- .../api/AbstractRichIterableAssert.java | 54 ++++++++++ ...RichIterableAssert_HasSameSizeAs_Test.java | 102 ++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSameSizeAs_Test.java 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 4cb6d62..598dcdf 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java @@ -15,16 +15,20 @@ */ package org.assertj.eclipse.collections.api; +import static org.assertj.core.error.ShouldBeAnArray.shouldBeAnArray; import static org.assertj.core.error.ShouldBeEmpty.shouldBeEmpty; import static org.assertj.core.error.ShouldBeNullOrEmpty.shouldBeNullOrEmpty; +import static org.assertj.core.error.ShouldHaveSameSizeAs.shouldHaveSameSizeAs; import static org.assertj.core.error.ShouldHaveSize.shouldHaveSize; import static org.assertj.core.error.ShouldHaveSizeGreaterThan.shouldHaveSizeGreaterThan; import static org.assertj.core.error.ShouldHaveSizeGreaterThanOrEqualTo.shouldHaveSizeGreaterThanOrEqualTo; import static org.assertj.core.error.ShouldHaveSizeLessThan.shouldHaveSizeLessThan; import static org.assertj.core.error.ShouldHaveSizeLessThanOrEqualTo.shouldHaveSizeLessThanOrEqualTo; import static org.assertj.core.error.ShouldNotBeEmpty.shouldNotBeEmpty; +import static org.assertj.core.util.IterableUtil.sizeOf; import static org.assertj.core.util.Preconditions.checkArgument; +import java.lang.reflect.Array; import java.util.Objects; import java.util.function.Function; import java.util.function.Predicate; @@ -85,6 +89,56 @@ public SELF filteredOn(Predicate predicate) { return internalFilteredOn(predicate::test); } + /** + * Verifies that the size of the actual RichIterable is equal to the size of the given iterable. + * + * @param other the iterable to compare the size of the actual RichIterable with. + * @return {@code this} assertion object. + * @throws NullPointerException if the given iterable is {@code null}. + * @throws AssertionError if the size of the actual RichIterable is not equal to the size of the given iterable. + */ + @Override + public SELF hasSameSizeAs(Iterable other) { + isNotNull(); + + final int otherSize; + if (other instanceof RichIterable richIterable) { + otherSize = richIterable.size(); + } else { + otherSize = sizeOf(other); + } + + int actualSize = actual.size(); + if (actualSize == otherSize) { + return myself; + } + throw assertionError(shouldHaveSameSizeAs(actual, other, actualSize, otherSize)); + } + + /** + * Verifies that the size of the actual RichIterable matches the size of the given array. + * + * @param other the array to compare the size of the actual RichIterable with. + * @return {@code this} assertion object. + * @throws AssertionError if the size of the actual RichIterable does not match the size of the given array or if the given array is {@code null}. + */ + @Override + public SELF hasSameSizeAs(Object other) { + isNotNull(); + + if (!(other != null && other.getClass().isArray())) { + throw assertionError(shouldBeAnArray(other)); + } + + int otherSize = Array.getLength(other); + int actualSize = actual.size(); + if (actualSize == otherSize) { + return myself; + } + + throw assertionError(shouldHaveSameSizeAs(actual, other, actualSize, otherSize)); + } + /** * Verifies that the number of values in the actual RichIterable is equal to the given one. *

diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSameSizeAs_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSameSizeAs_Test.java new file mode 100644 index 0000000..6f9eb99 --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSameSizeAs_Test.java @@ -0,0 +1,102 @@ +/* + * 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 static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; + +import java.util.List; + +import org.assertj.eclipse.collections.api.SoftAssertions; +import org.eclipse.collections.api.factory.Lists; + +class AbstractRichIterableAssert_HasSameSizeAs_Test { + + @RichIterableParameterizedTest + void passesRichIterable(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSameSizeAs(Lists.immutable.of("a", "b", "c", "d", "e"))); + } + + @RichIterableParameterizedTest + void passesJcfIterable(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSameSizeAs(List.of("a", "b", "c", "d", "e"))); + } + + @RichIterableParameterizedTest + void failsRichIterableDifferentSize(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSameSizeAs(Lists.immutable.of("a", "b", "c"))) + .withMessageContaining("Actual and expected should have same size but actual size is:"); + } + + @RichIterableParameterizedTest + void failsJcfIterableDifferentSize(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSameSizeAs(List.of("a", "b", "c"))) + .withMessageContaining("Actual and expected should have same size but actual size is:"); + } + + @RichIterableParameterizedTest + void failsRichIterableNullInput(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromNull().hasSameSizeAs(Lists.immutable.of("a", "b", "c", "d", "e"))) + .withMessageContaining("Expecting actual not to be null"); + } + + @RichIterableParameterizedTest + void failsJcfIterableNullInput(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromNull().hasSameSizeAs(List.of("a", "b", "c", "d", "e"))) + .withMessageContaining("Expecting actual not to be null"); + } + + @RichIterableParameterizedTest + void softAssertionPassesRichIterable(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly, "TOS", "TNG", "DS9", "VOY", "ENT").hasSameSizeAs(Lists.immutable.of("a", "b", "c", "d", "e"))); + } + + @RichIterableParameterizedTest + void softAssertionPassesJcfIterable(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly, "TOS", "TNG", "DS9", "VOY", "ENT").hasSameSizeAs(List.of("a", "b", "c", "d", "e"))); + } + + @RichIterableParameterizedTest + void passesArray(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSameSizeAs(new String[]{"a", "b", "c", "d", "e"})); + } + + @RichIterableParameterizedTest + void failsArrayDifferentSize(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSameSizeAs(new String[]{"a", "b", "c"})) + .withMessageContaining("Actual and expected should have same size but actual size is:"); + } + + @RichIterableParameterizedTest + void failsArrayNullInput(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromNull().hasSameSizeAs(new String[]{"a", "b", "c", "d", "e"})) + .withMessageContaining("Expecting actual not to be null"); + } + + @RichIterableParameterizedTest + void softAssertionPassesArray(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly, "TOS", "TNG", "DS9", "VOY", "ENT").hasSameSizeAs(new String[]{"a", "b", "c", "d", "e"})); + } +} From 26d1dfa2f65a7c754b009beff2a89a398ab48f2d Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Tue, 2 Jun 2026 19:20:35 -0400 Subject: [PATCH 12/14] Update docs --- .../eclipse/collections/api/AbstractRichIterableAssert.java | 1 + 1 file changed, 1 insertion(+) 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 598dcdf..18b27ea 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java @@ -120,6 +120,7 @@ public SELF hasSameSizeAs(Iterable other) { * * @param other the array to compare the size of the actual RichIterable with. * @return {@code this} assertion object. + * @throws AssertionError if the provided array is {@code null}. * @throws AssertionError if the size of the actual RichIterable does not match the size of the given array or if the given array is {@code null}. */ @Override From 8a42982709b9e5acd67290701676fe0a47a583da Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Tue, 2 Jun 2026 19:41:05 -0400 Subject: [PATCH 13/14] Add hasSizeBetween method to AbstractRichIterableAssert --- .../api/AbstractRichIterableAssert.java | 36 +++++++++ ...ichIterableAssert_HasSizeBetween_Test.java | 75 +++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeBetween_Test.java 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 18b27ea..60ccf6a 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java @@ -20,6 +20,7 @@ import static org.assertj.core.error.ShouldBeNullOrEmpty.shouldBeNullOrEmpty; import static org.assertj.core.error.ShouldHaveSameSizeAs.shouldHaveSameSizeAs; import static org.assertj.core.error.ShouldHaveSize.shouldHaveSize; +import static org.assertj.core.error.ShouldHaveSizeBetween.shouldHaveSizeBetween; import static org.assertj.core.error.ShouldHaveSizeGreaterThan.shouldHaveSizeGreaterThan; import static org.assertj.core.error.ShouldHaveSizeGreaterThanOrEqualTo.shouldHaveSizeGreaterThanOrEqualTo; import static org.assertj.core.error.ShouldHaveSizeLessThan.shouldHaveSizeLessThan; @@ -170,6 +171,41 @@ public SELF hasSize(int expected) { throw assertionError(shouldHaveSize(actual, actualSize, expected)); } + /** + * Verifies that the number of values in the actual RichIterable is between the given boundaries (inclusive). + *

+ * Example: + *

 // assertions will pass
+   * assertThat(Arrays.asList(1, 2, 3)).hasSizeBetween(2, 3)
+   *                                   .hasSizeBetween(3, 4)
+   *                                   .hasSizeBetween(3, 3);
+   *
+   * // assertion will fail
+   * assertThat(Arrays.asList(1, 2, 3)).hasSizeBetween(4, 6);
+ * + * @param lowerBoundary the lower boundary compared to which actual size should be greater than or equal to. + * @param higherBoundary the higher boundary compared to which actual size should be less than or equal to. + * @return {@code this} assertion object. + * @throws AssertionError if the number of values of the actual RichIterable is not between the boundaries. + */ + @Override + public SELF hasSizeBetween(int lowerBoundary, int higherBoundary) { + isNotNull(); + + if (!(higherBoundary >= lowerBoundary)) { + throw new IllegalArgumentException("The higher boundary <%s> must be greater than the lower boundary <%s>.".formatted( + higherBoundary, + lowerBoundary)); + } + + int actualSize = actual.size(); + if (actualSize >= lowerBoundary && actualSize <= higherBoundary) { + return myself; + } + + throw assertionError(shouldHaveSizeBetween(actual, actualSize, lowerBoundary, higherBoundary)); + } + /** * Verifies that the number of values in the actual RichIterable is greater than the given boundary. *

diff --git a/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeBetween_Test.java b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeBetween_Test.java new file mode 100644 index 0000000..91f79d1 --- /dev/null +++ b/src/test/java/org/assertj/eclipse/collections/api/richiterable/AbstractRichIterableAssert_HasSizeBetween_Test.java @@ -0,0 +1,75 @@ +/* + * 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 static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNoException; + +import org.assertj.eclipse.collections.api.SoftAssertions; + +class AbstractRichIterableAssert_HasSizeBetween_Test { + + @RichIterableParameterizedTest + void passes(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeBetween(3, 7)); + } + + @RichIterableParameterizedTest + void passesLowerBound(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeBetween(5, 7)); + } + + @RichIterableParameterizedTest + void passesUpperBound(RichIterableAssertFactory assertFactory) { + assertThatNoException().isThrownBy(() -> + assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeBetween(3, 5)); + } + + @RichIterableParameterizedTest + void failsBelowLowerBound(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeBetween(7, 10)) + .withMessageContaining("Expected size to be between"); + } + + @RichIterableParameterizedTest + void failsAboveUpperBound(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromElements("TOS", "TNG", "DS9", "VOY", "ENT").hasSizeBetween(1, 3)) + .withMessageContaining("Expected size to be between"); + } + + @RichIterableParameterizedTest + void failsEmpty(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromEmpty().hasSizeBetween(3, 5)) + .withMessageContaining("Expected size to be between"); + } + + @RichIterableParameterizedTest + void failsNullInput(RichIterableAssertFactory assertFactory) { + assertThatExceptionOfType(AssertionError.class) + .isThrownBy(() -> assertFactory.fromNull().hasSizeBetween(3, 5)) + .withMessageContaining("Expecting actual not to be null"); + } + + @RichIterableParameterizedTest + void softAssertionPasses(RichIterableAssertFactory assertFactory) { + SoftAssertions.assertSoftly(softly -> assertFactory.softlyFromElements(softly, "TOS", "TNG", "DS9", "VOY", "ENT").hasSizeBetween(3, 7)); + } +} From d23d1f64b207e36f9b9f9149a888fc68ba5419b5 Mon Sep 17 00:00:00 2001 From: Matt Bertolini Date: Wed, 3 Jun 2026 07:07:46 -0400 Subject: [PATCH 14/14] Update docs --- .../api/AbstractRichIterableAssert.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) 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 60ccf6a..b9593c9 100644 --- a/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java +++ b/src/main/java/org/assertj/eclipse/collections/api/AbstractRichIterableAssert.java @@ -34,6 +34,7 @@ import java.util.function.Function; import java.util.function.Predicate; +import org.assertj.core.annotation.CheckReturnValue; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractIterableAssert; import org.eclipse.collections.api.RichIterable; @@ -61,6 +62,7 @@ protected AbstractRichIterableAssert(ACTUAL actual, Class selfType) { } @Override + @CheckReturnValue public SELF filteredOn(Function function, T expectedValue) { checkArgument(function != null, "The filter function should not be null"); return internalFilteredOn(element -> Objects.equals(function.apply(element), expectedValue)); @@ -69,22 +71,23 @@ public SELF filteredOn(Function function, T expectedValu /** * Filters the iterable under test keeping only elements matching the given {@link Predicate}. *

- * Example: check old employees whose age > 100: + * Example: check crew members whose pips > 2: * - *

 Employee yoda   = new Employee(1L, new Name("Yoda"), 800);
-   * Employee obiwan = new Employee(2L, new Name("Obiwan"), 800);
-   * Employee luke   = new Employee(3L, new Name("Luke", "Skywalker"), 26);
+   * 
{@code CrewMember picard   = new CrewMember(1L, new Name("Picard"), 4);
+   * CrewMember riker = new CrewMember(2L, new Name("Riker"), 3);
+   * CrewMember crusher   = new CrewMember(3L, new Name("Wesley", "Crusher"), 1);
    *
-   * List<Employee> employees = List.of(yoda, luke, obiwan);
+   * ImmutableList crew = Lists.immutable.of(picard, crusher, riker);
    *
-   * assertThat(employees).filteredOn(employee -> employee.getAge() > 100)
-   *                      .containsOnly(yoda, obiwan);
+ * assertThat(crew).filteredOn(crewMember -> crewMember.getPips() > 2) + * .containsOnly(picard, riker);}
* * @param predicate the filter predicate * @return a new assertion object with the filtered iterable under test * @throws IllegalArgumentException if the given predicate is {@code null}. */ @Override + @CheckReturnValue public SELF filteredOn(Predicate predicate) { checkArgument(predicate != null, "The filter predicate should not be null"); return internalFilteredOn(predicate::test); @@ -148,11 +151,11 @@ public SELF hasSameSizeAs(Object other) { *
{@code
    * // assertions will pass
    * assertThat(Sets.immutable.of("TNG", "DS9")).hasSize(2);
-   * assertThat(Bags.immutable.of(1, 2, 3)).hasSize(3);
+   * assertThat(Bags.immutable.of("TNG", "DS9", "VOY")).hasSize(3);
    *
    * // assertions will fail
    * assertThat(Sets.immutable.empty()).hasSize(1);
-   * assertThat(Bags.immutable.of(1, 2, 3)).hasSize(2);
+   * assertThat(Bags.immutable.of("TNG", "DS9", "VOY")).hasSize(2);
    * }
* * @param expected the expected number of values in the actual collection. @@ -176,12 +179,12 @@ public SELF hasSize(int expected) { *

* Example: *

 // assertions will pass
-   * assertThat(Arrays.asList(1, 2, 3)).hasSizeBetween(2, 3)
-   *                                   .hasSizeBetween(3, 4)
-   *                                   .hasSizeBetween(3, 3);
+   * assertThat(Lists.immutable.of("TOS", "TNG", "DS9")).hasSizeBetween(2, 3)
+   *                                               .hasSizeBetween(3, 4)
+   *                                               .hasSizeBetween(3, 3);
    *
    * // assertion will fail
-   * assertThat(Arrays.asList(1, 2, 3)).hasSizeBetween(4, 6);
+ * assertThat(Lists.immutable.of("TOS", "TNG", "DS9")).hasSizeBetween(4, 6); * * @param lowerBoundary the lower boundary compared to which actual size should be greater than or equal to. * @param higherBoundary the higher boundary compared to which actual size should be less than or equal to. @@ -268,10 +271,10 @@ public SELF hasSizeGreaterThanOrEqualTo(int boundary) { * Example: *
{@code
    * // assertion will pass
-   * assertThat(Lists.immutable.of(1, 2, 3)).hasSizeLessThan(4);
+   * assertThat(Lists.immutable.of("TOS", "TNG", "DS9")).hasSizeLessThan(4);
    *
    * // assertion will fail
-   * assertThat(Lists.immutable.of(1, 2, 3)).hasSizeLessThan(3);
+   * assertThat(Lists.immutable.of("TOS", "TNG", "DS9")).hasSizeLessThan(3);
    * }
* * @param boundary the given value to compare the actual size to.