Change code style of AdaptiveLocationListenerPolicyTest.

This commit is contained in:
youtaol
2012-05-02 10:39:38 +08:00
parent 85095b5e59
commit 94c11face5
2 changed files with 19 additions and 26 deletions
@@ -16,7 +16,6 @@
package com.google.android.apps.mytracks.services; package com.google.android.apps.mytracks.services;
import com.google.common.annotations.VisibleForTesting;
/** /**
* A LocationListenerPolicy that will change based on how long the user has been * A LocationListenerPolicy that will change based on how long the user has been
@@ -42,12 +41,6 @@ public class AdaptiveLocationListenerPolicy implements LocationListenerPolicy {
private final int minDistance; private final int minDistance;
/**
* The smallest unit of interval to update.
*/
@VisibleForTesting
static final long SMALLEST_INTERVAL_UNIT = 1000;
/** /**
* The time the user has been at the current location, in milliseconds. * The time the user has been at the current location, in milliseconds.
*/ */
@@ -71,7 +64,7 @@ public class AdaptiveLocationListenerPolicy implements LocationListenerPolicy {
public long getDesiredPollingInterval() { public long getDesiredPollingInterval() {
long desiredInterval = idleTime / 2; long desiredInterval = idleTime / 2;
// Round to avoid setting the interval too often. // Round to avoid setting the interval too often.
desiredInterval = (desiredInterval / SMALLEST_INTERVAL_UNIT) * SMALLEST_INTERVAL_UNIT; desiredInterval = (desiredInterval / 1000) * 1000;
return Math.max(Math.min(maxInterval, desiredInterval), return Math.max(Math.min(maxInterval, desiredInterval),
minInterval); minInterval);
} }
@@ -25,18 +25,18 @@ import junit.framework.TestCase;
public class AdaptiveLocationListenerPolicyTest extends TestCase { public class AdaptiveLocationListenerPolicyTest extends TestCase {
private AdaptiveLocationListenerPolicy adocationListenerPolicy; private AdaptiveLocationListenerPolicy adocationListenerPolicy;
private long min = AdaptiveLocationListenerPolicy.SMALLEST_INTERVAL_UNIT; private static final long MIN = 1000;
private long max = AdaptiveLocationListenerPolicy.SMALLEST_INTERVAL_UNIT * 3; private static final long MAX = 3000;
private int minDistance = 10; private static final int MIN_DISTANCE = 10;
private long newIdleTimeBig = AdaptiveLocationListenerPolicy.SMALLEST_INTERVAL_UNIT * 10; private static final long NEW_IDLE_TIME_BIG = 10000;
private long newIdleTimeNormal = AdaptiveLocationListenerPolicy.SMALLEST_INTERVAL_UNIT * 5; private static final long NEW_IDLE_TIME_NORMAL = 5000;
private long newIdleTimeSmall = AdaptiveLocationListenerPolicy.SMALLEST_INTERVAL_UNIT * 2; private static final long NEW_IDLE_TIME_SMALL = 2000;
private long newIdleTimeLessThanMin = AdaptiveLocationListenerPolicy.SMALLEST_INTERVAL_UNIT / 2; private static final long NEW_IDLE_TIME_LESS_THAN_MIN = 500;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
adocationListenerPolicy = new AdaptiveLocationListenerPolicy(min, max, minDistance); adocationListenerPolicy = new AdaptiveLocationListenerPolicy(MIN, MAX, MIN_DISTANCE);
} }
/** /**
@@ -50,25 +50,25 @@ public class AdaptiveLocationListenerPolicyTest extends TestCase {
* </ul> * </ul>
*/ */
public void testGetDesiredPollingInterval() { public void testGetDesiredPollingInterval() {
adocationListenerPolicy.updateIdleTime(newIdleTimeBig); adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_BIG);
assertEquals(max, adocationListenerPolicy.getDesiredPollingInterval()); assertEquals(MAX, adocationListenerPolicy.getDesiredPollingInterval());
adocationListenerPolicy.updateIdleTime(newIdleTimeNormal); adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_NORMAL);
assertEquals((newIdleTimeNormal / 2 / AdaptiveLocationListenerPolicy.SMALLEST_INTERVAL_UNIT) assertEquals((NEW_IDLE_TIME_NORMAL / 2000)
* AdaptiveLocationListenerPolicy.SMALLEST_INTERVAL_UNIT, * 1000,
adocationListenerPolicy.getDesiredPollingInterval()); adocationListenerPolicy.getDesiredPollingInterval());
adocationListenerPolicy.updateIdleTime(newIdleTimeSmall); adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_SMALL);
assertEquals(min, adocationListenerPolicy.getDesiredPollingInterval()); assertEquals(MIN, adocationListenerPolicy.getDesiredPollingInterval());
adocationListenerPolicy.updateIdleTime(newIdleTimeLessThanMin); adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_LESS_THAN_MIN);
assertEquals(min, adocationListenerPolicy.getDesiredPollingInterval()); assertEquals(MIN, adocationListenerPolicy.getDesiredPollingInterval());
} }
/** /**
* Tests the method {@link AdaptiveLocationListenerPolicy#getMinDistance()}. * Tests the method {@link AdaptiveLocationListenerPolicy#getMinDistance()}.
*/ */
public void testGetMinDistance() { public void testGetMinDistance() {
assertEquals(minDistance, adocationListenerPolicy.getMinDistance()); assertEquals(MIN_DISTANCE, adocationListenerPolicy.getMinDistance());
} }
} }