MockspressoBuilder

interface MockspressoBuilder

Builds a mockspresso Mockspresso instance that is lazily instantiated under the hood.

Functions

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

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 build(): Mockspresso

Build a Mockspresso object, but the actual MockspressoInstance will not be created immediately and will still be mutable until its ensured or its dependencies are accessed.

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

Register a dependency provided by provider, bound in the mockspresso graph with key.

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

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 makeFallbackObjectsWith(fallbackMaker: FallbackObjectMaker): MockspressoBuilder

Define how this MockspressoInstance will make fallback objects (i.e. dependencies that have not been explicitly registered/cached within this instance). Usually this should be supplied by one of the mocking support plugins (i.e. plugins-mockito or plugins-mockk).

Link copied to clipboard
abstract fun makeRealObjectsWith(realMaker: RealObjectMaker): MockspressoBuilder

Define how this MockspressoInstance will construct real objects. By default, mockspresso will reflectively call the primary constructor of a given class and pass appropriate dependencies to it.

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

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

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

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).

Link copied to clipboard
abstract fun testResources(maker: (MockspressoProperties) -> Unit): MockspressoBuilder

A utility method intended to enable the creation of shared "test resources" that can add to, pull from and define some kind of functionality within the injected dependencies of the mockspresso graph.

Extensions

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

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> MockspressoBuilder.realImplementation(qualifier: Annotation? = null, noinline init: IMPL.() -> Unit = { }): MockspressoBuilder

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> MockspressoBuilder.realInstance(qualifier: Annotation? = null, noinline init: T.() -> Unit = { }): MockspressoBuilder

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.