Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Generate IterableAsserts for all generated Asserts #219

Open
reitzig opened this issue Aug 2, 2024 · 0 comments
Open

Feature: Generate IterableAsserts for all generated Asserts #219

reitzig opened this issue Aug 2, 2024 · 0 comments

Comments

@reitzig
Copy link

reitzig commented Aug 2, 2024

We would like to write something like this:

List<Foo> 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<Foo>.

We can work around this by creating something like this here:

public class FooIterableAssert
  extends AbstractIterableAssert<FooIterableAssert, Iterable<? extends Foo>, Foo, FooIterableAssert> {

  protected FooIterableAssert(Iterable<? extends Foo> foos, Class<?> selfType) {
    super(foos, selfType);
  }

  @Override
  protected FooAssert toAssert(Foo value, String description) {
    return new FooAssert(value);
  }

  @Override
  protected FooIterableAssert newAbstractIterableAssert(Iterable<? extends Foo> iterable) {
    return new FooIterableAssert(iterable, FooIterableAssert.class);
  }

  public static FooIterableAssert assertThat(List<Foo> 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant