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

inject

abstract fun inject(@NotNull 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)

Parameters

instance - Any: The object to inject mocks/dependencies into.

abstract fun <T : Any!> inject(@NotNull instance: T, @NotNull 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.

Parameters

instance - T: The object to inject mocks/dependencies into.

typeToken - TypeToken<T>: A TypeToken representing the complete type of instance

- The Type of instance param