-
- All Implemented Interfaces:
-
com.airbnb.mvrx.mocking.DataClassSetDsl
public final class SingleViewModelMockBuilder<V extends MockableMavericksView, Args extends Parcelable, S extends MavericksState> extends MockBuilder<V, Args>
Provides a DSL for defining variations to the default mock state.
-
-
Field Summary
Fields Modifier and Type Field Description private final <ERROR CLASS>mocksprivate final List<List<MavericksMock<V, out Args>>>mockGroups
-
Method Summary
Modifier and Type Method Description <ERROR CLASS>getMocks()A list of mocks to use when testing a view. List<List<MavericksMock<V, out Args>>>getMockGroups()final Unitstate(String name, Function1<Args, Args> args, Function1<S, S> stateBuilder)Provide a state object via the lambda for the view model being mocked. final <T extends Any, A extends Async<T>> UnitstateForLoadingAndFailure(S state, Function1<S, KProperty0<A>> asyncPropertyBlock)Helper to mock the loading and failure state of an Async property on your state. -
Methods inherited from class com.airbnb.mvrx.mocking.SingleViewModelMockBuilder
args -
Methods inherited from class com.airbnb.mvrx.mocking.MockBuilder
invoke, set, setEmpty, setFalse, setLoading, setNetworkFailure, setNull, setTrue, setZero, success, validate, with -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
getMocks
<ERROR CLASS> getMocks()
A list of mocks to use when testing a view. Each mock represents a unique state to be tested.
At least one of mocks or mockGroups must be implemented.
-
getMockGroups
List<List<MavericksMock<V, out Args>>> getMockGroups()
-
state
final Unit state(String name, Function1<Args, Args> args, Function1<S, S> stateBuilder)
Provide a state object via the lambda for the view model being mocked. The receiver of the lambda is the default state provided in the top level mock method. For simplicity you can modify the receiver directly.
The DSL provided by DataClassSetDsl can be used for simpler state modification.
Mock variations should test alterations to the "default" state, with each variant testing a minimal difference (ideally only one change). For example, a variant may test that a single property is null or empty.
- Parameters:
name- Describes the UI the state puts the view in.args- The arguments that should be provided to the view.stateBuilder- A lambda whose return object is the state for this mock.
-
stateForLoadingAndFailure
final <T extends Any, A extends Async<T>> Unit stateForLoadingAndFailure(S state, Function1<S, KProperty0<A>> asyncPropertyBlock)
Helper to mock the loading and failure state of an Async property on your state. Creates two different mocked states stemmed from the given state - one where the async property is set to Loading and one where it is set to Fail.
-
-
-
-