From bd96f408085701fe04fb46acdd3a101cfdebe064 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Thu, 22 Jun 2017 13:29:26 +0100 Subject: Clean up TestCaseUtil Part of the work of removing JUnit and dependent android.test classes from the Android API involves providing a static library that developers can include in their test applications to ease migration. That library will be built directly from the source (as opposed to android.jar which is built from stubs) and so developers will be able to see classes and methods that are not present in the stubs. This change is one of a number of similar changes that cleanup the existing non-API code in order to minimize the additional methods and classes exposed externally. The basic approach is to remove unused classes and methods, use least visible access modifier possible and generally minimize the amount of publicly visible code. TestCaseUtil.getTestCaseNames() is only used by tests but its tests did provide some coverage of the getTests() method so remove the method and the tests the method was simply moved into TestCaseUtilTest and the tests renamed to make it clearer that they are testing TestCaseUtil.getTests(). Similarly, TestCaseUtil.createTestSuite() was only used by tests but its tests did provide some coverage of the invokeSuiteMethodIfPossible() method so the tests were modified and renamed to preserve that coverage. TestCaseUtil.getTestAtIndex() was completely unused so was just removed. Bug: 30188076 Test: make checkbuild and ran FrameworkTestRunnerTests Change-Id: I62bbdbab428d7560f0c7df11f313fe60cfd31d13 --- test-runner/src/android/test/TestCaseUtil.java | 44 ++------------------------ 1 file changed, 2 insertions(+), 42 deletions(-) (limited to 'test-runner/src') diff --git a/test-runner/src/android/test/TestCaseUtil.java b/test-runner/src/android/test/TestCaseUtil.java index dc053a2359a0..156290997a1b 100644 --- a/test-runner/src/android/test/TestCaseUtil.java +++ b/test-runner/src/android/test/TestCaseUtil.java @@ -40,16 +40,6 @@ public class TestCaseUtil { private TestCaseUtil() { } - @SuppressWarnings("unchecked") - public static List getTestCaseNames(Test test, boolean flatten) { - List tests = (List) getTests(test, flatten); - List testCaseNames = new ArrayList<>(); - for (Test aTest : tests) { - testCaseNames.add(getTestName(aTest)); - } - return testCaseNames; - } - public static List getTests(Test test, boolean flatten) { return getTests(test, flatten, new HashSet>()); } @@ -92,7 +82,7 @@ public class TestCaseUtil { return testCases; } - private static Test invokeSuiteMethodIfPossible(Class testClass, + static Test invokeSuiteMethodIfPossible(Class testClass, Set> seen) { try { Method suiteMethod = testClass.getMethod( @@ -120,7 +110,7 @@ public class TestCaseUtil { return null; } - public static String getTestName(Test test) { + static String getTestName(Test test) { if (test instanceof TestCase) { TestCase testCase = (TestCase) test; return testCase.getName(); @@ -138,34 +128,4 @@ public class TestCaseUtil { } return ""; } - - public static Test getTestAtIndex(TestSuite testSuite, int position) { - int index = 0; - Enumeration enumeration = testSuite.tests(); - while (enumeration.hasMoreElements()) { - Test test = (Test) enumeration.nextElement(); - if (index == position) { - return test; - } - index++; - } - return null; - } - - public static TestSuite createTestSuite(Class testClass) - throws InstantiationException, IllegalAccessException { - - Test test = invokeSuiteMethodIfPossible(testClass, - new HashSet>()); - if (test == null) { - return new TestSuite(testClass); - - } else if (TestCase.class.isAssignableFrom(test.getClass())) { - TestSuite testSuite = new TestSuite(test.getClass().getName()); - testSuite.addTest(test); - return testSuite; - } - - return (TestSuite) test; - } } -- cgit v1.2.3-59-g8ed1b