forked from upstream-mirrors/OpenTracks
Fixed ChartFragmentTest.
This commit is contained in:
@@ -32,14 +32,14 @@ public class TrackStubUtils {
|
|||||||
|
|
||||||
public static final double INITIAL_ALTITUDE = 22;
|
public static final double INITIAL_ALTITUDE = 22;
|
||||||
public static final long INITIAL_TIME = 1000L;
|
public static final long INITIAL_TIME = 1000L;
|
||||||
static final String LOCATION_PROVIDER = "gps";
|
private static final String LOCATION_PROVIDER = "gps";
|
||||||
static final double INITIAL_LATITUDE = 22;
|
private static final double INITIAL_LATITUDE = 22;
|
||||||
static final double INITIAL_LONGITUDE = 22;
|
private static final double INITIAL_LONGITUDE = 22;
|
||||||
static final float INITIAL_ACCURACY = 5;
|
private static final float INITIAL_ACCURACY = 5;
|
||||||
static final float INITIAL_SPEED = 10;
|
private static final float INITIAL_SPEED = 10;
|
||||||
static final float INITIAL_BEARING = 3.0f;
|
private static final float INITIAL_BEARING = 3.0f;
|
||||||
// Used to change the value of latitude, longitude, and altitude.
|
// Used to change the value of latitude, longitude, and altitude.
|
||||||
static final double DIFFERENCE = 0.01;
|
private static final double DIFFERENCE = 0.01;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a a {@link Track} stub with specified number of locations.
|
* Gets a a {@link Track} stub with specified number of locations.
|
||||||
@@ -71,8 +71,7 @@ public class TrackStubUtils {
|
|||||||
*
|
*
|
||||||
* @return a SensorDataSetLocation stub.
|
* @return a SensorDataSetLocation stub.
|
||||||
*/
|
*/
|
||||||
public static SensorDataSetLocation createSensorDataSetLocation(double latitude, double longitude,
|
public static SensorDataSetLocation createSensorDataSetLocation(double latitude, double longitude, double altitude) {
|
||||||
double altitude) {
|
|
||||||
// Initial Location
|
// Initial Location
|
||||||
Location loc = new Location(LOCATION_PROVIDER);
|
Location loc = new Location(LOCATION_PROVIDER);
|
||||||
loc.setLatitude(latitude);
|
loc.setLatitude(latitude);
|
||||||
@@ -82,7 +81,7 @@ public class TrackStubUtils {
|
|||||||
loc.setSpeed(INITIAL_SPEED);
|
loc.setSpeed(INITIAL_SPEED);
|
||||||
loc.setTime(INITIAL_TIME);
|
loc.setTime(INITIAL_TIME);
|
||||||
loc.setBearing(INITIAL_BEARING);
|
loc.setBearing(INITIAL_BEARING);
|
||||||
SensorDataSet sd = new SensorDataSet(100, 100);
|
SensorDataSet sd = new SensorDataSet(Float.NaN, Float.NaN);
|
||||||
|
|
||||||
return new SensorDataSetLocation(loc, sd);
|
return new SensorDataSetLocation(loc, sd);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,8 +66,6 @@ public class TrackDataHubTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
|
||||||
private TrackDataManager trackDataManager;
|
|
||||||
|
|
||||||
private TrackDataHub trackDataHub;
|
private TrackDataHub trackDataHub;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@@ -80,8 +78,7 @@ public class TrackDataHubTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
sharedPreferences = PreferencesUtils.getSharedPreferences(context);
|
sharedPreferences = PreferencesUtils.getSharedPreferences(context);
|
||||||
trackDataManager = new TrackDataManager();
|
trackDataHub = new TrackDataHub(context, new TrackDataManager(), contentProviderUtils, TARGET_POINTS) {
|
||||||
trackDataHub = new TrackDataHub(context, trackDataManager, contentProviderUtils, TARGET_POINTS) {
|
|
||||||
@Override
|
@Override
|
||||||
protected DataSource newDataSource() {
|
protected DataSource newDataSource() {
|
||||||
return dataSource;
|
return dataSource;
|
||||||
@@ -307,8 +304,7 @@ public class TrackDataHubTest {
|
|||||||
|
|
||||||
// Unregister one listener and change track
|
// Unregister one listener and change track
|
||||||
locationIterator = new FixedSizeLocationIterator(101, 10);
|
locationIterator = new FixedSizeLocationIterator(101, 10);
|
||||||
when(contentProviderUtils.getTrackPointLocationIterator(
|
when(contentProviderUtils.getTrackPointLocationIterator(eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class)))
|
||||||
eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class)))
|
|
||||||
.thenReturn(locationIterator);
|
.thenReturn(locationIterator);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID + 1)).thenReturn(110L);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID + 1)).thenReturn(110L);
|
||||||
trackDataListener2.clearTrackPoints();
|
trackDataListener2.clearTrackPoints();
|
||||||
@@ -387,8 +383,7 @@ public class TrackDataHubTest {
|
|||||||
|
|
||||||
trackDataHub.start();
|
trackDataHub.start();
|
||||||
trackDataHub.loadTrack(TRACK_ID);
|
trackDataHub.loadTrack(TRACK_ID);
|
||||||
trackDataHub.registerTrackDataListener(
|
trackDataHub.registerTrackDataListener(trackDataListener1, EnumSet.of(TrackDataType.SAMPLED_IN_TRACK_POINTS_TABLE));
|
||||||
trackDataListener1, EnumSet.of(TrackDataType.SAMPLED_IN_TRACK_POINTS_TABLE));
|
|
||||||
verifyAndReset();
|
verifyAndReset();
|
||||||
|
|
||||||
// Unregister the listener
|
// Unregister the listener
|
||||||
@@ -400,11 +395,9 @@ public class TrackDataHubTest {
|
|||||||
verifyAndReset();
|
verifyAndReset();
|
||||||
|
|
||||||
// Register the listener after a new track
|
// Register the listener after a new track
|
||||||
dataSource.registerContentObserver(
|
dataSource.registerContentObserver(eq(TrackPointsColumns.CONTENT_URI), observerCapture.capture());
|
||||||
eq(TrackPointsColumns.CONTENT_URI), observerCapture.capture());
|
|
||||||
locationIterator = new FixedSizeLocationIterator(1, 10);
|
locationIterator = new FixedSizeLocationIterator(1, 10);
|
||||||
when(contentProviderUtils.getTrackPointLocationIterator(
|
when(contentProviderUtils.getTrackPointLocationIterator(eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class)))
|
||||||
eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class)))
|
|
||||||
.thenReturn(locationIterator);
|
.thenReturn(locationIterator);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID + 1)).thenReturn(10L);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID + 1)).thenReturn(10L);
|
||||||
trackDataListener1.clearTrackPoints();
|
trackDataListener1.clearTrackPoints();
|
||||||
@@ -413,8 +406,7 @@ public class TrackDataHubTest {
|
|||||||
replay();
|
replay();
|
||||||
|
|
||||||
trackDataHub.loadTrack(TRACK_ID + 1);
|
trackDataHub.loadTrack(TRACK_ID + 1);
|
||||||
trackDataHub.registerTrackDataListener(
|
trackDataHub.registerTrackDataListener(trackDataListener1, EnumSet.of(TrackDataType.SAMPLED_IN_TRACK_POINTS_TABLE));
|
||||||
trackDataListener1, EnumSet.of(TrackDataType.SAMPLED_IN_TRACK_POINTS_TABLE));
|
|
||||||
verifyAndReset();
|
verifyAndReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,8 +524,7 @@ public class TrackDataHubTest {
|
|||||||
when(trackDataListener2.onReportSpeedChanged(false)).thenReturn(false);
|
when(trackDataListener2.onReportSpeedChanged(false)).thenReturn(false);
|
||||||
replay();
|
replay();
|
||||||
|
|
||||||
PreferencesUtils.setString(
|
PreferencesUtils.setString(context, R.string.stats_rate_key, context.getString(R.string.stats_rate_pace));
|
||||||
context, R.string.stats_rate_key, context.getString(R.string.stats_rate_pace));
|
|
||||||
OnSharedPreferenceChangeListener listener = preferenceChangeListenerCapture.getValue();
|
OnSharedPreferenceChangeListener listener = preferenceChangeListenerCapture.getValue();
|
||||||
listener.onSharedPreferenceChanged(sharedPreferences, PreferencesUtils.getKey(context, R.string.stats_rate_key));
|
listener.onSharedPreferenceChanged(sharedPreferences, PreferencesUtils.getKey(context, R.string.stats_rate_key));
|
||||||
verifyAndReset();
|
verifyAndReset();
|
||||||
|
|||||||
@@ -60,9 +60,9 @@ public class ChartFragmentTest {
|
|||||||
|
|
||||||
// No input.
|
// No input.
|
||||||
double[] point = fillDataPointTestHelper(sensorDataSetLocation);
|
double[] point = fillDataPointTestHelper(sensorDataSetLocation);
|
||||||
Assert.assertEquals(Double.NaN, point[ChartView.HEART_RATE_SERIES + 1], 0.01);
|
Assert.assertEquals(Float.NaN, point[ChartView.HEART_RATE_SERIES + 1], 0.01);
|
||||||
Assert.assertEquals(Double.NaN, point[ChartView.CADENCE_SERIES + 1], 0.01);
|
Assert.assertEquals(Float.NaN, point[ChartView.CADENCE_SERIES + 1], 0.01);
|
||||||
Assert.assertEquals(Double.NaN, point[ChartView.POWER_SERIES + 1], 0.01);
|
Assert.assertEquals(Float.NaN, point[ChartView.POWER_SERIES + 1], 0.01);
|
||||||
|
|
||||||
// Input incorrect state.
|
// Input incorrect state.
|
||||||
// Creates SensorData.
|
// Creates SensorData.
|
||||||
@@ -70,9 +70,9 @@ public class ChartFragmentTest {
|
|||||||
sensorDataSetLocation.setSensorDataSet(sensorDataSet);
|
sensorDataSetLocation.setSensorDataSet(sensorDataSet);
|
||||||
// Test.
|
// Test.
|
||||||
point = fillDataPointTestHelper(sensorDataSetLocation);
|
point = fillDataPointTestHelper(sensorDataSetLocation);
|
||||||
Assert.assertEquals(Double.NaN, point[ChartView.HEART_RATE_SERIES + 1], 0.01);
|
Assert.assertEquals(Float.NaN, point[ChartView.HEART_RATE_SERIES + 1], 0.01);
|
||||||
Assert.assertEquals(Double.NaN, point[ChartView.CADENCE_SERIES + 1], 0.01);
|
Assert.assertEquals(Float.NaN, point[ChartView.CADENCE_SERIES + 1], 0.01);
|
||||||
Assert.assertEquals(Double.NaN, point[ChartView.POWER_SERIES + 1], 0.01);
|
Assert.assertEquals(Float.NaN, point[ChartView.POWER_SERIES + 1], 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,9 +83,9 @@ public class ChartFragmentTest {
|
|||||||
SensorDataSetLocation sensorDataSetLocation = TrackStubUtils.createSensorDataSetLocation();
|
SensorDataSetLocation sensorDataSetLocation = TrackStubUtils.createSensorDataSetLocation();
|
||||||
// No input.
|
// No input.
|
||||||
double[] point = fillDataPointTestHelper(sensorDataSetLocation);
|
double[] point = fillDataPointTestHelper(sensorDataSetLocation);
|
||||||
Assert.assertEquals(Double.NaN, point[ChartView.HEART_RATE_SERIES + 1], 0.01);
|
Assert.assertEquals(Float.NaN, point[ChartView.HEART_RATE_SERIES + 1], 0.01);
|
||||||
Assert.assertEquals(Double.NaN, point[ChartView.CADENCE_SERIES + 1], 0.01);
|
Assert.assertEquals(Float.NaN, point[ChartView.CADENCE_SERIES + 1], 0.01);
|
||||||
Assert.assertEquals(Double.NaN, point[ChartView.POWER_SERIES + 1], 0.01);
|
Assert.assertEquals(Float.NaN, point[ChartView.POWER_SERIES + 1], 0.01);
|
||||||
|
|
||||||
// Creates SensorData.
|
// Creates SensorData.
|
||||||
SensorDataSet sensorDataSet = new SensorDataSet(100, 101, 102);
|
SensorDataSet sensorDataSet = new SensorDataSet(100, 101, 102);
|
||||||
|
|||||||
+1
-1
@@ -96,7 +96,7 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
||||||
|
|
||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint(new Location[]{location1}, eq(1), eq(TRACK_ID_0))).thenReturn(1);
|
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(1), eq(TRACK_ID_0))).thenReturn(1);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_1);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_1);
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getLong(context, R.string.recording_track_id_key))).thenReturn(null);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getLong(context, R.string.recording_track_id_key))).thenReturn(null);
|
||||||
expectUpdateTrack(trackCaptor, true, TRACK_ID_0);
|
expectUpdateTrack(trackCaptor, true, TRACK_ID_0);
|
||||||
|
|||||||
Reference in New Issue
Block a user