DeadReckoning implements SensorEventListener, SensorCollector, DownloadListener<Map<String, Collection>> { @Override public void onDownloadFinished(DownloadTask task, boolean success, Map<String, Collection> data) { if(success){ final List<Integer> northAngleList = (List<Integer>) data.get(OsmParserKeys.NORTH_ANGLE); if ((northAngleList != null) && (!northAngleList.isEmpty()) && (northAngleList.get(0) != null)) { setBaseAngle(northAngleList.get(0)); } } else { Log.e(TAG, "North angle download signals failure, so probably direction will be completely wrong."); } } DeadReckoning(final Activity activity); void startSensors(); void stopSensors(); @Override void onDownloadFinished(DownloadTask task, boolean success, Map<String, Collection> data); @Override void onSensorChanged(final SensorEvent event); @Override void onAccuracyChanged(final Sensor sensor, final int accuracy); NicGeoPoint getDelta(); void setCompassFilterEnabled(boolean useLowPassFilter); void setBaseAngle(final double baseAngle);  }
@Test public void testInvalidBaseAngleData() { DownloadTask task = mock(DownloadMapDataTask.class); Map<String, Collection> data = new HashMap<String, Collection>(); deadReckoning.onDownloadFinished(task, true, data); assertTrue(0 == deadReckoning.baseAngle); deadReckoning.onDownloadFinished(task, false, data); assertTrue(0 == deadReckoning.baseAngle); List<Integer> list = new ArrayList<Integer>(); data.put(OsmParserKeys.NORTH_ANGLE, list); deadReckoning.onDownloadFinished(task, true, data); assertTrue(0 == deadReckoning.baseAngle); list.add(null); data.put(OsmParserKeys.NORTH_ANGLE, list); deadReckoning.onDownloadFinished(task, true, data); assertTrue(0 == deadReckoning.baseAngle); }
@Test public void testCalculateBaseAngle() { DownloadTask task = mock(DownloadMapDataTask.class); Map<String, Collection> data = new HashMap<String, Collection>(); List<Integer> list = new ArrayList<Integer>(); list.add(90); data.put(OsmParserKeys.NORTH_ANGLE, list); deadReckoning.onDownloadFinished(task, true, data); assertEquals(Math.PI/2, deadReckoning.baseAngle, 0.01f); }