Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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;

import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.InstanceOfAssertFactory;
import org.eclipse.collections.api.ordered.OrderedIterable;

//@format:off
public abstract class AbstractOrderedIterableAssert<SELF extends AbstractOrderedIterableAssert<SELF, ACTUAL, ELEMENT, ELEMENT_ASSERT>,
ACTUAL extends OrderedIterable<? extends ELEMENT>,
ELEMENT,
ELEMENT_ASSERT extends AbstractAssert<? extends ELEMENT_ASSERT, ELEMENT>>
extends AbstractRichIterableAssert<SELF, ACTUAL, ELEMENT, ELEMENT_ASSERT> {
//@format:on

protected AbstractOrderedIterableAssert(ACTUAL actual, Class<?> selfType) {
super(actual, selfType);
}

@Override
public ELEMENT_ASSERT first() {
return executeAssertionNavigation(this::internalFirst, () -> nullElementNavigationAssert("check first element"));
}

@Override
public <ASSERT extends AbstractAssert<?, ?>> ASSERT first(InstanceOfAssertFactory<?, ASSERT> assertFactory) {
return executeAssertionNavigation(() -> internalFirst().asInstanceOf(assertFactory),
() -> nullValueAssert(assertFactory));
}

@Override
public ELEMENT_ASSERT last() {
return executeAssertionNavigation(this::internalLast, () -> nullElementNavigationAssert("check last element"));
}

@Override
public <ASSERT extends AbstractAssert<?, ?>> ASSERT last(InstanceOfAssertFactory<?, ASSERT> assertFactory) {
return executeAssertionNavigation(() -> internalLast().asInstanceOf(assertFactory),
() -> nullValueAssert(assertFactory));
}

private ELEMENT_ASSERT internalFirst() {
isNotEmpty();
return toAssert(actual.getFirst(), navigationDescription("check first element"));
}

private ELEMENT_ASSERT internalLast() {
isNotEmpty();
return toAssert(actual.getLast(), navigationDescription("check last element"));
}

// TODO: Decide where this method should live: here, in AbstractRichIterableAssert, or somewhere else
protected ELEMENT_ASSERT nullElementNavigationAssert(String description) {
return toAssert(null, navigationDescription(description));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

import org.assertj.core.annotation.CheckReturnValue;
import org.eclipse.collections.api.bag.Bag;
import org.eclipse.collections.api.list.ListIterable;
import org.eclipse.collections.api.multimap.Multimap;
import org.eclipse.collections.api.set.SetIterable;
import org.eclipse.collections.api.stack.StackIterable;

/**
* Entry point for assertion methods for the Eclipse Collections library. Each method in this class is a static factory
Expand All @@ -44,6 +46,10 @@ public static <T> BagAssert<T> assertThat(Bag<T> actual) {
return new BagAssert<>(actual);
}

public static <T> ListIterableAssert<T> assertThat(ListIterable<T> actual) {
return new ListIterableAssert<>(actual);
}

/**
* Creates a new instance of {@link MultimapAssert}.
*
Expand All @@ -63,7 +69,11 @@ public static <KEY, VALUE> MultimapAssert<KEY, VALUE> assertThat(Multimap<KEY, V
* @return the created assertion object.
* @param <T> The type of the elements in the set
*/
public static <T>SetIterableAssert<T> assertThat(SetIterable<T> actual) {
public static <T> SetIterableAssert<T> assertThat(SetIterable<T> actual) {
return new SetIterableAssert<>(actual);
}

public static <T> StackIterableAssert<T> assertThat(StackIterable<T> actual) {
return new StackIterableAssert<>(actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

import org.assertj.core.annotation.CheckReturnValue;
import org.eclipse.collections.api.bag.Bag;
import org.eclipse.collections.api.list.ListIterable;
import org.eclipse.collections.api.multimap.Multimap;
import org.eclipse.collections.api.set.SetIterable;
import org.eclipse.collections.api.stack.StackIterable;

/**
* Behavior-driven development style entry point for assertion methods for the Eclipse Collections library. Each method
Expand All @@ -37,13 +39,24 @@ protected BDDAssertions() {
* Creates a new instance of {@link BagAssert}.
*
* @param actual the actual value.
* @return thre created assertion object.
* @param <T> THe type of the elements in the bag
* @return the created assertion object.
* @param <T> The type of the elements in the bag
*/
public static <T> BagAssert<T> then(Bag<T> actual) {
return assertThat(actual);
}

/**
* Creates a new instance of {@link ListIterableAssert}.
*
* @param actual the actual value.
* @return the created assertion object.
* @param <T> The type of the elements in the list
*/
public static <T> ListIterableAssert<T> then(ListIterable<T> actual) {
return assertThat(actual);
}

/**
* Creates a new instance of {@link MultimapAssert}.
*
Expand All @@ -66,4 +79,15 @@ public static <KEY, VALUE> MultimapAssert<KEY, VALUE> then(Multimap<KEY, VALUE>
public static <T> SetIterableAssert<T> then(SetIterable<T> actual) {
return assertThat(actual);
}

/**
* Creates a new instance of {@link StackIterableAssert}.
*
* @param actual the actual value.
* @return the created assertion object.
* @param <T> The type of the elements in the stack
*/
public static <T> StackIterableAssert<T> then(StackIterable<T> actual) {
return assertThat(actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import org.assertj.core.annotation.CheckReturnValue;
import org.assertj.core.api.SoftAssertionsProvider;
import org.eclipse.collections.api.bag.Bag;
import org.eclipse.collections.api.list.ListIterable;
import org.eclipse.collections.api.multimap.Multimap;
import org.eclipse.collections.api.set.SetIterable;
import org.eclipse.collections.api.stack.StackIterable;

/**
* Soft assertions implementations for Eclipse Collections types.
Expand All @@ -39,6 +41,18 @@ default <T> BagAssert<T> assertThat(Bag<T> actual) {
return this.proxy(BagAssert.class, Bag.class, actual);
}

/**
* Creates a new, proxied instance of a {@link ListIterableAssert}
*
* @param actual the actual value
* @return the created assertion object
* @param <T> The type of the elements in the list
*/
@SuppressWarnings("unchecked")
default <T> ListIterableAssert<T> assertThat(ListIterable<T> actual) {
return this.proxy(ListIterableAssert.class, ListIterable.class, actual);
}

/**
* Creates a new, proxied instance of a {@link MultimapAssert}
*
Expand All @@ -63,4 +77,16 @@ default <KEY, VALUE> MultimapAssert<KEY, VALUE> assertThat(Multimap<KEY, VALUE>
default <T> SetIterableAssert<T> assertThat(SetIterable<T> actual) {
return this.proxy(SetIterableAssert.class, SetIterable.class, actual);
}

/**
* Creates a new, proxied instance of a {@link StackIterableAssert}
*
* @param actual the actual value
* @return the created assertion object
* @param <T> The type of the elements in the stack
*/
@SuppressWarnings("unchecked")
default <T> StackIterableAssert<T> assertThat(StackIterable<T> actual) {
return this.proxy(StackIterableAssert.class, StackIterable.class, actual);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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;

import static org.assertj.core.api.Assertions.assertThat;

import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.InstanceOfAssertFactory;
import org.assertj.core.api.ObjectAssert;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.list.ListIterable;

/**
* Assertion methods for {@link ListIterable} interface.
*
* @param <ELEMENT> the type of elements stored in {@link ListIterable}.
*/
public class ListIterableAssert<ELEMENT> extends AbstractOrderedIterableAssert<ListIterableAssert<ELEMENT>, ListIterable<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> {
public ListIterableAssert(ListIterable<? extends ELEMENT> actual) {
super(actual, ListIterableAssert.class);
}

@Override
protected ObjectAssert<ELEMENT> toAssert(ELEMENT value) {
return new ObjectAssert<>(value);
}

@Override
protected ListIterableAssert<ELEMENT> newAbstractIterableAssert(Iterable<? extends ELEMENT> iterable) {
ImmutableList<? extends ELEMENT> elements = Lists.immutable.ofAll(iterable);
return new ListIterableAssert<>(elements);
}

@Override
public ObjectAssert<ELEMENT> element(int index) {
return executeAssertionNavigation(() -> internalElement(index),
() -> nullElementNavigationAssert("element at index " + index));
}

@Override
public <ASSERT extends AbstractAssert<?, ?>> ASSERT element(int index, InstanceOfAssertFactory<?, ASSERT> assertFactory) {
return executeAssertionNavigation(() -> internalElement(index).asInstanceOf(assertFactory),
() -> nullValueAssert(assertFactory));
}

private ObjectAssert<ELEMENT> internalElement(int index) {
isNotEmpty();
assertThat(index).describedAs(navigationDescription("check index validity"))
.isBetween(0, actual.size() - 1);
ELEMENT elementAtIndex = actual.get(index);

return toAssert(elementAtIndex, navigationDescription("element at index " + index));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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;

import org.assertj.core.annotation.CheckReturnValue;
import org.assertj.core.api.ObjectAssert;
import org.eclipse.collections.api.factory.Stacks;
import org.eclipse.collections.api.stack.ImmutableStack;
import org.eclipse.collections.api.stack.StackIterable;

/**
* Assertion methods for {@link StackIterable} interface.
*
* @param <ELEMENT> the type of elements stored in {@link StackIterable}.
*/
@CheckReturnValue
public class StackIterableAssert<ELEMENT> extends AbstractOrderedIterableAssert<StackIterableAssert<ELEMENT>, StackIterable<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> {
public StackIterableAssert(StackIterable<? extends ELEMENT> actual) {
super(actual, StackIterableAssert.class);
}

@Override
protected ObjectAssert<ELEMENT> toAssert(ELEMENT value) {
return new ObjectAssert<>(value);
}

@Override
protected StackIterableAssert<ELEMENT> newAbstractIterableAssert(Iterable<? extends ELEMENT> iterable) {
ImmutableStack<? extends ELEMENT> elements = Stacks.immutable.ofAll(iterable);
return new StackIterableAssert<>(elements);
}
}
5 changes: 3 additions & 2 deletions src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
* Test module for AssertJ Eclipse Collections
*/
open module org.assertj.eclipse.collections.test {
exports org.assertj.eclipse.collections.api.bag;
exports org.assertj.eclipse.collections.api.list;
exports org.assertj.eclipse.collections.api.multimap;
exports org.assertj.eclipse.collections.api.set;
exports org.assertj.eclipse.collections.api.richiterable;
exports org.assertj.eclipse.collections.api.stack;

requires org.assertj.eclipse.collections;
requires org.assertj.core;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.list;

import static org.assertj.core.api.Assertions.assertThatNoException;

import org.assertj.eclipse.collections.api.ListIterableAssert;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.list.ImmutableList;
import org.junit.jupiter.api.Test;

class ListIterableAssert_Element_Test {
@Test
void passes() {
assertThatNoException().isThrownBy(() -> {
ImmutableList<String> list = Lists.immutable.of("TOS", "TNG", "DS9", "VOY", "ENT");
new ListIterableAssert<>(list).element(2).isEqualTo("DS9");
});
}
}
Loading
Loading