MockLocus class
Mock implementation of Locus for unit testing.
This class provides a complete simulation of the Locus SDK without requiring platform channels or real location services.
Example:
final mock = MockLocus();
// Configure initial state
mock.setMockState(GeolocationState(
enabled: true,
isMoving: false,
odometer: 0,
));
// Emit mock locations
mock.emitLocation(Location.mock(
latitude: 37.4219,
longitude: -122.084,
));
- Implemented types
Constructors
- MockLocus({GeolocationState? initialState, Config? initialConfig})
- Creates a new MockLocus instance.
Properties
-
activityStream
→ Stream<
Activity> -
no setteroverride
- adaptiveTrackingConfig → AdaptiveTrackingConfig?
-
no setteroverride
- config → Config
-
The current mock configuration.
no setter
-
connectivityStream
→ Stream<
ConnectivityChangeEvent> -
no setteroverride
- currentTrackingProfile → TrackingProfile?
-
no setteroverride
-
enabledStream
→ Stream<
bool> -
no setteroverride
- errorRecoveryConfig → ErrorRecoveryConfig?
-
Last configured error recovery settings.
no setter
- errorRecoveryManager → ErrorRecoveryManager?
-
no setteroverride
-
errorStream
→ Stream<
LocusError> ? -
no setteroverride
-
events
→ Stream<
GeolocationEvent> -
no setteroverride
-
geofenceStream
→ Stream<
GeofenceEvent> -
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
-
heartbeatStream
→ Stream<
Location> -
no setteroverride
-
httpStream
→ Stream<
HttpEvent> -
no setteroverride
- isForeground → bool
-
no setteroverride
- isReady → bool
-
Whether ready has been called.
no setter
- isSignificantChangeMonitoringActive → bool
-
no setteroverride
-
locationStream
→ Stream<
Location> -
no setteroverride
-
methodCalls
→ List<
String> -
List of method calls made to this mock.
no setter
-
motionChangeStream
→ Stream<
Location> -
no setteroverride
-
polygonGeofenceEvents
→ Stream<
PolygonGeofenceEvent> -
no setteroverride
-
powerSaveStream
→ Stream<
bool> -
no setteroverride
-
powerStateStream
→ Stream<
PowerStateChangeEvent> -
no setteroverride
-
privacyZoneEvents
→ Stream<
PrivacyZoneEvent> -
Stream of privacy zone change events.
no setteroverride
-
providerStream
→ Stream<
ProviderChangeEvent> -
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
significantChangeStream
→ Stream<
SignificantChangeEvent> ? -
no setteroverride
- spoofDetectionConfig → SpoofDetectionConfig?
-
no setteroverride
- syncBodyBuilder → SyncBodyBuilder?
-
The current sync body builder (for test verification).
no setter
- syncPolicy → SyncPolicy?
-
Returns the last sync policy configured on the mock.
no setter
- trackingAutomationEnabled → bool
-
Whether tracking automation is enabled.
no setter
-
tripEvents
→ Stream<
TripEvent> -
no setteroverride
-
workflowEvents
→ Stream<
GeofenceWorkflowEvent> -
no setteroverride
Methods
-
addGeofence(
Geofence geofence) → Future< bool> -
override
-
addGeofences(
List< Geofence> geofences) → Future<bool> -
Adds multiple geofences.
override
-
addPolygonGeofence(
PolygonGeofence polygon) → Future< bool> -
override
-
addPolygonGeofences(
List< PolygonGeofence> polygons) → Future<int> -
override
-
addPrivacyZone(
PrivacyZone zone) → Future< void> -
Adds a privacy zone where location data will be obfuscated or excluded.
override
-
addPrivacyZones(
List< PrivacyZone> zones) → Future<void> -
Adds multiple privacy zones.
override
-
analyzeForSpoofing(
Location location, {bool? isMockProvider}) → SpoofDetectionEvent? -
override
-
applyRemoteCommand(
RemoteCommand command) → Future< bool> -
override
-
calculateAdaptiveSettings(
) → Future< AdaptiveSettings> -
override
-
changePace(
bool isMoving) → Future< bool> -
override
-
clearGeofenceWorkflows(
) → void -
override
-
clearHeadersCallback(
) → void -
override
-
clearMethodCalls(
) → void - Clears the method call history.
-
clearQueue(
) → Future< void> -
Clears the queue.
override
-
clearSyncBodyBuilder(
) → void -
Clears the sync body builder callback.
override
-
clearTrackingProfiles(
) → void -
override
-
destroy(
) → Future< void> -
override
-
destroyLocations(
) → Future< bool> -
override
-
dispose(
) → void - Disposes all stream controllers.
-
emitActivityChange(
Activity activity) → void - Emits a mock activity change.
-
emitConnectivityChange(
ConnectivityChangeEvent event) → void - Emits a mock connectivity change.
-
emitEnabledChange(
bool enabled) → void - Emits an enabled change event.
-
emitGeofenceEvent(
GeofenceEvent event) → void - Emits a mock geofence event.
-
emitHeartbeat(
Location location) → void - Emits a mock heartbeat.
-
emitHttpEvent(
HttpEvent event) → void - Emits a mock HTTP event.
-
emitLocation(
Location location) → void - Emits a mock location to all location listeners.
-
emitMotionChange(
Location location) → void - Emits a mock motion change event.
-
emitPolygonGeofenceEvent(
PolygonGeofenceEvent event) → void - Emits a mock polygon geofence event.
-
emitPowerSaveChange(
bool isPowerSaveMode) → void - Emits a power save mode change event.
-
emitPowerStateChange(
PowerStateChangeEvent event) → void - Emits a power state change event.
-
emitProviderChange(
ProviderChangeEvent event) → void - Emits a mock provider change.
-
emitTripEvent(
TripEvent event) → void - Emits a trip event.
-
enqueue(
Map< String, dynamic> payload, {String? type, String? idempotencyKey}) → Future<String> -
Enqueues a custom payload.
override
-
estimateBatteryRunway(
) → Future< BatteryRunway> -
override
-
evaluateSyncPolicy(
{required SyncPolicy policy}) → Future< SyncDecision> -
override
-
geofenceExists(
String identifier) → Future< bool> -
override
-
getBatteryStats(
) → Future< BatteryStats> -
override
-
getCurrentPosition(
{int? samples, int? timeout, int? maximumAge, bool? persist, int? desiredAccuracy, Map< String, dynamic> ? extras}) → Future<Location> -
override
-
getDiagnostics(
) → Future< DiagnosticsSnapshot> -
override
-
getGeofence(
String identifier) → Future< Geofence?> -
override
-
getGeofences(
) → Future< List< Geofence> > -
override
-
getLocations(
{int? limit}) → Future< List< Location> > -
override
-
getLocationSummary(
{DateTime? date, LocationQuery? query}) → Future< LocationSummary> -
override
-
getLog(
) → Future< List< LogEntry> > -
override
-
getPolygonGeofence(
String identifier) → Future< PolygonGeofence?> -
override
-
getPolygonGeofences(
) → Future< List< PolygonGeofence> > -
override
-
getPowerState(
) → Future< PowerState> -
override
-
getPrivacyZone(
String identifier) → Future< PrivacyZone?> -
Gets a privacy zone by identifier.
override
-
getPrivacyZones(
) → Future< List< PrivacyZone> > -
Gets all registered privacy zones.
override
-
getQueue(
{int? limit}) → Future< List< QueueItem> > -
Gets the queue.
override
-
getState(
) → Future< GeolocationState> -
override
-
getTripState(
) → TripState? -
override
-
getWorkflowState(
String workflowId) → GeofenceWorkflowState? -
override
-
handleError(
LocusError error) → Future< RecoveryAction> -
override
-
invokeSyncBodyBuilder(
List< Location> locations, JsonMap extras) → Future<JsonMap?> - Invokes the sync body builder if set (for testing).
-
isInActiveGeofence(
) → Future< bool> -
override
-
isTracking(
) → Future< bool> -
override
-
locationAnomalies(
{LocationAnomalyConfig config = const LocationAnomalyConfig()}) → Stream< LocationAnomaly> -
override
-
locationQuality(
{LocationQualityConfig config = const LocationQualityConfig()}) → Stream< LocationQuality> -
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onActivityChange(
void callback(Activity), {Function? onError}) → StreamSubscription< Activity> -
override
-
onConnectivityChange(
void callback(ConnectivityChangeEvent), {Function? onError}) → StreamSubscription< ConnectivityChangeEvent> -
override
-
onEnabledChange(
void callback(bool), {Function? onError}) → StreamSubscription< bool> -
override
-
onGeofence(
void callback(GeofenceEvent), {Function? onError}) → StreamSubscription< GeofenceEvent> -
override
-
onGeofencesChange(
void callback(dynamic), {Function? onError}) → StreamSubscription -
override
-
onHeartbeat(
void callback(Location), {Function? onError}) → StreamSubscription< Location> -
override
-
onHttp(
void callback(HttpEvent), {Function? onError}) → StreamSubscription< HttpEvent> -
override
-
onLocation(
void callback(Location), {Function? onError}) → StreamSubscription< Location> -
override
-
onLocationAnomaly(
void callback(LocationAnomaly anomaly), {LocationAnomalyConfig config = const LocationAnomalyConfig(), Function? onError}) → StreamSubscription< LocationAnomaly> -
override
-
onLocationQuality(
void callback(LocationQuality quality), {LocationQualityConfig config = const LocationQualityConfig(), Function? onError}) → StreamSubscription< LocationQuality> -
override
-
onMotionChange(
void callback(Location), {Function? onError}) → StreamSubscription< Location> -
override
-
onNotificationAction(
void callback(String), {Function? onError}) → StreamSubscription< String> -
override
-
onPowerSaveChange(
void callback(bool), {Function? onError}) → StreamSubscription< bool> -
override
-
onPowerStateChangeWithObj(
void callback(PowerStateChangeEvent event), {Function? onError}) → StreamSubscription< PowerStateChangeEvent> -
override
-
onProviderChange(
void callback(ProviderChangeEvent), {Function? onError}) → StreamSubscription< ProviderChangeEvent> -
override
-
onSchedule(
void callback(Location), {Function? onError}) → StreamSubscription< Location> -
override
-
onTripEvent(
void callback(TripEvent event), {Function? onError}) → StreamSubscription< TripEvent> -
override
-
onWorkflowEvent(
void callback(GeofenceWorkflowEvent event), {Function? onError}) → StreamSubscription< GeofenceWorkflowEvent> -
override
-
polygonGeofenceExists(
String identifier) → Future< bool> -
override
-
processLocationThroughPrivacyZones(
Location location) → PrivacyZoneResult - Helper to process a location through privacy zones.
-
queryLocations(
LocationQuery query) → Future< List< Location> > -
override
-
ready(
Config config, {bool skipValidation = false}) → Future< GeolocationState> -
override
-
recordBenchmarkLocationUpdate(
{double? accuracy}) → void -
override
-
recordBenchmarkSync(
) → void -
override
-
refreshHeaders(
) → Future< void> -
override
-
registerGeofenceWorkflows(
List< GeofenceWorkflow> workflows) → void -
override
-
registerHeadlessSyncBodyBuilder(
Future< JsonMap> builder(SyncBodyContext context)) → Future<bool> -
Registers a headless-compatible sync body builder.
override
-
registerHeadlessTask(
HeadlessEventCallback callback) → Future< bool> -
override
-
removeAllPolygonGeofences(
) → Future< void> -
override
-
removeAllPrivacyZones(
) → Future< void> -
Removes all privacy zones.
override
-
removeGeofence(
String identifier) → Future< bool> -
override
-
removeGeofences(
) → Future< bool> -
Removes all geofences.
override
-
removePolygonGeofence(
String identifier) → Future< bool> -
override
-
removePrivacyZone(
String identifier) → Future< bool> -
Removes a privacy zone by identifier.
override
-
requestPermission(
) → Future< bool> -
override
-
reset(
Config config) → Future< void> -
override
-
resumeSync(
) → Future< bool> -
override
-
setAdaptiveTracking(
AdaptiveTrackingConfig config) → Future< void> -
override
-
setBatteryStats(
BatteryStats stats) → void - Sets mock battery stats.
-
setConfig(
Config config) → Future< void> -
override
-
setErrorHandler(
ErrorRecoveryConfig config) → void -
override
-
setHeadersCallback(
Future< Map< callback()?) → voidString, String> > -
override
-
setIsForeground(
bool isForeground) → void - Sets whether the app is foregrounded.
-
setMockState(
GeolocationState state) → void - Sets the mock state.
-
setOdometer(
double value) → Future< double> -
override
-
setPowerState(
PowerState state, {PowerStateChangeType changeType = PowerStateChangeType.batteryLevel}) → void - Sets mock power state and emits a change event.
-
setPrivacyZoneEnabled(
String identifier, bool enabled) → Future< bool> -
Enables or disables a privacy zone.
override
-
setSpoofDetection(
SpoofDetectionConfig config) → Future< void> -
override
-
setSyncBodyBuilder(
SyncBodyBuilder? builder) → void -
Sets a callback to build custom HTTP sync body.
override
-
setSyncPolicy(
SyncPolicy policy) → Future< void> -
override
-
setTrackingProfile(
TrackingProfile profile) → Future< void> -
override
-
setTrackingProfiles(
Map< TrackingProfile, Config> profiles, {TrackingProfile? initialProfile, List<TrackingProfileRule> rules = const [], bool enableAutomation = false}) → Future<void> -
override
-
simulateLocationSequence(
List< Location> locations, {Duration interval = const Duration(seconds: 1)}) → Future<void> - Simulates a sequence of locations over time.
-
start(
) → Future< GeolocationState> -
override
-
startBackgroundTask(
) → Future< int> -
override
-
startBatteryBenchmark(
) → Future< void> -
override
-
startGeofences(
) → Future< bool> -
override
-
startLifecycleObserving(
) → void -
override
-
startSchedule(
) → Future< bool> -
override
-
startSignificantChangeMonitoring(
[SignificantChangeConfig config = const SignificantChangeConfig()]) → Future< void> -
override
-
startTrackingAutomation(
) → void -
override
-
startTrip(
TripConfig config) → Future< void> -
override
-
stop(
) → Future< GeolocationState> -
override
-
stopBackgroundTask(
int taskId) → Future< void> -
override
-
stopBatteryBenchmark(
) → Future< BenchmarkResult?> -
override
-
stopGeofenceWorkflows(
) → void -
override
-
stopLifecycleObserving(
) → void -
override
-
stopSchedule(
) → Future< bool> -
override
-
stopSignificantChangeMonitoring(
) → Future< void> -
override
-
stopTrackingAutomation(
) → void -
override
-
stopTrip(
) → TripSummary? -
override
-
sync(
) → Future< bool> -
override
-
syncQueue(
{int? limit}) → Future< int> -
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited