Feature: Generate IterableAsserts for all generated Asserts

Aperta
#219 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java
Ambito
tooling

Direzione di ricerca

Inizia tracciando il generatore di assertion che crea FooAssert, quindi esamina come vengono prodotti ListAssert e i punti di ingresso assertThat. Confronta la forma richiesta di FooIterableAssert con l’output generato attualmente e decidi come dovrebbero essere esposte le assertion iterable generate. Il lavoro è completato quando le assertion generate supportano l’uso richiesto di singleElement().hasName("Fool") senza classi wrapper manuali.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Java
Stelle
72
Fork
47
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di assertj/assertj-generator

Tutte le issue di assertj/assertj-generator

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.