Package 

Object MockableMavericks

    • Method Detail

      • initialize

         final Unit initialize(Context applicationContext)

        Initializes the required Mavericks.viewModelConfigFactory and sets ViewModel debug and mock behavior for the app.

        If the application was built with the debuggable flag enabled in its Android Manifest then this will add plugins to Mavericks that enable working with mock State. This is useful for both manual and automated testing of development builds.

        This function is a shortcut instead of setting each property in this object individually. For custom control you can set properties directly instead.

        It is safe to call this in both debug and production builds and it will take care of the correct behavior for you.

        The context will be used to automatically register a broadcast receiver for each ViewModel created in the app with ViewModelStatePrinter so that the state printing system is automatically enabled.

        Calling this subsequent times will replace the plugins with new instances.

      • initialize

         final Unit initialize(Boolean mocksEnabled, Boolean debugMode, Context applicationContext, CoroutineContext viewModelCoroutineContext, CoroutineContext stateStoreCoroutineContext, CoroutineContext subscriptionCoroutineContextOverride)

        Initializes the required Mavericks.viewModelConfigFactory and sets ViewModel debug and mock behavior for the app.

        Choose whether to enable Mavericks mocking tools. This is useful for both manual and automated testing of development builds.

        This function is a shortcut instead of setting each property in this object individually. For custom control you can set properties directly instead.

        The context will be used to automatically register a broadcast receiver for each ViewModel created in the app with ViewModelStatePrinter so that the state printing system is automatically enabled.

        Calling this subsequent times will replace the plugins with new instances.

      • setScriptableState

         final <VM extends MavericksViewModel<S>, S extends MavericksState> Unit setScriptableState(VM viewModel, S state)

        If the given viewmodel has a state store that implements ScriptableStateStore then this function can be used to set the next state via ScriptableStateStore.next.

        It is an error to call this if the store is not scriptable.

      • setState

         final <VM extends MavericksViewModel<S>, S extends MavericksState> Unit setState(VM viewModel, S state)

        A helper to set a state on a view model via MavericksStateStore.set.

        This may not work if the ViewModel's state store is mocked or configured to not accept state changes, and it is the responsibility of the caller to make sure that the state store can accept changes.

        Additionally, it is the responsibility of the caller to understand the type of state store the view model is using, and whether the state change will take affect synchronously or asynchronously depending on the state store implementation.

        See setScriptableState if you want to force a state on a ScriptableStateStore that would otherwise not allow state changes.

      • getMockStateHolder

         final MockStateHolder getMockStateHolder()

        This global instance enables mock states to be forced onto ViewModels as they are created. This enable easy testing.

        The instance is exposed publicly so references to mocked views can be cleared after a test completes.

      • getMockPrinterConfiguration

         final MockPrinterConfiguration getMockPrinterConfiguration()

        Configuration for how mock state is printed.

        The Mavericks mocking system allows you to generate a reproduction of a ViewModel's state. For any MavericksState instance that a ViewModel has, Mavericks can generate a file containing code to completely reconstruct that state.

        This generated code can then be used to reconstruct States that can be used during testing. The scripts in the MvRx/mock_generation folder are used to interact with the device to pull the resulting mock files.

        enableMockPrinterBroadcastReceiver must be enabled for this to work.

        See MavericksMockPrinter See https://github.com/airbnb/MvRx/wiki/Mock-Printer

      • setMockPrinterConfiguration

         final Unit setMockPrinterConfiguration(MockPrinterConfiguration mockPrinterConfiguration)

        Configuration for how mock state is printed.

        The Mavericks mocking system allows you to generate a reproduction of a ViewModel's state. For any MavericksState instance that a ViewModel has, Mavericks can generate a file containing code to completely reconstruct that state.

        This generated code can then be used to reconstruct States that can be used during testing. The scripts in the MvRx/mock_generation folder are used to interact with the device to pull the resulting mock files.

        enableMockPrinterBroadcastReceiver must be enabled for this to work.

        See MavericksMockPrinter See https://github.com/airbnb/MvRx/wiki/Mock-Printer