-
public final class MockStateHolderUsed to mock the initial state value of a viewmodel.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classMockStateHolder.ViewModelDelegateInfo
-
Constructor Summary
Constructors Constructor Description MockStateHolder()
-
Method Summary
Modifier and Type Method Description final <V extends MockableMavericksView, A extends Parcelable> UnitsetMock(MockableMavericksView view, MavericksMock<V, A> mockInfo)Set mock data for a view reference. final UnitclearMock(MockableMavericksView view)Clear the stored mock info for the given view. final UnitclearAllMocks()final <S extends MavericksState> SgetMockedState(MockableMavericksView view, KProperty<?> viewModelProperty, Boolean existingViewModel, Class<S> stateClass, Boolean forceMockExistingViewModel)Get the mocked state for the viewmodel on the given view. final <VM extends MavericksViewModel<S>, S extends MavericksState> UnitaddViewModelDelegate(MockableMavericksView view, Boolean existingViewModel, KProperty<?> viewModelProperty, lifecycleAwareLazy<VM> viewModelDelegate)-
-
Method Detail
-
setMock
final <V extends MockableMavericksView, A extends Parcelable> Unit setMock(MockableMavericksView view, MavericksMock<V, A> mockInfo)
Set mock data for a view reference. The mocks will be used to provide initial state when the view models are initialized as the view is started.
-
clearMock
final Unit clearMock(MockableMavericksView view)
Clear the stored mock info for the given view. This should be called after the view is done initializing itself with the mock. This should be done to prevent leaking references to the view and its mocks.
-
clearAllMocks
final Unit clearAllMocks()
-
getMockedState
final <S extends MavericksState> S getMockedState(MockableMavericksView view, KProperty<?> viewModelProperty, Boolean existingViewModel, Class<S> stateClass, Boolean forceMockExistingViewModel)
Get the mocked state for the viewmodel on the given view. Returns null if no mocked state has been set - this is valid if a view under mock contains nested views that are not under mock.
The mock state is not cleared after being retrieved because if the view has multiple viewmodels they will each need to access this separately.
If null is returned it means that the view should be initialized from its arguments. This will only happen if this is not an "existing" view model.
- Parameters:
forceMockExistingViewModel- If true, and if existingViewModel is true, then we expect that no mock state has been set for this viewmodel and we should instead manually retrieve the default mock state from the View and force that as the mock state to use.
-
addViewModelDelegate
final <VM extends MavericksViewModel<S>, S extends MavericksState> Unit addViewModelDelegate(MockableMavericksView view, Boolean existingViewModel, KProperty<?> viewModelProperty, lifecycleAwareLazy<VM> viewModelDelegate)
-
-
-
-