LocationEvent extends Event { @NonNull @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public final JsonMap getEventData() { return JsonMap.newBuilder() .put(LATITUDE_KEY, latitude) .put(LONGITUDE_KEY, longitude) .put(REQUESTED_ACCURACY_KEY, requestedAccuracy) .put(UPDATE_TYPE_KEY, updateType == UPDATE_TYPE_CONTINUOUS ? "CONTINUOUS" : "SINGLE") .put(PROVIDER_KEY, provider) .put(H_ACCURACY_KEY, accuracy) .put(V_ACCURACY_KEY, "NONE") .put(FOREGROUND_KEY, foreground) .put(UPDATE_DISTANCE_KEY, updateDistance) .build(); } LocationEvent(@NonNull Location location, @UpdateType int type, int userRequestedAccuracy, int updateDist, boolean isForeground); @NonNull @Override String getType(); @NonNull @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) final JsonMap getEventData(); @Override @Priority int getPriority(); final static int UPDATE_TYPE_CONTINUOUS; final static int UPDATE_TYPE_SINGLE; }
@Test public void testLatitude() throws JSONException { assertEquals(Double.parseDouble(event.getEventData().get(LocationEvent.LATITUDE_KEY).getString()), gpsLocation.getLatitude(), 0); }
@Test public void testLongitude() throws JSONException { assertEquals(Double.parseDouble(event.getEventData().get(LocationEvent.LONGITUDE_KEY).getString()), gpsLocation.getLongitude(), 0); }
@Test public void testRequestedAccuracy() throws JSONException { assertEquals(event.getEventData().get(LocationEvent.REQUESTED_ACCURACY_KEY).getString(), "1"); assertEquals(noRequestedAccuracyEvent.getEventData().get(LocationEvent.REQUESTED_ACCURACY_KEY).getString(), "NONE"); }
@Test public void testUpdateDistance() throws JSONException { assertEquals(event.getEventData().get(LocationEvent.UPDATE_DISTANCE_KEY).getString(), "1"); assertEquals(noUpdateDistanceEvent.getEventData().get(LocationEvent.UPDATE_DISTANCE_KEY).getString(), "NONE"); }
@Test public void testProvider() throws JSONException { assertEquals(event.getEventData().get(LocationEvent.PROVIDER_KEY).getString(), gpsLocation.getProvider()); assertEquals(networkProviderEvent.getEventData().get(LocationEvent.PROVIDER_KEY).getString(), networkProviderLocation.getProvider()); assertEquals(passiveProviderEvent.getEventData().get(LocationEvent.PROVIDER_KEY).getString(), passiveProviderLocation.getProvider()); assertEquals(unknownProviderEvent.getEventData().get(LocationEvent.PROVIDER_KEY).getString(), unknownProviderLocation.getProvider()); assertEquals(bogusProviderEvent.getEventData().get(LocationEvent.PROVIDER_KEY).getString(), "UNKNOWN"); }
@Test public void testHAccuracy() throws JSONException { assertEquals(Float.parseFloat(event.getEventData().get(LocationEvent.H_ACCURACY_KEY).getString()), gpsLocation.getAccuracy(), 0); }
@Test public void testVAccuracy() throws JSONException { assertEquals(event.getEventData().get(LocationEvent.V_ACCURACY_KEY).getString(), "NONE"); }
@Test public void testForeground() throws JSONException { assertEquals(event.getEventData().get(LocationEvent.FOREGROUND_KEY).getString(), "true"); assertEquals(backgroundEvent.getEventData().get(LocationEvent.FOREGROUND_KEY).getString(), "false"); }
@Test public void testContinousUpdateType() throws JSONException { assertEquals(event.getEventData().get(LocationEvent.UPDATE_TYPE_KEY).getString(), "CONTINUOUS"); }
@Test public void testSingleUpdateType() throws JSONException { assertEquals(singleUpdateEvent.getEventData().get(LocationEvent.UPDATE_TYPE_KEY).getString(), "SINGLE"); }
@Test public void testChangeUpdateType() throws JSONException { assertEquals(continuousUpdateEvent.getEventData().get(LocationEvent.UPDATE_TYPE_KEY).getString(), "CONTINUOUS"); }