LocationReceiver extends BroadcastReceiver { private void onLocationUpdate(@NonNull AirshipLocationManager locationManager, @NonNull Intent intent) { Location location; try { if (intent.hasExtra(LocationManager.KEY_PROVIDER_ENABLED)) { Logger.debug("LocationReceiver - One of the location providers was enabled or disabled."); locationManager.onSystemLocationProvidersChanged(); return; } location = (Location) (intent.hasExtra(LocationManager.KEY_LOCATION_CHANGED) ? intent.getParcelableExtra(LocationManager.KEY_LOCATION_CHANGED) : intent.getParcelableExtra("com.google.android.location.LOCATION")); } catch (Exception e) { Logger.error(e, "LocationReceiver - Unable to extract location."); return; } if (location != null) { locationManager.onLocationUpdate(location); } } @VisibleForTesting  LocationReceiver(Executor executor, Callable<AirshipLocationManager> locationManagerCallable);  LocationReceiver(); @Override void onReceive(@NonNull final Context context, @Nullable final Intent intent);  }
@Test public void testLocationUpdate() { Location location = new Location("location"); Bundle bundle = new Bundle(); bundle.putParcelable(LocationManager.KEY_LOCATION_CHANGED, location); sendIntent(LocationReceiver.ACTION_LOCATION_UPDATE, bundle); verify(locationManager).onLocationUpdate(eq(location)); }
@Test public void testLocationUpdateNullLocation() { sendIntent(LocationReceiver.ACTION_LOCATION_UPDATE); verify(locationManager, times(0)).onLocationUpdate(any(Location.class)); }