mvrx-mocking / com.airbnb.mvrx.mocking / MockMavericksViewModelConfigFactory

MockMavericksViewModelConfigFactory

open class MockMavericksViewModelConfigFactory : MavericksViewModelConfigFactory

Constructors

<init>

MockMavericksViewModelConfigFactory(applicationContext: Context?, debugMode: Boolean = true, viewModelCoroutineContext: CoroutineContext = EmptyCoroutineContext, stateStoreCoroutineContext: CoroutineContext = EmptyCoroutineContext, subscriptionCoroutineContextOverride: CoroutineContext = EmptyCoroutineContext)

Properties

currentConfigs

val currentConfigs: Map<MavericksStateStore<*>, MockableMavericksViewModelConfig<*>>

mockBehavior

var mockBehavior: MockBehavior

Determines what sort of mocked state store is created when provideConfig is called. This can be changed via withMockBehavior to affect behavior when creating a new Fragment.

Functions

addOnExecuteListener

fun addOnExecuteListener(listener: (MavericksViewModelConfig<*>, MavericksViewModel<*>, BlockExecutions) -> Unit): Unit

Add a lambda that will be invoked whenever MavericksViewModel.execute is used.

buildConfig

open fun <S : MavericksState> buildConfig(viewModel: MavericksViewModel<S>, initialState: S): MavericksViewModelConfig<S>

popMockBehaviorOverride

fun popMockBehaviorOverride(): Unit

pushMockBehaviorOverride

fun pushMockBehaviorOverride(mockBehavior: MockBehavior): Unit

Changes the current MockBehavior of all running ViewModels, if they were created when mockBehavior was non null. This forces the mock behavior to this new value.

fun pushMockBehaviorOverride(behaviorChange: (currentBehavior: MockBehavior) -> MockBehavior): Unit

removeOnExecuteListener

fun removeOnExecuteListener(listener: (MavericksViewModelConfig<*>, MavericksViewModel<*>, BlockExecutions) -> Unit): Unit

withMockBehavior

fun <R> withMockBehavior(mockBehavior: MockBehavior = this.mockBehavior, block: () -> R): R

Any view models created within the block will be given a viewmodel store that was created according to the rules of the given mock behavior. The default value may have been set by a wrapping call to withMockBehavior (ie if multiple calls to withMockBehavior are nested the most recent call can change the behavior of the outer call)