Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(912)

Unified Diff: base/android/javatests/src/org/chromium/base/ObserverListTest.java

Issue 2726003002: Auto convert base javatests in content shell apk to JUnit4 (Closed)
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/android/javatests/src/org/chromium/base/ObserverListTest.java
diff --git a/base/android/javatests/src/org/chromium/base/ObserverListTest.java b/base/android/javatests/src/org/chromium/base/ObserverListTest.java
index 6fa4f936ef81d804f197c77a814d225eb3bd26c2..1899f456c59c4a543f02578e76795284425435a3 100644
--- a/base/android/javatests/src/org/chromium/base/ObserverListTest.java
+++ b/base/android/javatests/src/org/chromium/base/ObserverListTest.java
@@ -1,12 +1,16 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.base;
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.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Feature;
import java.util.Collection;
@@ -16,7 +20,8 @@ import java.util.NoSuchElementException;
/**
* Tests for (@link ObserverList}.
*/
-public class ObserverListTest extends InstrumentationTestCase {
+@RunWith(BaseJUnit4ClassRunner.class)
+public class ObserverListTest {
interface Observer {
void observe(int x);
}
@@ -79,6 +84,7 @@ public class ObserverListTest extends InstrumentationTestCase {
return num;
}
+ @Test
@SmallTest
@Feature({"Android-AppBase"})
public void testRemoveWhileIteration() {
@@ -105,17 +111,18 @@ public class ObserverListTest extends InstrumentationTestCase {
for (Observer obs : observerList) obs.observe(10);
// observe should be called twice on a.
- assertEquals(20, a.mTotal);
+ Assert.assertEquals(20, a.mTotal);
// observe should be called twice on b.
- assertEquals(-20, b.mTotal);
+ Assert.assertEquals(-20, b.mTotal);
// evil removed c from the observerList before it got any callbacks.
- assertEquals(0, c.mTotal);
+ Assert.assertEquals(0, c.mTotal);
// observe should be called once on d.
- assertEquals(-10, d.mTotal);
+ Assert.assertEquals(-10, d.mTotal);
// e was never added to the list, observe should not be called.
- assertEquals(0, e.mTotal);
+ Assert.assertEquals(0, e.mTotal);
}
+ @Test
@SmallTest
@Feature({"Android-AppBase"})
public void testAddWhileIteration() {
@@ -131,12 +138,13 @@ public class ObserverListTest extends InstrumentationTestCase {
for (Observer obs : observerList) obs.observe(10);
- assertTrue(observerList.hasObserver(c));
- assertEquals(10, a.mTotal);
- assertEquals(-10, b.mTotal);
- assertEquals(0, c.mTotal);
+ Assert.assertTrue(observerList.hasObserver(c));
+ Assert.assertEquals(10, a.mTotal);
+ Assert.assertEquals(-10, b.mTotal);
+ Assert.assertEquals(0, c.mTotal);
}
+ @Test
@SmallTest
@Feature({"Android-AppBase"})
public void testIterator() {
@@ -144,38 +152,39 @@ public class ObserverListTest extends InstrumentationTestCase {
observerList.addObserver(5);
observerList.addObserver(10);
observerList.addObserver(15);
- assertEquals(3, getSizeOfIterable(observerList));
+ Assert.assertEquals(3, getSizeOfIterable(observerList));
observerList.removeObserver(10);
- assertEquals(2, getSizeOfIterable(observerList));
+ Assert.assertEquals(2, getSizeOfIterable(observerList));
Iterator<Integer> it = observerList.iterator();
- assertTrue(it.hasNext());
- assertTrue(5 == it.next());
- assertTrue(it.hasNext());
- assertTrue(15 == it.next());
- assertFalse(it.hasNext());
+ Assert.assertTrue(it.hasNext());
+ Assert.assertTrue(5 == it.next());
+ Assert.assertTrue(it.hasNext());
+ Assert.assertTrue(15 == it.next());
+ Assert.assertFalse(it.hasNext());
boolean removeExceptionThrown = false;
try {
it.remove();
- fail("Expecting UnsupportedOperationException to be thrown here.");
+ Assert.fail("Expecting UnsupportedOperationException to be thrown here.");
} catch (UnsupportedOperationException e) {
removeExceptionThrown = true;
}
- assertTrue(removeExceptionThrown);
- assertEquals(2, getSizeOfIterable(observerList));
+ Assert.assertTrue(removeExceptionThrown);
+ Assert.assertEquals(2, getSizeOfIterable(observerList));
boolean noElementExceptionThrown = false;
try {
it.next();
- fail("Expecting NoSuchElementException to be thrown here.");
+ Assert.fail("Expecting NoSuchElementException to be thrown here.");
} catch (NoSuchElementException e) {
noElementExceptionThrown = true;
}
- assertTrue(noElementExceptionThrown);
+ Assert.assertTrue(noElementExceptionThrown);
}
+ @Test
@SmallTest
@Feature({"Android-AppBase"})
public void testRewindableIterator() {
@@ -183,52 +192,54 @@ public class ObserverListTest extends InstrumentationTestCase {
observerList.addObserver(5);
observerList.addObserver(10);
observerList.addObserver(15);
- assertEquals(3, getSizeOfIterable(observerList));
+ Assert.assertEquals(3, getSizeOfIterable(observerList));
ObserverList.RewindableIterator<Integer> it = observerList.rewindableIterator();
- assertTrue(it.hasNext());
- assertTrue(5 == it.next());
- assertTrue(it.hasNext());
- assertTrue(10 == it.next());
- assertTrue(it.hasNext());
- assertTrue(15 == it.next());
- assertFalse(it.hasNext());
+ Assert.assertTrue(it.hasNext());
+ Assert.assertTrue(5 == it.next());
+ Assert.assertTrue(it.hasNext());
+ Assert.assertTrue(10 == it.next());
+ Assert.assertTrue(it.hasNext());
+ Assert.assertTrue(15 == it.next());
+ Assert.assertFalse(it.hasNext());
it.rewind();
- assertTrue(it.hasNext());
- assertTrue(5 == it.next());
- assertTrue(it.hasNext());
- assertTrue(10 == it.next());
- assertTrue(it.hasNext());
- assertTrue(15 == it.next());
- assertEquals(5, (int) observerList.mObservers.get(0));
+ Assert.assertTrue(it.hasNext());
+ Assert.assertTrue(5 == it.next());
+ Assert.assertTrue(it.hasNext());
+ Assert.assertTrue(10 == it.next());
+ Assert.assertTrue(it.hasNext());
+ Assert.assertTrue(15 == it.next());
+ Assert.assertEquals(5, (int) observerList.mObservers.get(0));
observerList.removeObserver(5);
- assertEquals(null, observerList.mObservers.get(0));
+ Assert.assertEquals(null, observerList.mObservers.get(0));
it.rewind();
- assertEquals(10, (int) observerList.mObservers.get(0));
- assertTrue(it.hasNext());
- assertTrue(10 == it.next());
- assertTrue(it.hasNext());
- assertTrue(15 == it.next());
+ Assert.assertEquals(10, (int) observerList.mObservers.get(0));
+ Assert.assertTrue(it.hasNext());
+ Assert.assertTrue(10 == it.next());
+ Assert.assertTrue(it.hasNext());
+ Assert.assertTrue(15 == it.next());
}
+ @Test
@SmallTest
@Feature({"Android-AppBase"})
public void testAddObserverReturnValue() {
ObserverList<Object> observerList = new ObserverList<Object>();
Object a = new Object();
- assertTrue(observerList.addObserver(a));
- assertFalse(observerList.addObserver(a));
+ Assert.assertTrue(observerList.addObserver(a));
+ Assert.assertFalse(observerList.addObserver(a));
Object b = new Object();
- assertTrue(observerList.addObserver(b));
- assertFalse(observerList.addObserver(null));
+ Assert.assertTrue(observerList.addObserver(b));
+ Assert.assertFalse(observerList.addObserver(null));
}
+ @Test
@SmallTest
@Feature({"Android-AppBase"})
public void testRemoveObserverReturnValue() {
@@ -239,91 +250,92 @@ public class ObserverListTest extends InstrumentationTestCase {
observerList.addObserver(a);
observerList.addObserver(b);
- assertTrue(observerList.removeObserver(a));
- assertFalse(observerList.removeObserver(a));
- assertFalse(observerList.removeObserver(new Object()));
- assertTrue(observerList.removeObserver(b));
- assertFalse(observerList.removeObserver(null));
+ Assert.assertTrue(observerList.removeObserver(a));
+ Assert.assertFalse(observerList.removeObserver(a));
+ Assert.assertFalse(observerList.removeObserver(new Object()));
+ Assert.assertTrue(observerList.removeObserver(b));
+ Assert.assertFalse(observerList.removeObserver(null));
// If we remove an object while iterating, it will be replaced by 'null'.
observerList.addObserver(a);
- assertTrue(observerList.removeObserver(a));
- assertFalse(observerList.removeObserver(null));
+ Assert.assertTrue(observerList.removeObserver(a));
+ Assert.assertFalse(observerList.removeObserver(null));
}
+ @Test
@SmallTest
@Feature({"Android-AppBase"})
public void testSize() {
ObserverList<Object> observerList = new ObserverList<Object>();
- assertEquals(0, observerList.size());
- assertTrue(observerList.isEmpty());
+ Assert.assertEquals(0, observerList.size());
+ Assert.assertTrue(observerList.isEmpty());
observerList.addObserver(null);
- assertEquals(0, observerList.size());
- assertTrue(observerList.isEmpty());
+ Assert.assertEquals(0, observerList.size());
+ Assert.assertTrue(observerList.isEmpty());
Object a = new Object();
observerList.addObserver(a);
- assertEquals(1, observerList.size());
- assertFalse(observerList.isEmpty());
+ Assert.assertEquals(1, observerList.size());
+ Assert.assertFalse(observerList.isEmpty());
observerList.addObserver(a);
- assertEquals(1, observerList.size());
- assertFalse(observerList.isEmpty());
+ Assert.assertEquals(1, observerList.size());
+ Assert.assertFalse(observerList.isEmpty());
observerList.addObserver(null);
- assertEquals(1, observerList.size());
- assertFalse(observerList.isEmpty());
+ Assert.assertEquals(1, observerList.size());
+ Assert.assertFalse(observerList.isEmpty());
Object b = new Object();
observerList.addObserver(b);
- assertEquals(2, observerList.size());
- assertFalse(observerList.isEmpty());
+ Assert.assertEquals(2, observerList.size());
+ Assert.assertFalse(observerList.isEmpty());
observerList.removeObserver(null);
- assertEquals(2, observerList.size());
- assertFalse(observerList.isEmpty());
+ Assert.assertEquals(2, observerList.size());
+ Assert.assertFalse(observerList.isEmpty());
observerList.removeObserver(new Object());
- assertEquals(2, observerList.size());
- assertFalse(observerList.isEmpty());
+ Assert.assertEquals(2, observerList.size());
+ Assert.assertFalse(observerList.isEmpty());
observerList.removeObserver(b);
- assertEquals(1, observerList.size());
- assertFalse(observerList.isEmpty());
+ Assert.assertEquals(1, observerList.size());
+ Assert.assertFalse(observerList.isEmpty());
observerList.removeObserver(b);
- assertEquals(1, observerList.size());
- assertFalse(observerList.isEmpty());
+ Assert.assertEquals(1, observerList.size());
+ Assert.assertFalse(observerList.isEmpty());
observerList.removeObserver(a);
- assertEquals(0, observerList.size());
- assertTrue(observerList.isEmpty());
+ Assert.assertEquals(0, observerList.size());
+ Assert.assertTrue(observerList.isEmpty());
observerList.removeObserver(a);
observerList.removeObserver(b);
observerList.removeObserver(null);
observerList.removeObserver(new Object());
- assertEquals(0, observerList.size());
- assertTrue(observerList.isEmpty());
+ Assert.assertEquals(0, observerList.size());
+ Assert.assertTrue(observerList.isEmpty());
observerList.addObserver(new Object());
observerList.addObserver(new Object());
observerList.addObserver(new Object());
observerList.addObserver(a);
- assertEquals(4, observerList.size());
- assertFalse(observerList.isEmpty());
+ Assert.assertEquals(4, observerList.size());
+ Assert.assertFalse(observerList.isEmpty());
observerList.clear();
- assertEquals(0, observerList.size());
- assertTrue(observerList.isEmpty());
+ Assert.assertEquals(0, observerList.size());
+ Assert.assertTrue(observerList.isEmpty());
observerList.removeObserver(a);
observerList.removeObserver(b);
observerList.removeObserver(null);
observerList.removeObserver(new Object());
- assertEquals(0, observerList.size());
- assertTrue(observerList.isEmpty());
+ Assert.assertEquals(0, observerList.size());
+ Assert.assertTrue(observerList.isEmpty());
}
}

Powered by Google App Engine
This is Rietveld 408576698