diff options
author | Dmitri Plotnikov <dplotnikov@google.com> | 2011-01-07 12:06:47 -0800 |
---|---|---|
committer | Dmitri Plotnikov <dplotnikov@google.com> | 2011-01-07 12:06:47 -0800 |
commit | ac77f4629c1bbdf2e440d0fcc9fd665e5dd1ae6e (patch) | |
tree | 5cd5a0217063445064876c39bc6fcfba5a8f8d65 /test-runner/src | |
parent | cd3676e7b835653b04d4f66251a63749e7603f5b (diff) | |
download | frameworks_base-ac77f4629c1bbdf2e440d0fcc9fd665e5dd1ae6e.zip frameworks_base-ac77f4629c1bbdf2e440d0fcc9fd665e5dd1ae6e.tar.gz frameworks_base-ac77f4629c1bbdf2e440d0fcc9fd665e5dd1ae6e.tar.bz2 |
Prevent ActivityTestCase from erasing constants.
If you test case is declaring a non-primitive constant,
this method would clear out the constant between
individual tests.
Change-Id: I570f2bbbbbb0a170bf63b7473b4aaf84869e93e0
Diffstat (limited to 'test-runner/src')
-rw-r--r-- | test-runner/src/android/test/ActivityTestCase.java | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/test-runner/src/android/test/ActivityTestCase.java b/test-runner/src/android/test/ActivityTestCase.java index 18bfccc..c7b1d70 100644 --- a/test-runner/src/android/test/ActivityTestCase.java +++ b/test-runner/src/android/test/ActivityTestCase.java @@ -19,10 +19,11 @@ package android.test; import android.app.Activity; import java.lang.reflect.Field; +import java.lang.reflect.Modifier; /** * This is common code used to support Activity test cases. For more useful classes, please see - * {@link android.test.ActivityUnitTestCase} and + * {@link android.test.ActivityUnitTestCase} and * {@link android.test.ActivityInstrumentationTestCase}. */ public abstract class ActivityTestCase extends InstrumentationTestCase { @@ -38,7 +39,7 @@ public abstract class ActivityTestCase extends InstrumentationTestCase { protected Activity getActivity() { return mActivity; } - + /** * Set the activity under test. * @param testActivity The activity under test @@ -46,15 +47,15 @@ public abstract class ActivityTestCase extends InstrumentationTestCase { protected void setActivity(Activity testActivity) { mActivity = testActivity; } - + /** * This function is called by various TestCase implementations, at tearDown() time, in order * to scrub out any class variables. This protects against memory leaks in the case where a * test case creates a non-static inner class (thus referencing the test case) and gives it to * someone else to hold onto. - * + * * @param testCaseClass The class of the derived TestCase implementation. - * + * * @throws IllegalAccessException */ protected void scrubClass(final Class<?> testCaseClass) @@ -62,7 +63,8 @@ public abstract class ActivityTestCase extends InstrumentationTestCase { final Field[] fields = getClass().getDeclaredFields(); for (Field field : fields) { final Class<?> fieldClass = field.getDeclaringClass(); - if (testCaseClass.isAssignableFrom(fieldClass) && !field.getType().isPrimitive()) { + if (testCaseClass.isAssignableFrom(fieldClass) && !field.getType().isPrimitive() + && (field.getModifiers() & Modifier.FINAL) == 0) { try { field.setAccessible(true); field.set(this, null); @@ -77,6 +79,6 @@ public abstract class ActivityTestCase extends InstrumentationTestCase { } } - + } |