Package com.episode6.mockspresso2

Types

Link copied to clipboard
interface Mockspresso : MockspressoInstance, MockspressoProperties

The main interface returned from a MockspressoBuilder. It implements MockspressoInstance but under the hood, the instance it implements is lazily initiated and doesn't become ensured/immutable until its dependencies are accessed.

Link copied to clipboard
interface MockspressoBuilder

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

Link copied to clipboard
interface MockspressoInstance

A fully-constructed instance of a Mockspresso dependency map.

Link copied to clipboard
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).

Functions

Link copied to clipboard
inline fun <T> MockspressoInstance.createNow(qualifier: Annotation? = null): T

Create a new real object of type T using the rules and dependencies in the mockspresso instance.

Link copied to clipboard
inline fun <T> MockspressoBuilder.dependency(qualifier: Annotation? = null, noinline provider: () -> T): MockspressoBuilder
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 <T> MockspressoInstance.findNow(qualifier: Annotation? = null): T

Find an existing dependency in this mockspresso instance of type T with the provided qualifier. If the dependency hasn't been cached or constructed then it will be generated on the fly and cached from that point forward. If the binding hasn't been declared in this mockspresso instance, then a fallback will be generated.

Link copied to clipboard
inline fun <BIND, IMPL : BIND> MockspressoBuilder.realImplementation(qualifier: Annotation? = null, noinline init: IMPL.() -> Unit = { }): MockspressoBuilder
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> MockspressoBuilder.realInstance(qualifier: Annotation? = null, noinline init: T.() -> Unit = { }): MockspressoBuilder
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.