forked from upstream-mirrors/OpenTracks
Merge heads
This commit is contained in:
@@ -33,7 +33,7 @@ public class ChartValueSeriesTest extends AndroidTestCase {
|
||||
R.color.elevation_fill,
|
||||
R.color.elevation_border,
|
||||
new ZoomSettings(5, new int[] {100}),
|
||||
R.string.stat_elevation);
|
||||
R.string.stats_elevation);
|
||||
}
|
||||
|
||||
public void testInitialConditions() {
|
||||
@@ -43,7 +43,7 @@ public class ChartValueSeriesTest extends AndroidTestCase {
|
||||
assertEquals(0, series.getMax());
|
||||
assertEquals(0.0, series.getSpread());
|
||||
assertEquals(Style.STROKE, series.getPaint().getStyle());
|
||||
assertEquals(getContext().getString(R.string.stat_elevation),
|
||||
assertEquals(getContext().getString(R.string.stats_elevation),
|
||||
series.getTitle());
|
||||
assertTrue(series.isEnabled());
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
private TrackDataHub hub;
|
||||
private TrackDataListeners listeners;
|
||||
private DataSourcesWrapper dataSources;
|
||||
private SharedPreferences prefs;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private TrackDataListener listener1;
|
||||
private TrackDataListener listener2;
|
||||
private Capture<OnSharedPreferenceChangeListener> preferenceListenerCapture =
|
||||
@@ -88,12 +88,12 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
getContext(), getContext(), "test.");
|
||||
context = new MockContext(mockContentResolver, targetContext);
|
||||
|
||||
prefs = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
providerUtils = AndroidMock.createMock("providerUtils", MyTracksProviderUtils.class);
|
||||
dataSources = AndroidMock.createNiceMock("dataSources", DataSourcesWrapper.class);
|
||||
|
||||
listeners = new TrackDataListeners();
|
||||
hub = new TrackDataHub(context, listeners, prefs, providerUtils, TARGET_POINTS) {
|
||||
hub = new TrackDataHub(context, listeners, sharedPreferences, providerUtils, TARGET_POINTS) {
|
||||
@Override
|
||||
protected DataSourcesWrapper newDataSources() {
|
||||
return dataSources;
|
||||
@@ -113,8 +113,8 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
|
||||
listener1 = AndroidMock.createStrictMock("listener1", TrackDataListener.class);
|
||||
listener2 = AndroidMock.createStrictMock("listener2", TrackDataListener.class);
|
||||
PreferencesUtils.setRecordingTrackId(context, TRACK_ID);
|
||||
PreferencesUtils.setSelectedTrackId(context, TRACK_ID);
|
||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key, TRACK_ID);
|
||||
PreferencesUtils.setLong(context, R.string.selected_track_id_key, TRACK_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -798,13 +798,8 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
public void testDisplayPreferencesListen() throws Exception {
|
||||
String metricUnitsKey = context.getString(R.string.metric_units_key);
|
||||
String speedKey = context.getString(R.string.report_speed_key);
|
||||
|
||||
prefs.edit()
|
||||
.putBoolean(metricUnitsKey, true)
|
||||
.putBoolean(speedKey, true)
|
||||
.apply();
|
||||
PreferencesUtils.setBoolean(context, R.string.report_speed_key, true);
|
||||
PreferencesUtils.setBoolean(context, R.string.metric_units_key, true);
|
||||
|
||||
Capture<OnSharedPreferenceChangeListener> listenerCapture =
|
||||
new Capture<OnSharedPreferenceChangeListener>();
|
||||
@@ -828,11 +823,10 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
|
||||
replay();
|
||||
|
||||
prefs.edit()
|
||||
.putBoolean(speedKey, false)
|
||||
.apply();
|
||||
PreferencesUtils.setBoolean(context, R.string.report_speed_key, false);
|
||||
OnSharedPreferenceChangeListener listener = listenerCapture.getValue();
|
||||
listener.onSharedPreferenceChanged(prefs, speedKey);
|
||||
listener.onSharedPreferenceChanged(
|
||||
sharedPreferences, PreferencesUtils.getKey(context, R.string.report_speed_key));
|
||||
|
||||
AndroidMock.verify(dataSources, providerUtils, listener1, listener2);
|
||||
AndroidMock.reset(dataSources, providerUtils, listener1, listener2);
|
||||
@@ -842,10 +836,9 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
|
||||
replay();
|
||||
|
||||
prefs.edit()
|
||||
.putBoolean(metricUnitsKey, false)
|
||||
.apply();
|
||||
listener.onSharedPreferenceChanged(prefs, metricUnitsKey);
|
||||
PreferencesUtils.setBoolean(context, R.string.metric_units_key, false);
|
||||
listener.onSharedPreferenceChanged(
|
||||
sharedPreferences, PreferencesUtils.getKey(context, R.string.metric_units_key));
|
||||
|
||||
verifyAndReset();
|
||||
}
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ import android.test.AndroidTestCase;
|
||||
public class WaypointCreationRequestTest extends AndroidTestCase {
|
||||
|
||||
public void testTypeParceling() {
|
||||
WaypointCreationRequest original = WaypointCreationRequest.DEFAULT_MARKER;
|
||||
WaypointCreationRequest original = WaypointCreationRequest.DEFAULT_WAYPOINT;
|
||||
Parcel p = Parcel.obtain();
|
||||
original.writeToParcel(p, 0);
|
||||
p.setDataPosition(0);
|
||||
@@ -42,7 +42,7 @@ public class WaypointCreationRequestTest extends AndroidTestCase {
|
||||
|
||||
public void testAllAttributesParceling() {
|
||||
WaypointCreationRequest original =
|
||||
new WaypointCreationRequest(WaypointType.MARKER, "name", "category", "description", "img.png");
|
||||
new WaypointCreationRequest(WaypointType.WAYPOINT, "name", "category", "description", "img.png");
|
||||
Parcel p = Parcel.obtain();
|
||||
original.writeToParcel(p, 0);
|
||||
p.setDataPosition(0);
|
||||
|
||||
@@ -120,7 +120,7 @@ public class ChartFragmentTest extends AndroidTestCase {
|
||||
*/
|
||||
public void testFillDataPoint_distanceMetric() {
|
||||
// By distance.
|
||||
chartFragment.getChartView().setMode(ChartView.Mode.BY_DISTANCE);
|
||||
chartFragment.setChartByDistance(true);
|
||||
// Resets last location and writes first location.
|
||||
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation();
|
||||
double[] point = fillDataPointTestHelper(myTracksLocation1);
|
||||
@@ -160,6 +160,8 @@ public class ChartFragmentTest extends AndroidTestCase {
|
||||
* {@link ChartFragment#fillDataPoint(Location, double[])}.
|
||||
*/
|
||||
public void testFillDataPoint_distanceImperial() {
|
||||
// By distance.
|
||||
chartFragment.setChartByDistance(true);
|
||||
// Setups to use imperial.
|
||||
chartFragment.setMetricUnits(false);
|
||||
|
||||
@@ -204,7 +206,7 @@ public class ChartFragmentTest extends AndroidTestCase {
|
||||
*/
|
||||
public void testFillDataPoint_time() {
|
||||
// By time
|
||||
chartFragment.getChartView().setMode(ChartView.Mode.BY_TIME);
|
||||
chartFragment.setChartByDistance(false);
|
||||
MyTracksLocation myTracksLocation1 = TrackStubUtils.createMyTracksLocation();
|
||||
double[] point = fillDataPointTestHelper(myTracksLocation1);
|
||||
assertEquals(0.0, point[0]);
|
||||
|
||||
@@ -31,9 +31,16 @@ public class CsvTrackWriterTest extends TrackFormatWriterTest {
|
||||
String expectedTrackHeader = getExpectedLine(
|
||||
"Name", "Activity type", "Description");
|
||||
String expectedTrack = getExpectedLine(TRACK_NAME, TRACK_CATEGORY, TRACK_DESCRIPTION);
|
||||
String expectedMarkerHeader = getExpectedLine("Marker name", "Marker type",
|
||||
"Marker description", "Latitude (deg)", "Longitude (deg)", "Altitude (m)", "Bearing (deg)",
|
||||
"Accuracy (m)", "Speed (m/s)", "Time");
|
||||
String expectedMarkerHeader = getExpectedLine("Name",
|
||||
"Marker type",
|
||||
"Description",
|
||||
"Latitude (deg)",
|
||||
"Longitude (deg)",
|
||||
"Altitude (m)",
|
||||
"Bearing (deg)",
|
||||
"Accuracy (m)",
|
||||
"Speed (m/s)",
|
||||
"Time");
|
||||
String expectedMarker1 = getExpectedLine(WAYPOINT1_NAME, WAYPOINT1_CATEGORY,
|
||||
WAYPOINT1_DESCRIPTION, "1.0", "-1.0", "10.0", "100.0", "1,000", "10,000",
|
||||
"1970-01-01T00:01:40.000Z");
|
||||
|
||||
+25
-43
@@ -15,14 +15,11 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.io.sendtogoogle;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.RadioButton;
|
||||
@@ -123,14 +120,10 @@ public class UploadServiceChooserActivityTest extends
|
||||
public void testOnCreateDialog_initStateUnchecked() {
|
||||
initialActivity(true, true, true);
|
||||
// Initial all values to false in SharedPreferences.
|
||||
SharedPreferences prefs = uploadServiceChooserActivity.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key), false);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_fusion_tables_key),
|
||||
false);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_docs_key), false);
|
||||
editor.commit();
|
||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key, false);
|
||||
PreferencesUtils.setBoolean(
|
||||
uploadServiceChooserActivity, R.string.send_to_fusion_tables_key, false);
|
||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key, false);
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
uploadServiceChooserActivity.initState();
|
||||
@@ -150,15 +143,11 @@ public class UploadServiceChooserActivityTest extends
|
||||
public void testOnCreateDialog_initStateChecked() {
|
||||
initialActivity(true, true, true);
|
||||
// Initial all values to true in SharedPreferences.
|
||||
SharedPreferences prefs = uploadServiceChooserActivity.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.pick_existing_map_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_fusion_tables_key),
|
||||
true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_docs_key), true);
|
||||
editor.commit();
|
||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.pick_existing_map_key, true);
|
||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key, true);
|
||||
PreferencesUtils.setBoolean(
|
||||
uploadServiceChooserActivity, R.string.send_to_fusion_tables_key, true);
|
||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key, true);
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
uploadServiceChooserActivity.initState();
|
||||
@@ -181,14 +170,10 @@ public class UploadServiceChooserActivityTest extends
|
||||
public void testOnCreateDialog_saveState() {
|
||||
initialActivity(true, true, true);
|
||||
// Initial all values to true in SharedPreferences.
|
||||
SharedPreferences prefs = uploadServiceChooserActivity.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_fusion_tables_key),
|
||||
true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_docs_key), true);
|
||||
editor.commit();
|
||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key, true);
|
||||
PreferencesUtils.setBoolean(
|
||||
uploadServiceChooserActivity, R.string.send_to_fusion_tables_key, true);
|
||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key, true);
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
uploadServiceChooserActivity.initState();
|
||||
@@ -197,12 +182,13 @@ public class UploadServiceChooserActivityTest extends
|
||||
instrumentation.waitForIdleSync();
|
||||
uploadServiceChooserActivity.saveState();
|
||||
// All values in SharedPreferences must be changed.
|
||||
assertTrue(prefs.getBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key),
|
||||
false));
|
||||
assertTrue(prefs.getBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key),
|
||||
false));
|
||||
assertTrue(prefs.getBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key),
|
||||
false));
|
||||
assertTrue(PreferencesUtils.getBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key,
|
||||
PreferencesUtils.SEND_TO_MAPS_DEFAULT));
|
||||
assertTrue(PreferencesUtils.getBoolean(
|
||||
uploadServiceChooserActivity, R.string.send_to_fusion_tables_key,
|
||||
PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
|
||||
assertTrue(PreferencesUtils.getBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key,
|
||||
PreferencesUtils.SEND_TO_DOCS_DEFAULT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,14 +199,10 @@ public class UploadServiceChooserActivityTest extends
|
||||
public void testOnCreateDialog_startNextActivity() {
|
||||
initialActivity(true, true, true);
|
||||
// Initial all values to true or false in SharedPreferences.
|
||||
SharedPreferences prefs = uploadServiceChooserActivity.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = prefs.edit();
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_maps_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_docs_key), true);
|
||||
editor.putBoolean(uploadServiceChooserActivity.getString(R.string.send_to_fusion_tables_key),
|
||||
false);
|
||||
editor.commit();
|
||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_maps_key, true);
|
||||
PreferencesUtils.setBoolean(uploadServiceChooserActivity, R.string.send_to_docs_key, true);
|
||||
PreferencesUtils.setBoolean(
|
||||
uploadServiceChooserActivity, R.string.send_to_fusion_tables_key, false);
|
||||
uploadServiceChooserActivity.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
uploadServiceChooserActivity.initState();
|
||||
|
||||
+28
-48
@@ -13,6 +13,7 @@
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
@@ -21,26 +22,23 @@ import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
/**
|
||||
* Tests for the {@link DynamicSpeedTrackPathDescriptor}.
|
||||
*
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class DynamicSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
|
||||
private Context context;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private Editor sharedPreferencesEditor;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
context = getContext();
|
||||
sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
sharedPreferencesEditor = sharedPreferences.edit();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,96 +46,77 @@ public class DynamicSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
* with zero, normal and illegal value.
|
||||
*/
|
||||
public void testGetSpeedMargin() {
|
||||
String[] actuals = { "0", "50", "99", "" };
|
||||
// The default value of speedMargin is 25.
|
||||
int[] expectations = { 0, 50, 99, 25 };
|
||||
// Test
|
||||
for (int i = 0; i < expectations.length; i++) {
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_dynamic_speed_variation_key), actuals[i]);
|
||||
sharedPreferencesEditor.commit();
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_percentage_key, expectations[i]);
|
||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
||||
context);
|
||||
assertEquals(expectations[i],
|
||||
dynamicSpeedTrackPathDescriptor.getSpeedMargin(sharedPreferences));
|
||||
assertEquals(expectations[i], dynamicSpeedTrackPathDescriptor.getSpeedMargin());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link
|
||||
* DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the key is null.
|
||||
*/
|
||||
public void testOnSharedPreferenceChanged_nullKey() {
|
||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
||||
context);
|
||||
int speedMargin = dynamicSpeedTrackPathDescriptor.getSpeedMargin(sharedPreferences);
|
||||
int speedMargin = dynamicSpeedTrackPathDescriptor.getSpeedMargin();
|
||||
// Change value in shared preferences.
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_dynamic_speed_variation_key),
|
||||
Integer.toString(speedMargin + 2));
|
||||
sharedPreferencesEditor.commit();
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_percentage_key, speedMargin + 2);
|
||||
|
||||
dynamicSpeedTrackPathDescriptor.onSharedPreferenceChanged(sharedPreferences, null);
|
||||
assertEquals(speedMargin, dynamicSpeedTrackPathDescriptor.getSpeedMargin());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link
|
||||
* DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the key is not null, and not trackColorModeDynamicVariation.
|
||||
*/
|
||||
public void testOnSharedPreferenceChanged_otherKey() {
|
||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
||||
context);
|
||||
int speedMargin = dynamicSpeedTrackPathDescriptor.getSpeedMargin(sharedPreferences);
|
||||
int speedMargin = dynamicSpeedTrackPathDescriptor.getSpeedMargin();
|
||||
// Change value in shared preferences.
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_dynamic_speed_variation_key),
|
||||
Integer.toString(speedMargin + 2));
|
||||
sharedPreferencesEditor.commit();
|
||||
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_percentage_key, speedMargin + 2);
|
||||
dynamicSpeedTrackPathDescriptor.onSharedPreferenceChanged(sharedPreferences, "anyKey");
|
||||
assertEquals(speedMargin, dynamicSpeedTrackPathDescriptor.getSpeedMargin());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link
|
||||
* DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the key is trackColorModeDynamicVariation.
|
||||
*/
|
||||
public void testOnSharedPreferenceChanged_trackColorModeDynamicVariationKey() {
|
||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
||||
context);
|
||||
int speedMargin = dynamicSpeedTrackPathDescriptor.getSpeedMargin(sharedPreferences);
|
||||
int speedMargin = dynamicSpeedTrackPathDescriptor.getSpeedMargin();
|
||||
// Change value in shared preferences.
|
||||
sharedPreferencesEditor.putString(
|
||||
"trackColorModeDynamicVariation",
|
||||
Integer.toString(speedMargin + 2));
|
||||
sharedPreferencesEditor.commit();
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_percentage_key, speedMargin + 2);
|
||||
|
||||
dynamicSpeedTrackPathDescriptor.onSharedPreferenceChanged(sharedPreferences,
|
||||
"trackColorModeDynamicVariation");
|
||||
PreferencesUtils.getKey(context, R.string.track_color_mode_percentage_key));
|
||||
assertEquals(speedMargin + 2, dynamicSpeedTrackPathDescriptor.getSpeedMargin());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link
|
||||
* DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the values of speedMargin is "".
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the values of speedMargin is the default value.
|
||||
*/
|
||||
public void testOnSharedPreferenceChanged_emptyValue() {
|
||||
public void testOnSharedPreferenceChanged_defaultValue() {
|
||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
||||
context);
|
||||
// Change value in shared preferences
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_dynamic_speed_variation_key), "");
|
||||
sharedPreferencesEditor.commit();
|
||||
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_percentage_key,
|
||||
PreferencesUtils.TRACK_COLOR_MODE_PERCENTAGE_DEFAULT);
|
||||
dynamicSpeedTrackPathDescriptor.onSharedPreferenceChanged(sharedPreferences,
|
||||
context.getString(R.string.track_color_mode_dynamic_speed_variation_key));
|
||||
PreferencesUtils.getKey(context, R.string.track_color_mode_percentage_key));
|
||||
// The default value of speedMargin is 25.
|
||||
assertEquals(25, dynamicSpeedTrackPathDescriptor.getSpeedMargin());
|
||||
assertEquals(PreferencesUtils.TRACK_COLOR_MODE_PERCENTAGE_DEFAULT,
|
||||
dynamicSpeedTrackPathDescriptor.getSpeedMargin());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +124,8 @@ public class DynamicSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
* id.
|
||||
*/
|
||||
public void testNeedsRedraw_WrongTrackId() {
|
||||
PreferencesUtils.setSelectedTrackId(context, -1L);
|
||||
PreferencesUtils.setLong(
|
||||
context, R.string.selected_track_id_key, PreferencesUtils.SELECTED_TRACK_ID_DEFAULT);
|
||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
||||
context);
|
||||
assertEquals(false, dynamicSpeedTrackPathDescriptor.needsRedraw());
|
||||
@@ -160,9 +140,9 @@ public class DynamicSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
context);
|
||||
double[] averageMovingSpeeds = { 0, 30, 30, 30 };
|
||||
double[] newAverageMovingSpeed = { 20, 30,
|
||||
// Difference is less than CRITICAL_DIFFERENCE_PERCENTAGE
|
||||
// Difference is less than CRITICAL_DIFFERENCE_PERCENTAGE
|
||||
30 * (1 + (DynamicSpeedTrackPathDescriptor.CRITICAL_DIFFERENCE_PERCENTAGE / 100) / 2),
|
||||
// Difference is more than CRITICAL_DIFFERENCE_PERCENTAGE
|
||||
// Difference is more than CRITICAL_DIFFERENCE_PERCENTAGE
|
||||
30 * (1 + (DynamicSpeedTrackPathDescriptor.CRITICAL_DIFFERENCE_PERCENTAGE / 100.00) * 2) };
|
||||
boolean[] expectedValues = { true, false, false, true };
|
||||
double[] expectedAverageMovingSpeed = { 20, 30, 30,
|
||||
@@ -172,8 +152,8 @@ public class DynamicSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
dynamicSpeedTrackPathDescriptor.setAverageMovingSpeed(averageMovingSpeeds[i]);
|
||||
assertEquals(expectedValues[i], dynamicSpeedTrackPathDescriptor.isDifferenceSignificant(
|
||||
averageMovingSpeeds[i], newAverageMovingSpeed[i]));
|
||||
assertEquals(expectedAverageMovingSpeed[i],
|
||||
dynamicSpeedTrackPathDescriptor.getAverageMovingSpeed());
|
||||
assertEquals(
|
||||
expectedAverageMovingSpeed[i], dynamicSpeedTrackPathDescriptor.getAverageMovingSpeed());
|
||||
}
|
||||
}
|
||||
}
|
||||
+39
-82
@@ -16,52 +16,42 @@
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
/**
|
||||
* Tests for the {@link DynamicSpeedTrackPathDescriptor}.
|
||||
*
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class FixedSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
|
||||
private Context context;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private Editor sharedPreferencesEditor;
|
||||
private int slowDefault;
|
||||
private int normalDefault;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
context = getContext();
|
||||
sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
sharedPreferencesEditor = sharedPreferences.edit();
|
||||
// Get the default value
|
||||
slowDefault = 9;
|
||||
normalDefault = 15;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the initialization of slowSpeed and normalSpeed in {@link
|
||||
* DynamicSpeedTrackPathDescriptor#DynamicSpeedTrackPathDescriptor(Context)}.
|
||||
* Tests the initialization of slowSpeed and normalSpeed in {@link DynamicSpeedTrackPathDescriptor#DynamicSpeedTrackPathDescriptor(Context)}
|
||||
* .
|
||||
*/
|
||||
public void testConstructor() {
|
||||
String[] slowSpeedsInShPre = { "0", "1", "99", "" };
|
||||
int[] slowSpeedExpectations = { 0, 1, 99, slowDefault };
|
||||
String[] normalSpeedsInShPre = { "0", "1", "99", "" };
|
||||
int[] normalSpeedExpectations = { 0, 1, 99, normalDefault };
|
||||
for (int i = 0; i < slowSpeedsInShPre.length; i++) {
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_fixed_speed_slow_key), slowSpeedsInShPre[i]);
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_fixed_speed_medium_key),
|
||||
normalSpeedsInShPre[i]);
|
||||
sharedPreferencesEditor.commit();
|
||||
int[] slowSpeedExpectations = { 0, 1, 99, PreferencesUtils.TRACK_COLOR_MODE_SLOW_DEFAULT };
|
||||
int[] normalSpeedExpectations = { 0, 1, 99, PreferencesUtils.TRACK_COLOR_MODE_MEDIUM_DEFAULT };
|
||||
for (int i = 0; i < slowSpeedExpectations.length; i++) {
|
||||
PreferencesUtils.setInt(
|
||||
context, R.string.track_color_mode_slow_key, slowSpeedExpectations[i]);
|
||||
PreferencesUtils.setInt(
|
||||
context, R.string.track_color_mode_medium_key, normalSpeedExpectations[i]);
|
||||
FixedSpeedTrackPathDescriptor fixedSpeedTrackPathDescriptor = new FixedSpeedTrackPathDescriptor(
|
||||
context);
|
||||
assertEquals(slowSpeedExpectations[i], fixedSpeedTrackPathDescriptor.getSlowSpeed());
|
||||
@@ -70,8 +60,7 @@ public class FixedSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link
|
||||
* DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the key is null.
|
||||
*/
|
||||
public void testOnSharedPreferenceChanged_null_key() {
|
||||
@@ -80,22 +69,15 @@ public class FixedSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
int slowSpeed = fixedSpeedTrackPathDescriptor.getSlowSpeed();
|
||||
int normalSpeed = fixedSpeedTrackPathDescriptor.getNormalSpeed();
|
||||
// Change value in shared preferences
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_fixed_speed_slow_key),
|
||||
Integer.toString(slowSpeed + 2));
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_fixed_speed_medium_key),
|
||||
Integer.toString(normalSpeed + 2));
|
||||
sharedPreferencesEditor.commit();
|
||||
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_slow_key, slowSpeed + 2);
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_medium_key, normalSpeed + 2);
|
||||
fixedSpeedTrackPathDescriptor.onSharedPreferenceChanged(sharedPreferences, null);
|
||||
assertEquals(slowSpeed, fixedSpeedTrackPathDescriptor.getSlowSpeed());
|
||||
assertEquals(normalSpeed, fixedSpeedTrackPathDescriptor.getNormalSpeed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link
|
||||
* DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the key is not null, and not slowSpeed and not normalSpeed.
|
||||
*/
|
||||
public void testOnSharedPreferenceChanged_other_key() {
|
||||
@@ -104,84 +86,59 @@ public class FixedSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
int slowSpeed = fixedSpeedTrackPathDescriptor.getSlowSpeed();
|
||||
int normalSpeed = fixedSpeedTrackPathDescriptor.getNormalSpeed();
|
||||
// Change value in shared preferences
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_fixed_speed_slow_key),
|
||||
Integer.toString(slowSpeed + 2));
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_fixed_speed_medium_key),
|
||||
Integer.toString(normalSpeed + 2));
|
||||
sharedPreferencesEditor.commit();
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_slow_key, slowSpeed + 2);
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_medium_key, normalSpeed + 2);
|
||||
fixedSpeedTrackPathDescriptor.onSharedPreferenceChanged(sharedPreferences, "anyKey");
|
||||
assertEquals(slowSpeed, fixedSpeedTrackPathDescriptor.getSlowSpeed());
|
||||
assertEquals(normalSpeed, fixedSpeedTrackPathDescriptor.getNormalSpeed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link
|
||||
* DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the key is slowSpeed.
|
||||
*/
|
||||
public void testOnSharedPreferenceChanged_slowSpeedKey() {
|
||||
FixedSpeedTrackPathDescriptor fixedSpeedTrackPathDescriptor = new FixedSpeedTrackPathDescriptor(
|
||||
context);
|
||||
int slowSpeed = fixedSpeedTrackPathDescriptor.getSlowSpeed();
|
||||
int normalSpeed = fixedSpeedTrackPathDescriptor.getNormalSpeed();
|
||||
// Change value in shared preferences
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_fixed_speed_slow_key),
|
||||
Integer.toString(slowSpeed + 2));
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_fixed_speed_medium_key),
|
||||
Integer.toString(normalSpeed + 2));
|
||||
sharedPreferencesEditor.commit();
|
||||
fixedSpeedTrackPathDescriptor.onSharedPreferenceChanged(sharedPreferences,
|
||||
context.getString(R.string.track_color_mode_fixed_speed_slow_key));
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_slow_key, slowSpeed + 2);
|
||||
fixedSpeedTrackPathDescriptor.onSharedPreferenceChanged(
|
||||
sharedPreferences, context.getString(R.string.track_color_mode_slow_key));
|
||||
assertEquals(slowSpeed + 2, fixedSpeedTrackPathDescriptor.getSlowSpeed());
|
||||
assertEquals(normalSpeed + 2, fixedSpeedTrackPathDescriptor.getNormalSpeed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link
|
||||
* DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the key is normalSpeed.
|
||||
*/
|
||||
public void testOnSharedPreferenceChanged_normalSpeedKey() {
|
||||
FixedSpeedTrackPathDescriptor fixedSpeedTrackPathDescriptor = new FixedSpeedTrackPathDescriptor(
|
||||
context);
|
||||
int slowSpeed = fixedSpeedTrackPathDescriptor.getSlowSpeed();
|
||||
int normalSpeed = fixedSpeedTrackPathDescriptor.getNormalSpeed();
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_fixed_speed_slow_key),
|
||||
Integer.toString(slowSpeed + 4));
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_fixed_speed_medium_key),
|
||||
Integer.toString(normalSpeed + 4));
|
||||
sharedPreferencesEditor.commit();
|
||||
|
||||
fixedSpeedTrackPathDescriptor.onSharedPreferenceChanged(sharedPreferences,
|
||||
context.getString(R.string.track_color_mode_fixed_speed_medium_key));
|
||||
assertEquals(slowSpeed + 4, fixedSpeedTrackPathDescriptor.getSlowSpeed());
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_medium_key, normalSpeed + 4);
|
||||
fixedSpeedTrackPathDescriptor.onSharedPreferenceChanged(
|
||||
sharedPreferences, context.getString(R.string.track_color_mode_medium_key));
|
||||
assertEquals(normalSpeed + 4, fixedSpeedTrackPathDescriptor.getNormalSpeed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link
|
||||
* DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the values of slowSpeed and normalSpeed in SharedPreference
|
||||
* is "". In such situation, the default value should get returned.
|
||||
* are the default values.
|
||||
*/
|
||||
public void testOnSharedPreferenceChanged_emptyValue() {
|
||||
public void testOnSharedPreferenceChanged_defaultValue() {
|
||||
FixedSpeedTrackPathDescriptor fixedSpeedTrackPathDescriptor = new FixedSpeedTrackPathDescriptor(
|
||||
context);
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_fixed_speed_slow_key), "");
|
||||
sharedPreferencesEditor.putString(
|
||||
context.getString(R.string.track_color_mode_fixed_speed_medium_key), "");
|
||||
sharedPreferencesEditor.commit();
|
||||
|
||||
fixedSpeedTrackPathDescriptor.onSharedPreferenceChanged(sharedPreferences,
|
||||
context.getString(R.string.track_color_mode_fixed_speed_medium_key));
|
||||
assertEquals(slowDefault, fixedSpeedTrackPathDescriptor.getSlowSpeed());
|
||||
assertEquals(normalDefault, fixedSpeedTrackPathDescriptor.getNormalSpeed());
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_slow_key,
|
||||
PreferencesUtils.TRACK_COLOR_MODE_SLOW_DEFAULT);
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_medium_key,
|
||||
PreferencesUtils.TRACK_COLOR_MODE_MEDIUM_DEFAULT);
|
||||
fixedSpeedTrackPathDescriptor.onSharedPreferenceChanged(
|
||||
sharedPreferences, context.getString(R.string.track_color_mode_medium_key));
|
||||
assertEquals(PreferencesUtils.TRACK_COLOR_MODE_SLOW_DEFAULT,
|
||||
fixedSpeedTrackPathDescriptor.getSlowSpeed());
|
||||
assertEquals(PreferencesUtils.TRACK_COLOR_MODE_MEDIUM_DEFAULT,
|
||||
fixedSpeedTrackPathDescriptor.getNormalSpeed());
|
||||
}
|
||||
}
|
||||
+11
-17
@@ -15,11 +15,10 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
|
||||
/**
|
||||
@@ -41,25 +40,20 @@ public class TrackPathPainterFactoryTest extends TrackPathPainterTestCase {
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
SharedPreferences prefs = context.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
if (prefs == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
testTrackPathPainterFactorySpecific(context, prefs, R.string.display_track_color_value_none,
|
||||
SingleColorTrackPathPainter.class);
|
||||
testTrackPathPainterFactorySpecific(context, prefs, R.string.display_track_color_value_fixed,
|
||||
DynamicSpeedTrackPathPainter.class);
|
||||
testTrackPathPainterFactorySpecific(context, prefs, R.string.display_track_color_value_dynamic,
|
||||
testTrackPathPainterFactorySpecific(context,
|
||||
R.string.settings_map_track_color_mode_single_value, SingleColorTrackPathPainter.class);
|
||||
testTrackPathPainterFactorySpecific(context, R.string.settings_map_track_color_mode_fixed_value,
|
||||
DynamicSpeedTrackPathPainter.class);
|
||||
testTrackPathPainterFactorySpecific(context,
|
||||
R.string.settings_map_track_color_mode_dynamic_value, DynamicSpeedTrackPathPainter.class);
|
||||
}
|
||||
|
||||
private <T> void testTrackPathPainterFactorySpecific(Context context, SharedPreferences prefs,
|
||||
int track_color_mode, Class <?> c) {
|
||||
prefs.edit().putString(context.getString(R.string.track_color_mode_key),
|
||||
context.getString(track_color_mode)).apply();
|
||||
|
||||
private <T> void testTrackPathPainterFactorySpecific(
|
||||
Context context, int track_color_mode, Class<?> c) {
|
||||
PreferencesUtils.setString(
|
||||
context, R.string.track_color_mode_key, context.getString(track_color_mode));
|
||||
|
||||
int startLocationIdx = 0;
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
|
||||
+104
-105
@@ -34,7 +34,6 @@ import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.database.Cursor;
|
||||
import android.location.Location;
|
||||
import android.net.Uri;
|
||||
@@ -66,7 +65,6 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
|
||||
private Context context;
|
||||
private MyTracksProviderUtils providerUtils;
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
/*
|
||||
* In order to support starting and binding to the service in the same
|
||||
@@ -160,14 +158,16 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
|
||||
providerUtils = MyTracksProviderUtils.Factory.get(context);
|
||||
|
||||
sharedPreferences = context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
// Let's use default values.
|
||||
sharedPreferences.edit().clear().apply();
|
||||
|
||||
// Disable auto resume by default.
|
||||
updateAutoResumePrefs(0, -1);
|
||||
updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT, 0);
|
||||
// No recording track.
|
||||
PreferencesUtils.setRecordingTrackId(context, -1L);
|
||||
PreferencesUtils.setLong(
|
||||
context, R.string.recording_track_id_key, PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@@ -188,7 +188,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
createDummyTrack(123L, System.currentTimeMillis(), true);
|
||||
|
||||
// Clear the number of attempts and set the timeout to 10 min.
|
||||
updateAutoResumePrefs(0, 10);
|
||||
updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT,
|
||||
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
|
||||
|
||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||
Intent startIntent = createStartIntent();
|
||||
@@ -210,7 +211,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
// TODO: If fixed, remove "disabled" prefix from the test name.
|
||||
@MediumTest
|
||||
public void disabledTestResumeAfterReboot_simulateReboot() throws Exception {
|
||||
updateAutoResumePrefs(0, 10);
|
||||
updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT,
|
||||
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
|
||||
ITrackRecordingService service = bindAndGetService(createStartIntent());
|
||||
assertFalse(service.isRecording());
|
||||
|
||||
@@ -219,7 +221,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
assertTrue(service.isRecording());
|
||||
assertEquals(id, service.getRecordingTrackId());
|
||||
shutdownService();
|
||||
assertEquals(id, PreferencesUtils.getRecordingTrackId(context));
|
||||
assertEquals(id, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
||||
|
||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||
Intent startIntent = createStartIntent();
|
||||
@@ -236,7 +238,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
createDummyTrack(123L, System.currentTimeMillis(), false);
|
||||
|
||||
// Clear the number of attempts and set the timeout to 10 min.
|
||||
updateAutoResumePrefs(0, 10);
|
||||
updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT,
|
||||
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
|
||||
|
||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||
Intent startIntent = createStartIntent();
|
||||
@@ -256,7 +259,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
createDummyTrack(123L, System.currentTimeMillis() - 20 * 60 * 1000, true);
|
||||
|
||||
// Clear the number of attempts and set the timeout to 10 min.
|
||||
updateAutoResumePrefs(0, 10);
|
||||
updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT,
|
||||
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
|
||||
|
||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||
Intent startIntent = createStartIntent();
|
||||
@@ -276,8 +280,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
createDummyTrack(123L, System.currentTimeMillis(), true);
|
||||
|
||||
// Set the number of attempts to max.
|
||||
updateAutoResumePrefs(
|
||||
TrackRecordingService.MAX_AUTO_RESUME_TRACK_RETRY_ATTEMPTS, 10);
|
||||
updateAutoResumePrefs(TrackRecordingService.MAX_AUTO_RESUME_TRACK_RETRY_ATTEMPTS,
|
||||
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
|
||||
|
||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||
Intent startIntent = createStartIntent();
|
||||
@@ -315,7 +319,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
@MediumTest
|
||||
public void testRecording_orphanedRecordingTrack() throws Exception {
|
||||
// Just set recording track to a bogus value.
|
||||
PreferencesUtils.setRecordingTrackId(context, 256L);
|
||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key, 256L);
|
||||
|
||||
// Make sure that the service will not start recording and will clear
|
||||
// the bogus track.
|
||||
@@ -387,9 +391,10 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
Track track = providerUtils.getTrack(id);
|
||||
assertNotNull(track);
|
||||
assertEquals(id, track.getId());
|
||||
assertEquals(sharedPreferences.getString(context.getString(R.string.default_activity_key), ""),
|
||||
assertEquals(PreferencesUtils.getString(
|
||||
context, R.string.default_activity_key, PreferencesUtils.DEFAULT_ACTIVITY_DEFAULT),
|
||||
track.getCategory());
|
||||
assertEquals(id, PreferencesUtils.getRecordingTrackId(context));
|
||||
assertEquals(id, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
||||
assertEquals(id, service.getRecordingTrackId());
|
||||
|
||||
// Verify that the start broadcast was received.
|
||||
@@ -415,7 +420,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
long newTrack = service.startNewTrack();
|
||||
assertEquals(-1L, newTrack);
|
||||
|
||||
assertEquals(123L, PreferencesUtils.getRecordingTrackId(context));
|
||||
assertEquals(123L, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
||||
assertEquals(123L, service.getRecordingTrackId());
|
||||
}
|
||||
|
||||
@@ -434,8 +439,9 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
// End the current track.
|
||||
service.endCurrentTrack();
|
||||
assertFalse(service.isRecording());
|
||||
assertEquals(-1L, PreferencesUtils.getRecordingTrackId(context));
|
||||
assertEquals(-1L, service.getRecordingTrackId());
|
||||
assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT,
|
||||
PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
||||
assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, service.getRecordingTrackId());
|
||||
|
||||
// Verify that the stop broadcast was received.
|
||||
assertTrue(stopReceiver.waitUntilReceived(1));
|
||||
@@ -457,8 +463,9 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
// Ending the current track when there is no recording should not result in any error.
|
||||
service.endCurrentTrack();
|
||||
|
||||
assertEquals(-1L, PreferencesUtils.getRecordingTrackId(context));
|
||||
assertEquals(-1L, service.getRecordingTrackId());
|
||||
assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT,
|
||||
PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
||||
assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, service.getRecordingTrackId());
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
@@ -491,11 +498,9 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
assertEquals(1, service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS));
|
||||
assertEquals(2, service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS));
|
||||
|
||||
Waypoint wpt = providerUtils.getWaypoint(1);
|
||||
assertEquals(getContext().getString(R.string.marker_statistics_icon_url),
|
||||
wpt.getIcon());
|
||||
assertEquals(getContext().getString(R.string.marker_edit_type_statistics),
|
||||
wpt.getName());
|
||||
Waypoint wpt = providerUtils.getWaypoint(2);
|
||||
assertEquals(getContext().getString(R.string.marker_statistics_icon_url), wpt.getIcon());
|
||||
assertEquals(getContext().getString(R.string.marker_statistics_name_format, 1), wpt.getName());
|
||||
assertEquals(Waypoint.TYPE_STATISTICS, wpt.getType());
|
||||
assertEquals(123L, wpt.getTrackId());
|
||||
assertEquals(0.0, wpt.getLength());
|
||||
@@ -512,7 +517,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
assertFalse(service.isRecording());
|
||||
|
||||
try {
|
||||
service.insertWaypoint(WaypointCreationRequest.DEFAULT_MARKER);
|
||||
service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT);
|
||||
fail("Expecting IllegalStateException");
|
||||
} catch (IllegalStateException e) {
|
||||
// Expected.
|
||||
@@ -526,12 +531,11 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
ITrackRecordingService service = bindAndGetService(createStartIntent());
|
||||
assertTrue(service.isRecording());
|
||||
|
||||
assertEquals(1, service.insertWaypoint(WaypointCreationRequest.DEFAULT_MARKER));
|
||||
assertEquals(1, service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT));
|
||||
Waypoint wpt = providerUtils.getWaypoint(1);
|
||||
assertEquals(getContext().getString(R.string.marker_waypoint_icon_url),
|
||||
wpt.getIcon());
|
||||
assertEquals(getContext().getString(R.string.marker_edit_type_waypoint),
|
||||
wpt.getName());
|
||||
assertEquals(getContext().getString(R.string.marker_waypoint_name_format, 1), wpt.getName());
|
||||
assertEquals(Waypoint.TYPE_WAYPOINT, wpt.getType());
|
||||
assertEquals(123L, wpt.getTrackId());
|
||||
assertEquals(0.0, wpt.getLength());
|
||||
@@ -540,95 +544,120 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_noAnnouncementFreq() throws Exception {
|
||||
functionalTest(R.string.announcement_frequency_key, (Object) null);
|
||||
public void testWithProperties_announcementFrequencyDefault() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.announcement_frequency_key,
|
||||
PreferencesUtils.ANNOUNCEMENT_FREQUENCY_DEFAULT);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_defaultAnnouncementFreq() throws Exception {
|
||||
functionalTest(R.string.announcement_frequency_key, 1);
|
||||
public void testWithProperties_announcementFrequencyByDistance() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.announcement_frequency_key, -1);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_noMaxRecordingDist() throws Exception {
|
||||
functionalTest(R.string.max_recording_distance_key, (Object) null);
|
||||
public void testWithProperties_announcementFrequencyByTime() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.announcement_frequency_key, 1);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_maxRecordingDistanceDefault() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.max_recording_distance_key,
|
||||
PreferencesUtils.MAX_RECORDING_DISTANCE_DEFAULT);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_defaultMaxRecordingDist() throws Exception {
|
||||
functionalTest(R.string.max_recording_distance_key, 5);
|
||||
public void testWithProperties_maxRecordingDistance() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.max_recording_distance_key, 50);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_noMinRecordingDist() throws Exception {
|
||||
functionalTest(R.string.min_recording_distance_key, (Object) null);
|
||||
public void testWithProperties_minRecordingDistanceDefault() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.min_recording_distance_key,
|
||||
PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_defaultMinRecordingDist() throws Exception {
|
||||
functionalTest(R.string.min_recording_distance_key, 2);
|
||||
public void testWithProperties_minRecordingDistance() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.min_recording_distance_key, 2);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_noSplitFreq() throws Exception {
|
||||
functionalTest(R.string.split_frequency_key, (Object) null);
|
||||
public void testWithProperties_splitFrequencyDefault() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.split_frequency_key,
|
||||
PreferencesUtils.SPLIT_FREQUENCY_DEFAULT);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_defaultSplitFreqByDist() throws Exception {
|
||||
functionalTest(R.string.split_frequency_key, 5);
|
||||
public void testWithProperties_splitFrequencyByDistance() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.split_frequency_key, -1);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_defaultSplitFreqByTime() throws Exception {
|
||||
functionalTest(R.string.split_frequency_key, -2);
|
||||
public void testWithProperties_splitFrequencyByTime() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.split_frequency_key, 1);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_noMetricUnits() throws Exception {
|
||||
functionalTest(R.string.metric_units_key, (Object) null);
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_metricUnitsEnabled() throws Exception {
|
||||
functionalTest(R.string.metric_units_key, true);
|
||||
public void testWithProperties_metricUnitsDefault() throws Exception {
|
||||
PreferencesUtils.setBoolean(
|
||||
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_metricUnitsDisabled() throws Exception {
|
||||
functionalTest(R.string.metric_units_key, false);
|
||||
PreferencesUtils.setBoolean(context, R.string.metric_units_key, false);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_noMinRecordingInterval() throws Exception {
|
||||
functionalTest(R.string.min_recording_interval_key, (Object) null);
|
||||
public void testWithProperties_minRecordingIntervalDefault() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.min_recording_interval_key,
|
||||
PreferencesUtils.MIN_RECORDING_INTERVAL_DEFAULT);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_defaultMinRecordingInterval()
|
||||
throws Exception {
|
||||
functionalTest(R.string.min_recording_interval_key, 3);
|
||||
public void testWithProperties_minRecordingInterval() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.min_recording_interval_key, 2);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_noMinRequiredAccuracy() throws Exception {
|
||||
functionalTest(R.string.min_required_accuracy_key, (Object) null);
|
||||
public void testWithProperties_minRequiredAccuracyDefault() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.min_required_accuracy_key,
|
||||
PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_defaultMinRequiredAccuracy() throws Exception {
|
||||
functionalTest(R.string.min_required_accuracy_key, 500);
|
||||
public void testWithProperties_minRequiredAccuracy() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.min_required_accuracy_key, 500);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_noSensorType() throws Exception {
|
||||
functionalTest(R.string.sensor_type_key, (Object) null);
|
||||
public void testWithProperties_sensorTypeDefault() throws Exception {
|
||||
PreferencesUtils.setString(
|
||||
context, R.string.sensor_type_key, context.getString(R.string.sensor_type_value_none));
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_zephyrSensorType() throws Exception {
|
||||
functionalTest(R.string.sensor_type_key,
|
||||
context.getString(R.string.sensor_type_value_zephyr));
|
||||
public void testWithProperties_sensorTypeZephyr() throws Exception {
|
||||
PreferencesUtils.setString(
|
||||
context, R.string.sensor_type_key, context.getString(R.string.sensor_type_value_zephyr));
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
private ITrackRecordingService bindAndGetService(Intent intent) {
|
||||
@@ -650,12 +679,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
}
|
||||
|
||||
private void updateAutoResumePrefs(int attempts, int timeoutMins) {
|
||||
Editor editor = sharedPreferences.edit();
|
||||
editor.putInt(context.getString(
|
||||
R.string.auto_resume_track_current_retry_key), attempts);
|
||||
editor.putInt(context.getString(
|
||||
R.string.auto_resume_track_timeout_key), timeoutMins);
|
||||
editor.apply();
|
||||
PreferencesUtils.setInt(context, R.string.auto_resume_track_current_retry_key, attempts);
|
||||
PreferencesUtils.setInt(context, R.string.auto_resume_track_timeout_key, timeoutMins);
|
||||
}
|
||||
|
||||
private Intent createStartIntent() {
|
||||
@@ -668,34 +693,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
assertTrue(track.getId() >= 0);
|
||||
providerUtils.insertTrack(track);
|
||||
assertEquals(track.getId(), providerUtils.getTrack(track.getId()).getId());
|
||||
PreferencesUtils.setRecordingTrackId(context, isRecording ? track.getId() : -1L);
|
||||
}
|
||||
|
||||
// TODO: We support multiple values for readability, however this test's
|
||||
// base class doesn't properly shutdown the service, so it's not possible
|
||||
// to pass more than 1 value at a time.
|
||||
private void functionalTest(int resourceId, Object ...values)
|
||||
throws Exception {
|
||||
final String key = context.getString(resourceId);
|
||||
for (Object value : values) {
|
||||
// Remove all properties and set the property for the given key.
|
||||
Editor editor = sharedPreferences.edit();
|
||||
editor.clear();
|
||||
if (value instanceof String) {
|
||||
editor.putString(key, (String) value);
|
||||
} else if (value instanceof Long) {
|
||||
editor.putLong(key, (Long) value);
|
||||
} else if (value instanceof Integer) {
|
||||
editor.putInt(key, (Integer) value);
|
||||
} else if (value instanceof Boolean) {
|
||||
editor.putBoolean(key, (Boolean) value);
|
||||
} else if (value == null) {
|
||||
// Do nothing, as clear above has already removed this property.
|
||||
}
|
||||
editor.apply();
|
||||
|
||||
fullRecordingSession();
|
||||
}
|
||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key, isRecording ? track.getId()
|
||||
: PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
|
||||
}
|
||||
|
||||
private void fullRecordingSession() throws Exception {
|
||||
@@ -709,7 +708,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
Track track = providerUtils.getTrack(id);
|
||||
assertNotNull(track);
|
||||
assertEquals(id, track.getId());
|
||||
assertEquals(id, PreferencesUtils.getRecordingTrackId(context));
|
||||
assertEquals(id, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
||||
assertEquals(id, service.getRecordingTrackId());
|
||||
|
||||
// Insert a few points, markers and statistics.
|
||||
@@ -727,7 +726,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
if (i % 10 == 0) {
|
||||
service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
|
||||
} else if (i % 7 == 0) {
|
||||
service.insertWaypoint(WaypointCreationRequest.DEFAULT_MARKER);
|
||||
service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-7
@@ -1,6 +1,7 @@
|
||||
package com.google.android.apps.mytracks.services.sensors;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -10,13 +11,11 @@ import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
public class SensorManagerFactoryTest extends AndroidTestCase {
|
||||
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
sharedPreferences = getContext().getSharedPreferences(
|
||||
SharedPreferences sharedPreferences = getContext().getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
// Let's use default values.
|
||||
sharedPreferences.edit().clear().apply();
|
||||
@@ -38,10 +37,7 @@ public class SensorManagerFactoryTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
private void assertClassForName(Class<?> c, int i) {
|
||||
sharedPreferences.edit()
|
||||
.putString(getContext().getString(R.string.sensor_type_key),
|
||||
getContext().getString(i))
|
||||
.apply();
|
||||
PreferencesUtils.setString(getContext(), R.string.sensor_type_key, getContext().getString(i));
|
||||
SensorManager sm = SensorManagerFactory.getInstance().getSensorManager(getContext());
|
||||
assertNotNull(sm);
|
||||
assertTrue(c.isInstance(sm));
|
||||
|
||||
+4
-5
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.services.sensors.ant;
|
||||
import com.dsi.ant.AntMesg;
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -27,7 +28,6 @@ import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
public class AntDirectSensorManagerTest extends AndroidTestCase {
|
||||
|
||||
private SharedPreferences sharedPreferences;
|
||||
private AntSensorBase heartRateSensor;
|
||||
private static final byte HEART_RATE_CHANNEL = 0;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class AntDirectSensorManagerTest extends AndroidTestCase {
|
||||
private AntDirectSensorManager manager;
|
||||
|
||||
public void setUp() {
|
||||
sharedPreferences = getContext().getSharedPreferences(
|
||||
SharedPreferences sharedPreferences = getContext().getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
// Let's use default values.
|
||||
sharedPreferences.edit().clear().apply();
|
||||
@@ -87,9 +87,8 @@ public class AntDirectSensorManagerTest extends AndroidTestCase {
|
||||
manager.handleMessage(AntMesg.MESG_CHANNEL_ID_ID, buff);
|
||||
|
||||
assertEquals(43, heartRateSensor.getDeviceNumber());
|
||||
assertEquals(43,
|
||||
sharedPreferences.getInt(
|
||||
getContext().getString(R.string.ant_heart_rate_sensor_id_key), -1));
|
||||
assertEquals(43, PreferencesUtils.getInt(
|
||||
getContext(), R.string.ant_heart_rate_sensor_id_key, AntSensorManager.WILDCARD));
|
||||
assertNull(manager.getSensorDataSet());
|
||||
}
|
||||
|
||||
|
||||
@@ -130,13 +130,6 @@ public class StringUtilsTest extends AndroidTestCase {
|
||||
assertEquals("-", StringUtils.formatSpeed(getContext(), Double.NEGATIVE_INFINITY, true, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#formatTimeDistance(android.content.Context, long, double, boolean)}.
|
||||
*/
|
||||
public void testFormatTimeDistance() {
|
||||
assertEquals("00:10 5.00 km", StringUtils.formatTimeDistance(getContext(), 10000, 5000, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link StringUtils#formatCData(String)}.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user