mockspresso-api / com.episode6.hackit.mockspresso / Mockspresso / Rule

Rule

interface Rule : Mockspresso, MethodRule

An implementation of Mockspresso that also implements JUnit's MethodRule.

Inherited Functions

buildUpon

abstract fun buildUpon(): Mockspresso.Builder

Build upon this mockspresso instance's configuration and dependencies.

create

abstract fun <T : Any!> create(clazz: Class<T>): T
abstract fun <T : Any!> create(typeToken: TypeToken<T>): T

Create a real object injected with mockspresso dependencies.

getDependency

abstract fun <T : Any!> getDependency(key: DependencyKey<T>): T

Get a dependency (creating a new mock, if needed) from mockspresso. We purposefully don't annotate the return-type here NotNull because nulls are theoretically allowed dependencies (they just must be mapped explicitly). So kotlin users must assume nullability via platform-type.

inject

abstract fun inject(instance: Any): Unit

Inject an existing object with mockspresso dependencies. Field and method injection will be performed (assuming the injector of this mockspresso instance supports it)

abstract fun <T : Any!> inject(instance: T, typeToken: TypeToken<T>): Unit

An alternative signature to #inject(Object). Use this method and pass an explic type token if injecting a pre- constructed generic object that injects parameters defined as TypeVariables. I.e. class MySampleGeneric<V> { @Inject V myInjectedVariable; } Without the typeToken represented the object being injected, we're unable to infer the correct type for the generic paremeter, and may wind up providing a mock Object instead of the correct mapping.