Index: chrome/android/javatests/src/org/chromium/chrome/browser/omaha/ExponentialBackoffSchedulerTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/omaha/ExponentialBackoffSchedulerTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/omaha/ExponentialBackoffSchedulerTest.java |
index c84a94dc9cd1189cc09ac7c912052aa21e764e4a..373c4e78240f506379c1fadab707adcd40891c46 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/omaha/ExponentialBackoffSchedulerTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/omaha/ExponentialBackoffSchedulerTest.java |
@@ -6,14 +6,20 @@ package org.chromium.chrome.browser.omaha; |
import android.content.Context; |
import android.content.Intent; |
+import android.support.test.InstrumentationRegistry; |
import android.support.test.filters.SmallTest; |
-import android.test.InstrumentationTestCase; |
+ |
+import org.junit.Assert; |
+import org.junit.Test; |
+import org.junit.runner.RunWith; |
import org.chromium.base.test.util.AdvancedMockContext; |
import org.chromium.base.test.util.Feature; |
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
/** Tests the ExponentialBackoffScheduler. */ |
-public class ExponentialBackoffSchedulerTest extends InstrumentationTestCase { |
+@RunWith(ChromeJUnit4ClassRunner.class) |
+public class ExponentialBackoffSchedulerTest { |
private static final String INTENT_STRING = "schedulerIntent"; |
private static final String PREFERENCE_NAME = "scheduler"; |
private static final long BACKOFF_MS = 15000; |
@@ -22,10 +28,11 @@ public class ExponentialBackoffSchedulerTest extends InstrumentationTestCase { |
/** |
* Checks that the correct number of failures are set/reset. |
*/ |
+ @Test |
@SmallTest |
@Feature({"Omaha", "Sync"}) |
public void testExponentialBackoffSchedulerFailureSetting() { |
- Context targetContext = getInstrumentation().getTargetContext(); |
+ Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); |
TestContext context = new TestContext(targetContext); |
ExponentialBackoffScheduler writer = |
@@ -33,22 +40,24 @@ public class ExponentialBackoffSchedulerTest extends InstrumentationTestCase { |
ExponentialBackoffScheduler reader = |
new ExponentialBackoffScheduler(PREFERENCE_NAME, context, BACKOFF_MS, MAX_MS); |
- assertEquals("Expected no failures for freshly created class", 0, |
- reader.getNumFailedAttempts()); |
+ Assert.assertEquals( |
+ "Expected no failures for freshly created class", 0, reader.getNumFailedAttempts()); |
writer.increaseFailedAttempts(); |
writer.increaseFailedAttempts(); |
- assertEquals("Expected 2 failures after 2 increments.", 2, reader.getNumFailedAttempts()); |
+ Assert.assertEquals( |
+ "Expected 2 failures after 2 increments.", 2, reader.getNumFailedAttempts()); |
writer.resetFailedAttempts(); |
- assertEquals("Expected 0 failures after reset.", 0, reader.getNumFailedAttempts()); |
+ Assert.assertEquals("Expected 0 failures after reset.", 0, reader.getNumFailedAttempts()); |
} |
/** |
* Check that the delay generated by the scheduler is within the correct range. |
*/ |
+ @Test |
@SmallTest |
@Feature({"Omaha", "Sync"}) |
public void testExponentialBackoffSchedulerDelayCalculation() { |
- Context targetContext = getInstrumentation().getTargetContext(); |
+ Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); |
TestContext context = new TestContext(targetContext); |
MockExponentialBackoffScheduler scheduler = |
new MockExponentialBackoffScheduler(PREFERENCE_NAME, context, BACKOFF_MS, MAX_MS); |
@@ -58,8 +67,8 @@ public class ExponentialBackoffSchedulerTest extends InstrumentationTestCase { |
// With no failures, expect the base backoff delay. |
long delay = scheduler.getAlarmTimestamp() - scheduler.getCurrentTime(); |
- assertEquals("Expected delay of " + BACKOFF_MS + " milliseconds.", BACKOFF_MS, |
- delay); |
+ Assert.assertEquals( |
+ "Expected delay of " + BACKOFF_MS + " milliseconds.", BACKOFF_MS, delay); |
// With two failures, expect a delay within [BACKOFF_MS, BACKOFF_MS * 2^2]. |
scheduler.increaseFailedAttempts(); |
@@ -69,17 +78,18 @@ public class ExponentialBackoffSchedulerTest extends InstrumentationTestCase { |
delay = scheduler.getAlarmTimestamp() - scheduler.getCurrentTime(); |
final long minDelay = BACKOFF_MS; |
final long maxDelay = BACKOFF_MS * (1 << scheduler.getNumFailedAttempts()); |
- assertTrue("Expected delay greater than the minimum.", delay >= minDelay); |
- assertTrue("Expected delay within maximum of " + maxDelay, delay <= maxDelay); |
+ Assert.assertTrue("Expected delay greater than the minimum.", delay >= minDelay); |
+ Assert.assertTrue("Expected delay within maximum of " + maxDelay, delay <= maxDelay); |
} |
/** |
* Check that the alarm is being set by the class. |
*/ |
+ @Test |
@SmallTest |
@Feature({"Omaha", "Sync"}) |
public void testExponentialBackoffSchedulerAlarmCreation() { |
- Context targetContext = getInstrumentation().getTargetContext(); |
+ Context targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); |
TestContext context = new TestContext(targetContext); |
MockExponentialBackoffScheduler scheduler = |
@@ -87,8 +97,8 @@ public class ExponentialBackoffSchedulerTest extends InstrumentationTestCase { |
Intent intent = new Intent(INTENT_STRING); |
scheduler.createAlarm(intent, scheduler.calculateNextTimestamp()); |
- assertTrue("Never requested the alarm manager.", context.mRequestedAlarmManager); |
- assertTrue("Never received a call to set the alarm.", scheduler.getAlarmWasSet()); |
+ Assert.assertTrue("Never requested the alarm manager.", context.mRequestedAlarmManager); |
+ Assert.assertTrue("Never received a call to set the alarm.", scheduler.getAlarmWasSet()); |
} |
/** |
@@ -108,7 +118,7 @@ public class ExponentialBackoffSchedulerTest extends InstrumentationTestCase { |
*/ |
@Override |
public Object getSystemService(final String name) { |
- assertTrue("Requested service other than AlarmManager.", |
+ Assert.assertTrue("Requested service other than AlarmManager.", |
Context.ALARM_SERVICE.equals(name)); |
mRequestedAlarmManager = true; |
return super.getSystemService(name); |