-
public final class MavericksMock<V extends MavericksView, Args extends Parcelable>Defines a unique variation of a View's state for testing purposes.
A view is represented completely by:
The arguments used to initialize it
The State classes of all ViewModels used by the View
For proper mocking, the View MUST NOT reference data from any other sources, such as static singletons, dependency injection, shared preferences, etc. All of this should be channeled through the ViewModel and State. Otherwise a mock cannot deterministically and completely be used to test the View.
An exception is Android OS level View state, with things such as scroll and cursor positions. These are not feasible to track in state, and are generally independent and inconsequential in testing.
It is recommended that the "Default" mock state for a view represent the most canonical, complete form of the View. For example, all data loaded, with no empty or null instances.
Other mock variations should test alterations to this "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.
This pattern is encouraged because:
The tools for defining mock variations are designed to enable easy modification of the default
Each mock variant is only one line of code, and is easily maintained
Each variant tests a single edge case
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumMavericksMock.TypeThere are a set of standard mock variants that all Views have. Beyond that users can define custom mock variants.
public classMavericksMock.Companion
-
Field Summary
Fields Modifier and Type Field Description private final Argsargsprivate final List<MockState<V, ?>>statesprivate final BooleanisDefaultInitializationprivate final BooleanisDefaultStateprivate final BooleanisForProcessRecreationprivate final Stringnameprivate final BooleanforInitializationprivate final MavericksMock.Typetype
-
Method Summary
Modifier and Type Method Description final ArgsgetArgs()Returns the arguments that should be used to initialize the Mavericks view. final List<MockState<V, ?>>getStates()The State to set on each ViewModel in the View. final BooleangetIsDefaultInitialization()final BooleangetIsDefaultState()final BooleangetIsForProcessRecreation()final StringgetName()final BooleangetForInitialization()If true, this mock tests the view being created either from arguments or with the viewmodels' default constructor (when args is null). final MavericksMock.TypegetType()final MavericksStatestateForViewModelProperty(KProperty<?> property, Boolean existingViewModel)Find a mocked state value for the given view model property. Booleanequals(Object other)IntegerhashCode()-
-
Method Detail
-
getArgs
final Args getArgs()
Returns the arguments that should be used to initialize the Mavericks view. If null, the view models will be initialized purely with the mock states instead.
-
getStates
final List<MockState<V, ?>> getStates()
The State to set on each ViewModel in the View. There should be a one to one match.
-
getIsDefaultInitialization
final Boolean getIsDefaultInitialization()
-
getIsDefaultState
final Boolean getIsDefaultState()
-
getIsForProcessRecreation
final Boolean getIsForProcessRecreation()
-
getForInitialization
final Boolean getForInitialization()
If true, this mock tests the view being created either from arguments or with the viewmodels' default constructor (when args is null).
-
getType
final MavericksMock.Type getType()
-
stateForViewModelProperty
final MavericksState stateForViewModelProperty(KProperty<?> property, Boolean existingViewModel)
Find a mocked state value for the given view model property.
If null is returned it means the initial state should be created through the default mavericks mechanism of arguments.
-
-
-
-