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

Mockspresso

interface Mockspresso

Main mockspresso interface

Types

Builder

interface Builder

Class used to build Mockspresso and Mockspresso.Rule instances.

Rule

interface Rule : Mockspresso, MethodRule

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

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.

Extension Functions

createNew

fun <T : Any> Mockspresso.createNew(): T

Create a real object of type T injected with mockspresso dependencies.

getDependencyOf

fun <T : Any> Mockspresso.getDependencyOf(qualifier: Annotation? = null): T?

Get a dependency (creating a new mock, if needed) from mockspresso.

injectType

fun <T : Any> Mockspresso.injectType(instance: T): Unit

Inject an existing object with mockspresso dependencies. Field and method injection will be performed (assuming the injector of this mockspresso instance supports it). Uses a reified type and includes a TypeToken in the method call, so will work with generics.

Inheritors

Rule

interface Rule : Mockspresso, MethodRule

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