MockRuleStorage

interface MockRuleStorage

Persistence seam for network MockRules.

The runtime loads the rules once, when they are first needed, off the main thread: on the thread of the first request a rule could answer, or of the first debug API call that reads or changes them. It saves the full set on every mutation, on the thread of the debug API call that made it. Both lists are in the order the rules are tried: the first rule that matches a request answers it. Provide an implementation to survive app restarts (see SharedPreferencesMockRuleStorage); pass null to NetworkDebugTab.create for in-memory-only rules.

An implementation of your own must persist every MockRule property, MockRule.failure too: the compiler does not ask for it, because it has a default, and a failure rule saved without it loads as a rule that answers with its status and body. SharedPreferencesMockRuleStorage persists them all.

Inheritors

Functions

Link copied to clipboard
abstract fun load(): List<MockRule>

Returns the persisted mock rules, or an empty list when none are stored.

Link copied to clipboard
abstract fun save(rules: List<MockRule>)

Persists the full set of rules, replacing any previously stored.