MockspressoProperties

interface MockspressoProperties

An interface that represents a MockspressoInstance that has not yet been fully constructed/ensured. It allows us to make changes to the graph while also leveraging kotlin's delegated properties to grab lazy references from it (that will be available after the MockspressoInstance under the hood has been ensured).

Most of the methods in the interface should be used in conjunction with Kotlin's delegated properties (aka "by") syntax.

Functions

Link copied to clipboard
abstract fun addDynamicObjectMaker(dynamicMaker: DynamicObjectMaker)

Adds a DynamicObjectMaker to this MockspressoInstance. A DynamicObjectMaker gets a chance to supply any un-cached/undefined dependency before the request goes to the FallbackObjectMaker. This enables mockspresso plugins supply dependencies based on properties other than concrete types (i.e. generic types, class annotations, etc.). It also allows for "default" instances for bindings, which can be overridden by an explicit dependency.

Link copied to clipboard
abstract fun <T> dependency(key: DependencyKey<T>, provider: Dependencies.() -> T): Lazy<T>

Register a dependency provided by provider, bound in the mockspresso graph with key and return a Lazy of that object.

Link copied to clipboard
abstract fun <T> findDependency(key: DependencyKey<T>): Lazy<T>

Find an existing dependency in the underlying mockspresso instance (bound with key) and return a Lazy for it.

Link copied to clipboard
abstract fun <BIND, IMPL : BIND> interceptRealImplementation(    key: DependencyKey<BIND>,     implementationToken: TypeToken<IMPL>,     interceptor: (IMPL) -> IMPL = { it }): Lazy<IMPL>

Register a request to create a real object of type implementationToken bound in the mockspresso graph with key. The supplied interceptor lambda will be called when the real object is created and allows the test code to wrap the newly constructed real object before it's used. This enables the mock-support plugins to include spy support.

Link copied to clipboard
abstract fun onSetup(cmd: (MockspressoInstance) -> Unit)

Add a callback that will fire when the MockspressoInstance is fully instantiated/ensured.

Link copied to clipboard
abstract fun onTeardown(cmd: () -> Unit)

Add a callback that will fire when/if the MockspressoInstance is eventually torn down. (Automatic tear-down is not supported by default but can be configured using plugins).

Inheritors

Link copied to clipboard

Extensions

Link copied to clipboard
inline fun <T> MockspressoProperties.dependency(qualifier: Annotation? = null, noinline provider: () -> T): Lazy<T>

Register a dependency provided by provider, bound in the mockspresso graph with a dependencyKey made from type T and qualifier.

Link copied to clipboard
inline fun <BIND, IMPL : BIND> MockspressoProperties.fake(qualifier: Annotation? = null, noinline provider: () -> IMPL): Lazy<IMPL>

Register a dependency provided by provider that is of type IMPL but bound in the mockspresso graph with a dependencyKey made from type BIND and qualifier. Returns a Lazy with access to that dependency as type IMPL

Link copied to clipboard
inline fun <T> MockspressoProperties.findDependency(qualifier: Annotation? = null): Lazy<T>

Find an existing dependency in the underlying mockspresso instance (bound with a dependencyKey of type T + qualifier) and return a Lazy for access to it.

Link copied to clipboard
inline fun <BIND, IMPL : BIND> MockspressoProperties.realImplementation(qualifier: Annotation? = null, noinline init: IMPL.() -> Unit = { }): Lazy<IMPL>

Register a request to create a real object of type IMPL bound in the mockspresso graph with a dependencyKey made from type BIND and qualifier.

Link copied to clipboard
inline fun <T> MockspressoProperties.realInstance(qualifier: Annotation? = null, noinline init: T.() -> Unit = { }): Lazy<T>

Register a request to create a real object of type T bound in the mockspresso graph with a dependencyKey made from type T and qualifier.