...9import junit.framework.TestCase;10import junit.framework.TestListener;11import junit.framework.TestResult;12import junit.framework.TestSuite;13import junit.runner.BaseTestRunner;14@Deprecated15public class AndroidTestRunner extends BaseTestRunner {16 private Context mContext;17 private Instrumentation mInstrumentation;18 private boolean mSkipExecution = false;19 private List<TestCase> mTestCases;20 private String mTestClassName;21 private List<TestListener> mTestListeners = new ArrayList();22 private TestResult mTestResult;23 public void setTestClassName(String testClassName, String testMethodName) {24 Class testClass = loadTestClass(testClassName);25 if (shouldRunSingleTestMethod(testMethodName, testClass)) {26 TestCase testCase = buildSingleTestMethod(testClass, testMethodName);27 this.mTestCases = new ArrayList();28 this.mTestCases.add(testCase);29 this.mTestClassName = testClass.getSimpleName();30 return;31 }32 setTest(getTest(testClass), testClass);33 }34 public void setTest(Test test) {35 setTest(test, test.getClass());36 }37 private void setTest(Test test, Class<? extends Test> testClass) {38 this.mTestCases = TestCaseUtil.getTests(test, true);39 if (TestSuite.class.isAssignableFrom(testClass)) {40 this.mTestClassName = TestCaseUtil.getTestName(test);41 } else {42 this.mTestClassName = testClass.getSimpleName();43 }44 }45 public void clearTestListeners() {46 this.mTestListeners.clear();47 }48 public void addTestListener(TestListener testListener) {49 if (testListener != null) {50 this.mTestListeners.add(testListener);51 }52 }53 /* JADX DEBUG: Type inference failed for r0v4. Raw type applied. Possible types: java.lang.Class<?>, java.lang.Class<? extends junit.framework.Test> */54 private Class<? extends Test> loadTestClass(String testClassName) {55 try {56 return this.mContext.getClassLoader().loadClass(testClassName);57 } catch (ClassNotFoundException e) {58 runFailed("Could not find test class. Class: " + testClassName);59 return null;60 }61 }62 private TestCase buildSingleTestMethod(Class testClass, String testMethodName) {63 try {64 return newSingleTestMethod(testClass, testMethodName, testClass.getConstructor(new Class[0]), new Object[0]);65 } catch (NoSuchMethodException e) {66 try {67 return newSingleTestMethod(testClass, testMethodName, testClass.getConstructor(String.class), testMethodName);68 } catch (NoSuchMethodException e2) {69 return null;70 }71 }72 }73 private TestCase newSingleTestMethod(Class testClass, String testMethodName, Constructor constructor, Object... args) {74 try {75 TestCase testCase = (TestCase) constructor.newInstance(args);76 testCase.setName(testMethodName);77 return testCase;78 } catch (IllegalAccessException e) {79 runFailed("Could not access test class. Class: " + testClass.getName());80 return null;81 } catch (InstantiationException e2) {82 runFailed("Could not instantiate test class. Class: " + testClass.getName());83 return null;84 } catch (IllegalArgumentException e3) {85 runFailed("Illegal argument passed to constructor. Class: " + testClass.getName());86 return null;87 } catch (InvocationTargetException e4) {88 runFailed("Constructor thew an exception. Class: " + testClass.getName());89 return null;90 }91 }92 private boolean shouldRunSingleTestMethod(String testMethodName, Class<? extends Test> testClass) {93 return testMethodName != null && TestCase.class.isAssignableFrom(testClass);94 }95 private Test getTest(Class clazz) {96 if (TestSuiteProvider.class.isAssignableFrom(clazz)) {97 try {98 return ((TestSuiteProvider) clazz.getConstructor(new Class[0]).newInstance(new Object[0])).getTestSuite();99 } catch (InstantiationException e) {100 runFailed("Could not instantiate test suite provider. Class: " + clazz.getName());101 } catch (IllegalAccessException e2) {102 runFailed("Illegal access of test suite provider. Class: " + clazz.getName());103 } catch (InvocationTargetException e3) {104 runFailed("Invocation exception test suite provider. Class: " + clazz.getName());105 } catch (NoSuchMethodException e4) {106 runFailed("No such method on test suite provider. Class: " + clazz.getName());107 }108 }109 return getTest(clazz.getName());110 }111 /* access modifiers changed from: protected */112 public TestResult createTestResult() {113 if (this.mSkipExecution) {114 return new NoExecTestResult();115 }116 return new TestResult();117 }118 /* access modifiers changed from: package-private */119 public void setSkipExecution(boolean skip) {120 this.mSkipExecution = skip;121 }122 public List<TestCase> getTestCases() {123 return this.mTestCases;124 }125 public String getTestClassName() {126 return this.mTestClassName;127 }128 public TestResult getTestResult() {129 return this.mTestResult;130 }131 public void runTest() {132 runTest(createTestResult());133 }134 public void runTest(TestResult testResult) {135 this.mTestResult = testResult;136 for (TestListener testListener : this.mTestListeners) {137 this.mTestResult.addListener(testListener);138 }139 Instrumentation instrumentation = this.mInstrumentation;140 Context testContext = instrumentation == null ? this.mContext : instrumentation.getContext();141 for (TestCase testCase : this.mTestCases) {142 setContextIfAndroidTestCase(testCase, this.mContext, testContext);143 setInstrumentationIfInstrumentationTestCase(testCase, this.mInstrumentation);144 testCase.run(this.mTestResult);145 }146 }147 private void setContextIfAndroidTestCase(Test test, Context context, Context testContext) {148 if (AndroidTestCase.class.isAssignableFrom(test.getClass())) {149 ((AndroidTestCase) test).setContext(context);150 ((AndroidTestCase) test).setTestContext(testContext);151 }152 }153 public void setContext(Context context) {154 this.mContext = context;155 }156 private void setInstrumentationIfInstrumentationTestCase(Test test, Instrumentation instrumentation) {157 if (InstrumentationTestCase.class.isAssignableFrom(test.getClass())) {158 ((InstrumentationTestCase) test).injectInstrumentation(instrumentation);159 }160 }161 public void setInstrumentation(Instrumentation instrumentation) {162 this.mInstrumentation = instrumentation;163 }164 @Deprecated165 public void setInstrumentaiton(Instrumentation instrumentation) {166 setInstrumentation(instrumentation);167 }168 /* access modifiers changed from: protected */169 @Override // junit.runner.BaseTestRunner170 public Class loadSuiteClass(String suiteClassName) throws ClassNotFoundException {171 return this.mContext.getClassLoader().loadClass(suiteClassName);172 }173 @Override // junit.runner.BaseTestRunner174 public void testStarted(String testName) {175 }176 @Override // junit.runner.BaseTestRunner177 public void testEnded(String testName) {178 }179 @Override // junit.runner.BaseTestRunner180 public void testFailed(int status, Test test, Throwable t) {181 }182 /* access modifiers changed from: protected */183 @Override // junit.runner.BaseTestRunner184 public void runFailed(String message) {185 throw new RuntimeException(message);186 }187}...