BackgroundLocationManager implements LocationClient.LocationClientListener, LocationListener { public BackgroundLocationMessage activityDisplayed() { switch (currentState) { case NO_BACKGROUND_LOCATION_NEEDED: if (helper.isCurrentFormSet() && helper.currentFormAuditsLocation()) { startLocationRequests(); if (currentState != BackgroundLocationState.RECEIVING_LOCATIONS) { currentState = BackgroundLocationState.STOPPED; } } break; case PENDING_PRECONDITION_CHECKS: BackgroundLocationMessage userMessage = null; if (!helper.isBackgroundLocationPreferenceEnabled()) { helper.logAuditEvent(AuditEvent.AuditEventType.LOCATION_TRACKING_DISABLED); userMessage = BackgroundLocationMessage.LOCATION_PREF_DISABLED; } if (!helper.arePlayServicesAvailable()) { helper.logAuditEvent(AuditEvent.AuditEventType.GOOGLE_PLAY_SERVICES_NOT_AVAILABLE); userMessage = BackgroundLocationMessage.PLAY_SERVICES_UNAVAILABLE; } if (userMessage == null) { helper.logAuditEvent(AuditEvent.AuditEventType.LOCATION_TRACKING_ENABLED); currentState = BackgroundLocationState.PENDING_PERMISSION_CHECK; } else { currentState = BackgroundLocationState.STOPPED; } return userMessage; case STOPPED: startLocationRequests(); break; } return null; } BackgroundLocationManager(LocationClient locationClient, BackgroundLocationHelper helper); void formFinishedLoading(); BackgroundLocationMessage activityDisplayed(); void activityHidden(); boolean isPendingPermissionCheck(); BackgroundLocationMessage locationPermissionGranted(); void locationPermissionDenied(); void backgroundLocationPreferenceToggled(); void locationPermissionChanged(); void locationProvidersChanged(); @Override void onLocationChanged(Location location); @Override void onClientStart(); @Override void onClientStartFailure(); @Override void onClientStop();  }
@Test public void locationRequests_Resume_WhenActivityIsDisplayed_AndFormThatAuditsLocationWasAlreadyLoaded() { when(locationHelper.isCurrentFormSet()).thenReturn(true); when(locationHelper.currentFormAuditsLocation()).thenReturn(true); when(locationHelper.arePlayServicesAvailable()).thenReturn(true); when(locationHelper.isBackgroundLocationPreferenceEnabled()).thenReturn(true); when(locationHelper.isAndroidLocationPermissionGranted()).thenReturn(true); when(locationHelper.getCurrentFormAuditConfig()).thenReturn(new AuditConfig("foo", "2", "3", true)); backgroundLocationManager.activityDisplayed(); Location location = LocationTestUtils.createLocation("GPS", 1, 2, 3, 4); fakeLocationClient.receiveFix(location); verify(locationHelper).provideLocationToAuditLogger(location); }