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

Builder

interface Builder

Class used to build Mockspresso and Mockspresso.Rule instances.

Functions

build

abstract fun build(): Mockspresso

buildRule

abstract fun buildRule(): Mockspresso.Rule

dependency

abstract fun <T : Any!, V : T> dependency(clazz: Class<T>, value: V?): Mockspresso.Builder
abstract fun <T : Any!, V : T> dependency(typeToken: TypeToken<T>, value: V?): Mockspresso.Builder
abstract fun <T : Any!, V : T> dependency(key: DependencyKey<T>, value: V?): Mockspresso.Builder

Apply a specific instance of an object as a mockspresso dependency.

dependencyProvider

abstract fun <T : Any!, V : T> dependencyProvider(clazz: Class<T>, value: ObjectProvider<V>): Mockspresso.Builder
abstract fun <T : Any!, V : T> dependencyProvider(typeToken: TypeToken<T>, value: ObjectProvider<V>): Mockspresso.Builder
abstract fun <T : Any!, V : T> dependencyProvider(key: DependencyKey<T>, value: ObjectProvider<V>): Mockspresso.Builder

Apply a specific instance of an object as a mockspresso dependency.

injector

abstract fun injector(injectionConfig: InjectionConfig): Mockspresso.Builder

Apply a InjectionConfig to this builder, which tells mockspresso how to create real objects.

innerRule

abstract fun innerRule(testRule: TestRule): Mockspresso.Builder
abstract fun innerRule(methodRule: MethodRule): Mockspresso.Builder

Treat the resulting Mockspresso.Rule as a RuleChain, and wrap the supplied testRule as an innerRule to mockspresso. Rules are processed in the order they are added to the builder. So the first innerRule added will be the outer-most innerRule.

mocker

abstract fun mocker(mockerConfig: MockerConfig): Mockspresso.Builder

Apply a MockerConfig to this builder, which tells mockspresso how to create a mock and how they are annotated.

outerRule

abstract fun outerRule(testRule: TestRule): Mockspresso.Builder
abstract fun outerRule(methodRule: MethodRule): Mockspresso.Builder

Treat the resulting Mockspresso.Rule as a RuleChain, and wrap it using the supplied testRule as an outerRule. Rules are processed in the order they are added to the builder. So the first outerRule added will be the outermost-rule.

plugin

abstract fun plugin(plugin: MockspressoPlugin): Mockspresso.Builder

Apply a MockspressoPlugin to this builder

realObject

abstract fun <T : Any!> realObject(objectClass: Class<T>): Mockspresso.Builder

Instruct mockspresso to create a real object for the provided dependency key. Convenience method, equivalent to calling realObject(DependencyKey.of(objectClass), objectClass);

abstract fun <T : Any!> realObject(objectToken: TypeToken<T>): Mockspresso.Builder

Instruct mockspresso to create a real object for the provided dependency key. Convenience method, equivalent to calling realObject(DependencyKey.of(objectToken), objectToken);

abstract fun <T : Any!> realObject(keyAndImplementation: DependencyKey<T>): Mockspresso.Builder

Instruct mockspresso to create a real object for the provided dependency key. Convenience method, equivalent to calling realObject(keyAndImplementation, keyAndImplementation.typeToken);

abstract fun <T : Any!> realObject(key: DependencyKey<T>, implementationClass: Class<out T>): Mockspresso.Builder
abstract fun <T : Any!> realObject(key: DependencyKey<T>, implementationToken: TypeToken<out T>): Mockspresso.Builder

Instruct mockspresso to create a real object (of type implementationClass) for the provided dependency key.

specialObjectMaker

abstract fun specialObjectMaker(specialObjectMaker: SpecialObjectMaker): Mockspresso.Builder

Apply a SpecialObjectMaker to this builder, which tells mockspresso how it should create object types that should not be mocked by default.

testResources

abstract fun testResources(objectWithResources: Any): Mockspresso.Builder

Scans the included objectWithResources for fields annotated with @Mock and @RealObject, then prepares them and adds them to our dependency map. Will also call any methods annotated with org.junit.Before during the initialization process, and any methods annotated with org.junit.After during the teardown process. Don't pass the actual test class to this method, as it will result in multiple calls to your @Before and @After methods. Instead use #testResourcesWithoutLifecycle(Object)

testResourcesWithoutLifecycle

abstract fun testResourcesWithoutLifecycle(objectWithResources: Any): Mockspresso.Builder

Scans the included objectWithResources for fields annotated with @Mock and @RealObject, then prepares them and adds them to our dependency map. Mockspresso will not call any methods on objects added via this method.

Extension Functions

dependencyOf

fun <T : Any> Mockspresso.Builder.dependencyOf(qualifier: Annotation? = null, value: () -> T?): Mockspresso.Builder

Apply a specific instance of an object as a mockspresso dependency. Kotlin alias for Mockspresso.Builder.dependencyProvider.

realClassOf

fun <BIND_AND_IMPL : Any> Mockspresso.Builder.realClassOf(qualifier: Annotation? = null): Mockspresso.Builder

Instruct mockspresso to create a real object and bind with a dependencyKey of its own concrete type Convenience method for realImplOf when both BIND and IMPL are the same type

realImplOf

fun <BIND : Any, IMPL : BIND> Mockspresso.Builder.realImplOf(qualifier: Annotation? = null): Mockspresso.Builder

Instruct mockspresso to create a real object (of type IMPL) to be bound using a dependency key of type BIND. Kotlin alias for Mockspresso.Builder.realObject