Class Extractors

java.lang.Object
org.assertj.core.extractor.Extractors

public class Extractors extends Object
Extractors factory, providing convenient methods of creating common extractors.

For example:

 assertThat(objectsList).extracting(toStringMethod()).contains("toString 1", "toString 2");
 assertThat(objectsList).extracting(byName("field")).contains("someResult1", "someResult2");
Author:
Mateusz Haligowski
  • Constructor Details

    • Extractors

      public Extractors()
  • Method Details

    • toStringMethod

      public static Function<Object,String> toStringMethod()
      Provides extractor for extracting Object.toString() from any object
      Returns:
      the built Function
    • byName

      public static Function<Object,Object> byName(String fieldOrProperty)
      Provides extractor for extracting single field or property from any object using reflection
      Parameters:
      fieldOrProperty - the name of the field/property to extract
      Returns:
      the built Function
    • byName

      public static Function<Object,Tuple> byName(String... fieldsOrProperties)
      Provides extractor for extracting multiple fields or properties from any object using reflection
      Parameters:
      fieldsOrProperties - the name of the fields/properties to extract
      Returns:
      the built Function
    • resultOf

      public static Function<Object,Object> resultOf(String methodName)
      Provides extractor for extracting values by method name from any object using reflection
      Parameters:
      methodName - the name of the method to execute
      Returns:
      the built Function
    • extractedDescriptionOf

      public static String extractedDescriptionOf(String... itemsDescription)
    • extractedDescriptionOf

      public static String extractedDescriptionOf(Object... items)
    • extractedDescriptionOfMethod

      public static String extractedDescriptionOfMethod(String method)