public class ExtractingKt
| Modifier and Type | Method and Description |
|---|---|
static <K,T> java.util.List<T> |
extracting(java.util.Collection<? extends K> col,
kotlin.jvm.functions.Function1<? super K,? extends T> extractor)
extracting pulls property values out of a list of objects for typed bulk assertions on properties. |
public static <K,T> java.util.List<T> extracting(java.util.Collection<? extends K> col,
kotlin.jvm.functions.Function1<? super K,? extends T> extractor)
extracting pulls property values out of a list of objects for typed bulk assertions on properties.
The simple example shows how extracting helps with disjunct collection assertions:
extracting(persons){ name }
.shouldContainAll("John Doe", "Samantha Roes")
This is similar to using multiple InspectorsKt.forOne however allows for a more concise notation.
forOne(persons){ it.name shouldBe "John Doe" }
forOne(persons){ it.name shouldBe "Samantha Rose" }
extracting also allows to define complex return types shown in this elaborate example:
extracting(persons){ Pair(name, age) }
.shouldContainAll(
Pair("John Doe", 20),
Pair("Samantha Roes", 19)
)
col - the collection of objects from which to extract the propertiesextractor - the extractor that defines which properties are returnedInspectorsKt.forOne