SimpleTestingServiceLocator

A SimpleServiceLocator subclass designed specifically for use in tests.

This locator provides two key features to simplify testing:

  1. Automatic Mocking: If a service is requested that has not been explicitly registered, this locator will automatically create and return a mock instance for it by calling the abstract createMock function.

  2. Re-registration: Unlike the production locator, this class allows a key to be registered multiple times, overwriting the previous registration. This is useful for setting up different fakes or mocks for different test cases within the same test suite.

Parameters

S

The type of the scope identifier.

scope

The specific scope instance for this locator, which should be a testing-specific scope.

Constructors

Link copied to clipboard
constructor(scope: S)

Properties

Link copied to clipboard
val scope: S

Functions

Link copied to clipboard
inline fun <T : Any> get(): T
fun <T : Any> get(key: KClass<T>): T
Link copied to clipboard
inline fun <T : Any> getOrNull(): T?
fun <T : Any> getOrNull(key: KClass<T>): T?
Link copied to clipboard
inline fun <T : Any> getOrProvide(noinline allowedScopes: (S) -> Boolean, threadSafetyMode: LazyThreadSafetyMode, noinline provider: (S) -> T): T
fun <T : Any> getOrProvide(key: KClass<T>, allowedScopes: (S) -> Boolean, threadSafetyMode: LazyThreadSafetyMode, provider: (S) -> T): T
Link copied to clipboard
inline fun <T : Any> put(threadSafetyMode: LazyThreadSafetyMode, noinline provider: () -> T)
fun <T : Any> put(key: KClass<T>, threadSafetyMode: LazyThreadSafetyMode, provider: () -> T)