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)
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.
instance
- T: The object to inject mocks/dependencies into.
typeToken
- TypeToken<T>: A TypeToken representing the complete type of instance