TestingServiceLocator
A ScopedServiceLocator subclass designed specifically for use in tests.
This locator provides two key features to simplify testing:
Automatic Mocking: If a service is requested that has not been explicitly registered, this locator will automatically create and return a mock instance by calling the abstract createMock function.
Re-registration: Unlike a 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.
Parameters
S
The type of the scope identifier.
scope
The specific scope instance for this locator, which should be a testing-specific scope.
Functions
Link copied to clipboard
Link copied to clipboard
inline fun <T : Any> getOrProvide(noinline allowedScopes: (S) -> Boolean, threadSafetyMode: LazyThreadSafetyMode, noinline provider: () -> T): T
Link copied to clipboard
override fun <T : Any, PutParams> onInvalidScope(key: ServiceKey<T, *, *, PutParams>, putParams: PutParams): ServiceEntry<T>
Called when getOrProvide is attempted for a specified key in a disallowed scope.