diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2015-01-10 08:41:22 +0100 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2015-01-10 08:41:22 +0100 |
commit | 1c43f74aace3096d32d474aacfb590a8f14fedf9 (patch) | |
tree | 7e0ee27d44f0ed496baa2e0295e6e4a6699015aa /tests | |
parent | b36fd0cef27042ee662f228a7efcd982473a6679 (diff) | |
download | cgeo-1c43f74aace3096d32d474aacfb590a8f14fedf9.zip cgeo-1c43f74aace3096d32d474aacfb590a8f14fedf9.tar.gz cgeo-1c43f74aace3096d32d474aacfb590a8f14fedf9.tar.bz2 |
fix some lint warnings and Findbugs in test project
Diffstat (limited to 'tests')
-rw-r--r-- | tests/res/layout/cgeo_tests_activity.xml | 3 | ||||
-rw-r--r-- | tests/src/cgeo/junit/CgeoTestRunner.java | 39 |
2 files changed, 29 insertions, 13 deletions
diff --git a/tests/res/layout/cgeo_tests_activity.xml b/tests/res/layout/cgeo_tests_activity.xml index 43225ac..d035210 100644 --- a/tests/res/layout/cgeo_tests_activity.xml +++ b/tests/res/layout/cgeo_tests_activity.xml @@ -13,6 +13,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" + android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_gravity="center_vertical" android:gravity="center_vertical" @@ -27,6 +28,7 @@ android:layout_height="fill_parent" android:layout_above="@+id/buttonRun" android:layout_alignParentLeft="true" + android:layout_alignParentStart="true" android:layout_below="@+id/headline" > <TextView @@ -43,6 +45,7 @@ android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="false" + android:layout_alignParentStart="false" android:onClick="runTests" android:text="@string/run_tests" /> diff --git a/tests/src/cgeo/junit/CgeoTestRunner.java b/tests/src/cgeo/junit/CgeoTestRunner.java index 16a5f12..94803cf 100644 --- a/tests/src/cgeo/junit/CgeoTestRunner.java +++ b/tests/src/cgeo/junit/CgeoTestRunner.java @@ -11,10 +11,12 @@ import android.util.Log; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; /** * Test runner which derives from the newer Google instrumentation test runner used by the Espresso test framework. It - * adds junit report functionality by cloning the behaviour of the {@link JUnitReportTestRunner}. + * adds junit report functionality by cloning the behavior of the {@link JUnitReportTestRunner}. * */ public class CgeoTestRunner extends GoogleInstrumentationTestRunner { @@ -86,21 +88,32 @@ public class CgeoTestRunner extends GoogleInstrumentationTestRunner { @Override public void start() { - mListener = new JUnitReportListener(getContext(), getTargetContext(), mReportFile, mReportDir, mFilterTraces, mMultiFile); - try { - Class<?> c = getClass(); - Field bridgeTestRunner = c.getSuperclass().getDeclaredField("bridgeTestRunner"); - bridgeTestRunner.setAccessible(true); - Object obj = bridgeTestRunner.get(this); - Method m = obj.getClass().getDeclaredMethod("getAndroidTestRunner", (Class[]) null); - AndroidTestRunner androidTestRunner = (AndroidTestRunner) m.invoke(obj); - androidTestRunner.addTestListener(mListener); - } catch (NoSuchFieldException | InvocationTargetException | IllegalAccessException | NoSuchMethodException | SecurityException x) { - Log.e(LOG_TAG, x.toString()); - } + makeAndroidTestRunnerAccessible(); super.start(); } + private void makeAndroidTestRunnerAccessible() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + mListener = new JUnitReportListener(getContext(), getTargetContext(), mReportFile, mReportDir, mFilterTraces, mMultiFile); + try { + Class<?> c = getClass(); + Field bridgeTestRunner = c.getSuperclass().getDeclaredField("bridgeTestRunner"); + bridgeTestRunner.setAccessible(true); + Object obj = bridgeTestRunner.get(this); + Method m = obj.getClass().getDeclaredMethod("getAndroidTestRunner", (Class[]) null); + AndroidTestRunner androidTestRunner = (AndroidTestRunner) m.invoke(obj); + androidTestRunner.addTestListener(mListener); + } catch (NoSuchFieldException | InvocationTargetException | IllegalAccessException + | NoSuchMethodException | SecurityException x) { + Log.e(LOG_TAG, x.toString()); + } + return null; + } + }); + } + @Override public void finish(int resultCode, Bundle results) { if (mListener != null) { |