doc / ch.tutteli.atrium.api.infix.en_GB / feature

feature

infix fun <T, R> Expect<T>.feature(property: KProperty1<in T, R>): FeatureExpect<T, R>

Extracts the property out of the current subject of the assertion, creates a new Expect for it and returns it so that subsequent calls are based on the feature.

Return
The newly created Expect for the given property.

Since
0.12.0

infix fun <T, R> Expect<T>.feature(f: KFunction1<T, R>): FeatureExpect<T, R>

Extracts the value which is returned when calling the method f on the current subject of the assertion, creates a new Expect for it and returns it so that subsequent calls are based on the feature.

Use feature of(...) in case the method requires parameters or in case you want to define an assertion group block for it.

Return
The newly created Expect for the return value of calling the method f on the current subject of the assertion.

Since
0.12.0

infix fun <T, R> Expect<T>.feature(of: Feature<in T, R>): FeatureExpect<T, R>

Extracts a feature out of the current subject of the assertion using the given Feature.extractor, creates a new Expect for it and returns it so that subsequent calls are based on the feature.

Use of(K..., ...) to create a Feature where the first argument is the extractor in form of a KProperty1 or a KFunctionX and potentially the required arguments for a KFunctionX where X > 1.

Note, Feature will be made invariant once Kotlin 1.4 is out and Atrium depends on it (most likely with 1.0.0)

Parameters

of - Use of(K..., ...) to create a Feature where the first argument is the extractor in form of a KProperty1 or a KFunctionX and potentially the required arguments for a KFunctionX where X > 1.

Return
The newly created Expect for the extracted feature.

Since
0.12.0

infix fun <T, R> Expect<T>.feature(of: FeatureWithCreator<in T, R>): Expect<T>

Extracts a feature out of the current subject of the assertion using the given FeatureWithCreator.extractor, creates a new Expect for it, applies an assertion group based on the given FeatureWithCreator.assertionCreator for the feature and returns the initial Expect with the current subject.

Use of(K..., ...) { ... } to create a FeatureWithCreator where the first argument is the extractor in form of a KProperty1 or a KFunctionX, the last an assertionCreator-lambda and the remaining arguments in-between the required arguments in case of a KFunctionX where X > 1.

Note, FeatureWithCreator will be made invariant once Kotlin 1.4 is out and Atrium depends on it (most likely with 1.0.0)

Parameters

of - Use of(K..., ...) { ... } to create a FeatureWithCreator where the first argument is the extractor in form of a KProperty1 or a KFunctionX, the last an assertionCreator-lambda and the remaining arguments in-between the required arguments in case of a KFunctionX where X > 1.

Exceptions

AssertionError - Might throw an AssertionError in case the created AssertionGroup does not hold.

Return
An Expect for the current subject of the assertion.

Since
0.12.0

infix fun <T, R> Expect<T>.feature(provider: MetaFeatureOption<T>.(T) -> MetaFeature<R>): FeatureExpect<T, R>

Extracts a feature out of the current subject of the assertion, based on the given provider, creates a new Expect for it and returns it so that subsequent calls are based on the feature.

Parameters

provider - Creates a MetaFeature where the subject of the assertion is available via implicit parameter it. Usually you use f to create a MetaFeature, e.g. feature { f(it::size) }

Return
The newly created Expect for the extracted feature.

Since
0.12.0

infix fun <T, R> Expect<T>.feature(of: MetaFeatureOptionWithCreator<T, R>): Expect<T>

Extracts a feature out of the current subject of the assertion, based on the given MetaFeatureOptionWithCreator creates a new Expect for it, applies an assertion group based on the given MetaFeatureOptionWithCreator.assertionCreator for the feature and returns the initial Expect with the current subject.

Note that you need to enable the new type inference of Kotlin (or use Kotlin 1.4 and above) in order that Kotlin is able to infer the types. As workaround you can use the overload which expects MetaFeatureOption<T>.(T) -> MetaFeature<R> and use it after the call (import from the package workaround). For instance:

// use
import ch.tutteli.atrium.api.infix.en_GB.workaround.it
expect(person) feature { f(it::age) } it { o toBe 20 }

// instead of (which causes problems with Kotlin < 1.4)
expect(person) feature of({ f(it::age) }) { o toBe 20 }

Parameters

of - Use the function of({ ... }) { ... } to create the MetaFeatureOptionWithCreator where the first argument is a lambda with a MetaFeatureOption as receiver which has to create a MetaFeature where the subject of the assertion is available via implicit parameter it. Usually you use f to create a MetaFeature, e.g. feature of({ f(it::size) }) { o toBe 3 }

Return
An Expect for the current subject of the assertion.

Since
0.12.0