NetworkMockState
Represents the complete state of network mocking, persisted in DataStore.
This data class encapsulates all runtime state for the network mock feature, including the global mocking toggle and individual endpoint configurations. The state is persisted using DataStore Preferences to survive app restarts.
State Structure
Global Toggle: Master switch to enable/disable all mocking
Endpoint States: Per-endpoint configuration (mock enabled + selected response)
Metadata: Timestamp tracking for state changes
Persistence
State is automatically saved to DataStore when changes are made through the com.worldline.devview.networkmock.core.repository.MockStateRepository:
val repository = MockStateRepository(dataStore)
// Enable global mocking
repository.setGlobalMockingEnabled(true)
// Configure specific endpoint
repository.setEndpointMockState(
key = EndpointKey("my-backend", "staging", "getUser"),
state = EndpointMockState.Mock(responseFile = "getUser-200.json")
)Two-Level Toggle System
The plugin uses a two-level check:
Global Level: If globalMockingEnabled is
false, ALL requests use actual networkEndpoint Level: If global is
true, check individual endpointStates for each request
This allows quick testing with/without mocking while preserving individual configurations.
Environment Resolution
There is no stored "active environment" selection. The environment is derived at runtime by matching the incoming request's hostname against the com.worldline.devview.networkmock.core.model.EnvironmentConfig.url of each environment across all API groups. This allows the app to simultaneously target different environments for different API groups without any manual selection.
Endpoint State Keys
Endpoint states are keyed by "{groupId}-{environmentId}-{endpointId}" to guarantee uniqueness across all combinations. This prevents collisions between API groups that happen to share the same environment ID and endpoint ID:
val key = "my-backend-staging-getUser" // my-backend group, staging environment, getUser endpoint
val state = networkMockState.endpointStates[key]See also
Constructors
Properties
Functions
Gets the mock state for a specific endpoint identified by an EndpointKey.
Gets the mock state for a specific endpoint in a specific group and environment.
Creates a new state with all endpoint mocks reset to use the actual network.
Creates a new state with the specified endpoint state updated.