diff options
author | David Srbecky <dsrbecky@google.com> | 2021-02-24 21:50:58 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-02-24 21:50:58 +0000 |
commit | 5cb7d97d73027edb2274ac39e8a958bab5e2e7b3 (patch) | |
tree | fb060599e56a1ce3ccfa4cacd193406f14ba84db /src/main/java/junit/framework/TestSuite.java | |
parent | f7adff9d456ec1fd10bfe84951d4756d78dbba6f (diff) | |
parent | 138b64feb682b90292d36002f3aff9869d6a9e4b (diff) | |
download | junit-5cb7d97d73027edb2274ac39e8a958bab5e2e7b3.tar.gz |
Merge changes from topic "revert-1601635-AIQYZOHWTP" am: 565f36d281 am: 23e304a839 am: 91c5e5ff9d am: 138b64feb6
Original change: https://android-review.googlesource.com/c/platform/external/junit/+/1605377
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: Ic05d8452bb92220507ec751aa85c8e657f77cc79
Diffstat (limited to 'src/main/java/junit/framework/TestSuite.java')
-rw-r--r-- | src/main/java/junit/framework/TestSuite.java | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/main/java/junit/framework/TestSuite.java b/src/main/java/junit/framework/TestSuite.java index 50cd5f8..366f1cf 100644 --- a/src/main/java/junit/framework/TestSuite.java +++ b/src/main/java/junit/framework/TestSuite.java @@ -1,5 +1,7 @@ package junit.framework; +import java.io.PrintWriter; +import java.io.StringWriter; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -10,7 +12,6 @@ import java.util.List; import java.util.Vector; import org.junit.internal.MethodSorter; -import org.junit.internal.Throwables; /** * A <code>TestSuite</code> is a <code>Composite</code> of Tests. @@ -34,7 +35,7 @@ import org.junit.internal.Throwables; * <p> * A final option is to do the same for a large array of test classes. * <pre> - * Class[] testClasses = { MathTest.class, AnotherTest.class }; + * Class[] testClasses = { MathTest.class, AnotherTest.class } * TestSuite suite= new TestSuite(testClasses); * </pre> * @@ -64,11 +65,11 @@ public class TestSuite implements Test { test = constructor.newInstance(new Object[]{name}); } } catch (InstantiationException e) { - return (warning("Cannot instantiate test case: " + name + " (" + Throwables.getStacktrace(e) + ")")); + return (warning("Cannot instantiate test case: " + name + " (" + exceptionToString(e) + ")")); } catch (InvocationTargetException e) { - return (warning("Exception in constructor: " + name + " (" + Throwables.getStacktrace(e.getTargetException()) + ")")); + return (warning("Exception in constructor: " + name + " (" + exceptionToString(e.getTargetException()) + ")")); } catch (IllegalAccessException e) { - return (warning("Cannot access test case: " + name + " (" + Throwables.getStacktrace(e) + ")")); + return (warning("Cannot access test case: " + name + " (" + exceptionToString(e) + ")")); } return (Test) test; } @@ -98,6 +99,16 @@ public class TestSuite implements Test { }; } + /** + * Converts the stack trace into a string + */ + private static String exceptionToString(Throwable e) { + StringWriter stringWriter = new StringWriter(); + PrintWriter writer = new PrintWriter(stringWriter); + e.printStackTrace(writer); + return stringWriter.toString(); + } + private String fName; private Vector<Test> fTests = new Vector<Test>(10); // Cannot convert this to List because it is used directly by some test runners @@ -199,7 +210,7 @@ public class TestSuite implements Test { } /** - * Adds the tests from the given class to the suite. + * Adds the tests from the given class to the suite */ public void addTestSuite(Class<? extends TestCase> testClass) { addTest(new TestSuite(testClass)); @@ -251,21 +262,21 @@ public class TestSuite implements Test { } /** - * Returns the test at the given index. + * Returns the test at the given index */ public Test testAt(int index) { return fTests.get(index); } /** - * Returns the number of tests in this suite. + * Returns the number of tests in this suite */ public int testCount() { return fTests.size(); } /** - * Returns the tests as an enumeration. + * Returns the tests as an enumeration */ public Enumeration<Test> tests() { return fTests.elements(); |