assertj / assertj/assertj-generator
Feature: Generate IterableAsserts for all generated Asserts
- Dominant language
- Java
- Stars
- 72
- Forks
- 47
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 2
Description
We would like to write something like this:
```java
List result;
assertThat(result).singleElement().hasName("Fool")
```
Now, we can generate `FooAssert` with the generator, but the `ListAssert` we get out of `assertThat` in this case does, of course, not known about the generated assertion; we get a regular `ObjectAssert`.
We can work around this by creating something like this here:
```java
public class FooIterableAssert
extends AbstractIterableAssert, Foo, FooIterableAssert> {
protected FooIterableAssert(Iterable foos, Class selfType) {
super(foos, selfType);
}
@Override
protected FooAssert toAssert(Foo value, String description) {
return new FooAssert(value);
}
@Override
protected FooIterableAssert newAbstractIterableAssert(Iterable iterable) {
return new FooIterableAssert(iterable, FooIterableAssert.class);
}
public static FooIterableAssert assertThat(List foos) {
return new FooIterableAssert(foos, FooIterableAssert.class);
}
}
```
This has the feel of "should be a template" and "surely not only we want this", so I'm raising this issue. :)
I'm also not sure whether one would have/want to fiddle with the entrypoint methods in support of this.
PS: I was considering to use Lombok's `@ExtensionMethod` on `ListAssert` to add something like `FooAssert singleFoo()` to it. Unfortunately, it does not seem possible to get the actual _value_ back from an Assert, so I was stuck there.
Contributor guide
Assessment
This issue has not been assessed yet.