Class ObjectAssert<ACTUAL>

    • Method Detail

      • extracting

        @SafeVarargs
        public final AbstractListAssert<?,​List<?>,​Object,​ObjectAssert<Object>> extracting​(Function<? super ACTUAL,​?>... extractors)
        Description copied from class: AbstractObjectAssert
        Uses the given Functions to extract the values from the object under test into a list, this new list becoming the object under test.

        If the given Functions extract the id, name and email values then the list will contain the id, name and email values of the object under test, you can then perform list assertions on the extracted values.

        Example:

         // Create frodo, setting its name, age and Race (Race having a name property)
         TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);
        
         // let's verify Frodo's name, age and race name:
         assertThat(frodo).extracting(TolkienCharacter::getName,
                                      character -> character.age, // public field
                                      character -> character.getRace().getName())
                          .containsExactly("Frodo", 33, "Hobbit");

        Note that the order of extracted values is consistent with the order of given extractor functions.

        Overrides:
        extracting in class AbstractObjectAssert<ObjectAssert<ACTUAL>,​ACTUAL>
        Parameters:
        extractors - the extractor functions to extract values from the Object under test.
        Returns:
        a new assertion object whose object under test is the list containing the extracted values