Roll android_tools support library to 25.1.0
[android_tools.git] / sdk / sources / android-23 / android / test / suitebuilder / ListTestCaseNames.java
blob37ec3281410f236445eb412ca421a1fc34bef2d6
1 /*
2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.test.suitebuilder;
19 import junit.framework.Test;
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
27 public class ListTestCaseNames {
28 public static List<String> getTestCaseNames(TestSuite suite) {
29 // TODO: deprecate this method and move all callers to use getTestNames
30 List<Test> tests = Collections.<Test>list(suite.tests());
31 ArrayList<String> testCaseNames = new ArrayList<String>();
32 for (Test test : tests) {
33 if (test instanceof TestCase) {
34 testCaseNames.add(((TestCase) test).getName());
35 } else if (test instanceof TestSuite) {
36 testCaseNames.addAll(getTestCaseNames((TestSuite) test));
39 return testCaseNames;
42 /**
43 * Returns a list of test class and method names for each TestCase in suite.
45 public static List<TestDescriptor> getTestNames(TestSuite suite) {
46 List<Test> tests = Collections.<Test>list(suite.tests());
47 ArrayList<TestDescriptor> testNames = new ArrayList<TestDescriptor>();
48 for (Test test : tests) {
49 if (test instanceof TestCase) {
50 String className = test.getClass().getName();
51 String testName = ((TestCase) test).getName();
52 testNames.add(new TestDescriptor(className, testName));
53 } else if (test instanceof TestSuite) {
54 testNames.addAll(getTestNames((TestSuite) test));
57 return testNames;
60 /**
61 * Data holder for test case info
63 public static class TestDescriptor {
64 private String mClassName;
65 private String mTestName;
67 public TestDescriptor(String className, String testName) {
68 mClassName = className;
69 mTestName = testName;
72 public String getClassName() {
73 return mClassName;
76 public String getTestName() {
77 return mTestName;
80 /**
81 * Override parent to do string-based class and test name comparison
83 @Override
84 public boolean equals(Object otherObj) {
85 if (otherObj instanceof TestDescriptor) {
86 TestDescriptor otherDesc = (TestDescriptor)otherObj;
87 return otherDesc.getClassName().equals(this.getClassName()) &&
88 otherDesc.getTestName().equals(this.getTestName());
91 return false;
94 /**
95 * Override parent to return a more user-friendly display string
97 @Override
98 public String toString() {
99 return getClassName() + "#" + getTestName();