summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java27
1 files changed, 14 insertions, 13 deletions
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java b/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java
index 88d853e244e0..8f06e636b479 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java
@@ -181,29 +181,30 @@ public class PluginInstanceTest extends SysuiTestCase {
String ACTION = "testAction";
}
- public void assertInstances(Integer allocated, Integer created) {
- // Run the garbage collector to finalize and deallocate outstanding
- // instances. Since the GC doesn't always appear to want to run
- // completely when we ask, we ask it 10 times in a short loop.
- for (int i = 0; i < 10; i++) {
+ private void assertInstances(int allocated, int created) {
+ // If there are more than the expected number of allocated instances, then we run the
+ // garbage collector to finalize and deallocate any outstanding non-referenced instances.
+ // Since the GC doesn't always appear to want to run completely when we ask, we do this up
+ // to 10 times before failing the test.
+ for (int i = 0; mCounter.getAllocatedInstances() > allocated && i < 10; i++) {
System.runFinalization();
System.gc();
}
- mCounter.assertInstances(allocated, created);
+ assertEquals(allocated, mCounter.getAllocatedInstances());
+ assertEquals(created, mCounter.getCreatedInstances());
}
public static class RefCounter {
public final AtomicInteger mAllocatedInstances = new AtomicInteger();
public final AtomicInteger mCreatedInstances = new AtomicInteger();
- public void assertInstances(Integer allocated, Integer created) {
- if (allocated != null) {
- assertEquals(allocated.intValue(), mAllocatedInstances.get());
- }
- if (created != null) {
- assertEquals(created.intValue(), mCreatedInstances.get());
- }
+ public int getAllocatedInstances() {
+ return mAllocatedInstances.get();
+ }
+
+ public int getCreatedInstances() {
+ return mCreatedInstances.get();
}
}