Giter Site home page Giter Site logo

Comments (4)

joel-costigliola avatar joel-costigliola commented on July 4, 2024 1

Thanks for reporting this @laisbento, we'll have a stab at it for the next release !

from assertj.

laisbento avatar laisbento commented on July 4, 2024 1

Hello @joel-costigliola! Thanks for the explanation. I hadn't realized that flatExtracting existed. I've replaced for it in my tests and now everything is working as expected. I'll be using it from now on. :)

from assertj.

joel-costigliola avatar joel-costigliola commented on July 4, 2024

This is not a bug, when extracting multiple values AssertJ returns a list of Tuple, each tuple corresponding to the extracted values of the iterable under test.

The extracting javadoc shows the tuple role:

 // Build a list of TolkienCharacter, a TolkienCharacter has a name, and age and a Race (a specific class)
 // they can be public field or properties, both can be extracted.
 List<TolkienCharacter> fellowshipOfTheRing = new ArrayList<TolkienCharacter>();

 fellowshipOfTheRing.add(new TolkienCharacter("Frodo", 33, HOBBIT));
 fellowshipOfTheRing.add(new TolkienCharacter("Sam", 38, HOBBIT));
 fellowshipOfTheRing.add(new TolkienCharacter("Gandalf", 2020, MAIA));
 fellowshipOfTheRing.add(new TolkienCharacter("Legolas", 1000, ELF));
 fellowshipOfTheRing.add(new TolkienCharacter("Pippin", 28, HOBBIT));
 fellowshipOfTheRing.add(new TolkienCharacter("Gimli", 139, DWARF));
 fellowshipOfTheRing.add(new TolkienCharacter("Aragorn", 87, MAN);
 fellowshipOfTheRing.add(new TolkienCharacter("Boromir", 37, MAN));

 // let's verify 'name' and 'age' of some TolkienCharacter in fellowshipOfTheRing:
 assertThat(fellowshipOfTheRing).extracting("name", "age")
                                .contains(tuple("Boromir", 37),
                                          tuple("Sam", 38),
                                          tuple("Legolas", 1000));

the contains assertion following extracting works on tuples.

In your case, I'm guessing what you wanted to do is to check the elements of the extracted fields, this is possible with flatExtracting that "flattens" the tuples values, here's the javadoc:

 // values are extracted in order and flattened: age1, name1, age2, name2, age3 ...
 assertThat(fellowshipOfTheRing).flatExtracting("age", "name")
                                .contains(33 ,"Frodo",
                                          1000, "Legolas",
                                          87, "Aragorn");

No tuples used with flatExtracting, try this:

    assertThat(testList).flatExtracting("fullNames", "ages")
                        .containsOnlyNulls(); 

from assertj.

joel-costigliola avatar joel-costigliola commented on July 4, 2024

@laisbento I'm closing this issue, but feel free to comment on it, and we'll reopen it if necessary.

from assertj.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.