mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-07 03:53:05 +02:00
Merge heads
This commit is contained in:
@@ -30,6 +30,7 @@ import com.google.android.apps.mytracks.content.TrackDataHub.ListenerDataType;
|
||||
import com.google.android.apps.mytracks.content.TrackDataListener.ProviderState;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceTest.MockContext;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.android.testing.mocking.AndroidMock;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -70,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 =
|
||||
@@ -87,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;
|
||||
@@ -112,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
|
||||
@@ -797,13 +798,8 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
public void testDisplayPreferencesListen() throws Exception {
|
||||
String metricUnitsKey = PreferencesUtils.getMetricUnitsKey(context);
|
||||
String reportSpeedKey = PreferencesUtils.getReportSpeedKey(context);
|
||||
|
||||
prefs.edit()
|
||||
.putBoolean(metricUnitsKey, true)
|
||||
.putBoolean(reportSpeedKey, 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>();
|
||||
@@ -827,11 +823,10 @@ public class TrackDataHubTest extends AndroidTestCase {
|
||||
|
||||
replay();
|
||||
|
||||
prefs.edit()
|
||||
.putBoolean(reportSpeedKey, false)
|
||||
.apply();
|
||||
PreferencesUtils.setBoolean(context, R.string.report_speed_key, false);
|
||||
OnSharedPreferenceChangeListener listener = listenerCapture.getValue();
|
||||
listener.onSharedPreferenceChanged(prefs, reportSpeedKey);
|
||||
listener.onSharedPreferenceChanged(
|
||||
sharedPreferences, PreferencesUtils.getKey(context, R.string.report_speed_key));
|
||||
|
||||
AndroidMock.verify(dataSources, providerUtils, listener1, listener2);
|
||||
AndroidMock.reset(dataSources, providerUtils, listener1, listener2);
|
||||
@@ -841,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();
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
|
||||
+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;
|
||||
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.android.apps.mytracks.services;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests the {@link AdaptiveLocationListenerPolicy}.
|
||||
*
|
||||
* @author youtaol
|
||||
*/
|
||||
public class AdaptiveLocationListenerPolicyTest extends TestCase {
|
||||
|
||||
private AdaptiveLocationListenerPolicy adocationListenerPolicy;
|
||||
private static final long MIN = 1000;
|
||||
private static final long MAX = 3000;
|
||||
private static final int MIN_DISTANCE = 10;
|
||||
private static final long NEW_IDLE_TIME_BIG = 10000;
|
||||
private static final long NEW_IDLE_TIME_NORMAL = 5000;
|
||||
private static final long NEW_IDLE_TIME_SMALL = 2000;
|
||||
private static final long NEW_IDLE_TIME_LESS_THAN_MIN = 500;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
adocationListenerPolicy = new AdaptiveLocationListenerPolicy(MIN, MAX, MIN_DISTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link AdaptiveLocationListenerPolicy#getDesiredPollingInterval()} in four
|
||||
* situations.
|
||||
* <ul>
|
||||
* <li>The newIdleTime is bigger than max interval.</li>
|
||||
* <li>The newIdleTime is between min and max interval.</li>
|
||||
* <li>The newIdleTime is smaller than max interval.</li>
|
||||
* <li>The newIdleTime is smaller than the smallest interval unit.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public void testGetDesiredPollingInterval() {
|
||||
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_BIG);
|
||||
assertEquals(MAX, adocationListenerPolicy.getDesiredPollingInterval());
|
||||
|
||||
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_NORMAL);
|
||||
// First get the half of NEW_IDLE_TIME_NORMAL, and then round it to the
|
||||
// nearest second.
|
||||
assertEquals((NEW_IDLE_TIME_NORMAL / 2 / 1000) * 1000,
|
||||
adocationListenerPolicy.getDesiredPollingInterval());
|
||||
|
||||
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_SMALL);
|
||||
assertEquals(MIN, adocationListenerPolicy.getDesiredPollingInterval());
|
||||
|
||||
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_LESS_THAN_MIN);
|
||||
assertEquals(MIN, adocationListenerPolicy.getDesiredPollingInterval());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link AdaptiveLocationListenerPolicy#getMinDistance()}.
|
||||
*/
|
||||
public void testGetMinDistance() {
|
||||
assertEquals(MIN_DISTANCE, adocationListenerPolicy.getMinDistance());
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.android.apps.mytracks.services;
|
||||
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.android.testing.mocking.UsesMocks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.RemoteException;
|
||||
import android.test.ServiceTestCase;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
|
||||
/**
|
||||
* Tests {@link ControlRecordingService}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class ControlRecordingServiceTest extends ServiceTestCase<ControlRecordingService> {
|
||||
|
||||
private Context context;
|
||||
private ControlRecordingService controlRecordingService;
|
||||
|
||||
public ControlRecordingServiceTest() {
|
||||
super(ControlRecordingService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
context = getContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the start of {@link ControlRecordingService} and tests the method
|
||||
* {@link ControlRecordingService#onHandleIntent(Intent, ITrackRecordingService)}
|
||||
* to start a track recording.
|
||||
*/
|
||||
@UsesMocks(ITrackRecordingService.class)
|
||||
public void testStartRecording() {
|
||||
assertNull(controlRecordingService);
|
||||
Intent intent = startControlRecordingService(context.getString(R.string.track_action_start));
|
||||
assertNotNull(controlRecordingService);
|
||||
|
||||
ITrackRecordingService iTrackRecordingServiceMock = EasyMock
|
||||
.createStrictMock(ITrackRecordingService.class);
|
||||
try {
|
||||
EasyMock.expect(iTrackRecordingServiceMock.startNewTrack()).andReturn(1L);
|
||||
EasyMock.replay(iTrackRecordingServiceMock);
|
||||
controlRecordingService.onHandleIntent(intent, iTrackRecordingServiceMock);
|
||||
EasyMock.verify(iTrackRecordingServiceMock);
|
||||
} catch (RemoteException e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link ControlRecordingService#onHandleIntent(Intent, ITrackRecordingService)}
|
||||
* to stop a track recording.
|
||||
*/
|
||||
@UsesMocks(ITrackRecordingService.class)
|
||||
public void testStopRecording() {
|
||||
Intent intent = startControlRecordingService(context.getString(R.string.track_action_end));
|
||||
|
||||
ITrackRecordingService iTrackRecordingServiceMock = EasyMock
|
||||
.createStrictMock(ITrackRecordingService.class);
|
||||
try {
|
||||
iTrackRecordingServiceMock.endCurrentTrack();
|
||||
EasyMock.replay(iTrackRecordingServiceMock);
|
||||
controlRecordingService.onHandleIntent(intent, iTrackRecordingServiceMock);
|
||||
EasyMock.verify(iTrackRecordingServiceMock);
|
||||
} catch (RemoteException e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a ControlRecordingService with a specified action.
|
||||
*
|
||||
* @param action the action string in the start intent
|
||||
*/
|
||||
private Intent startControlRecordingService(String action) {
|
||||
Intent intent = new Intent(context, ControlRecordingService.class);
|
||||
intent.setAction(action);
|
||||
startService(intent);
|
||||
controlRecordingService = getService();
|
||||
return intent;
|
||||
}
|
||||
|
||||
}
|
||||
+97
-95
@@ -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
|
||||
@@ -537,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) {
|
||||
@@ -647,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() {
|
||||
@@ -665,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 {
|
||||
@@ -706,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.
|
||||
|
||||
+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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user