diff options
author | Pete Bentley <prb@google.com> | 2021-02-21 18:26:28 +0000 |
---|---|---|
committer | Pete Bentley <prb@google.com> | 2021-02-22 18:38:53 +0000 |
commit | aa1524950fb5fbffbb61d23c5442984cb731a1eb (patch) | |
tree | 7ce2c9779133dd053d314fdb25818acbbb4fa2be /src/main/java/junit | |
parent | e938015d2d5a2157ed20eb622fcd9750a12bb4af (diff) | |
download | junit-aa1524950fb5fbffbb61d23c5442984cb731a1eb.tar.gz |
Upgrade external/junit to 4.13.2
Contains just the changes from 4.12 to 4.13.2 and undoes local
Android changes. Will re-patch those in in subsequent CLs.
Bug: 129054170
Test: m
Change-Id: I5ec909df6840f6c54cbab9c509c5addaee3f94e6
Diffstat (limited to 'src/main/java/junit')
-rw-r--r-- | src/main/java/junit/extensions/ActiveTestSuite.java | 2 | ||||
-rw-r--r-- | src/main/java/junit/extensions/TestDecorator.java | 1 | ||||
-rw-r--r-- | src/main/java/junit/framework/Assert.java | 78 | ||||
-rw-r--r-- | src/main/java/junit/framework/ComparisonCompactor.java | 1 | ||||
-rw-r--r-- | src/main/java/junit/framework/JUnit4TestAdapter.java | 25 | ||||
-rw-r--r-- | src/main/java/junit/framework/Protectable.java | 4 | ||||
-rw-r--r-- | src/main/java/junit/framework/TestCase.java | 47 | ||||
-rw-r--r-- | src/main/java/junit/framework/TestFailure.java | 8 | ||||
-rw-r--r-- | src/main/java/junit/framework/TestResult.java | 10 | ||||
-rw-r--r-- | src/main/java/junit/framework/TestSuite.java | 29 | ||||
-rw-r--r-- | src/main/java/junit/runner/BaseTestRunner.java | 9 | ||||
-rw-r--r-- | src/main/java/junit/runner/TestRunListener.java | 16 | ||||
-rw-r--r-- | src/main/java/junit/runner/Version.java | 2 | ||||
-rw-r--r-- | src/main/java/junit/textui/TestRunner.java | 4 |
14 files changed, 103 insertions, 133 deletions
diff --git a/src/main/java/junit/extensions/ActiveTestSuite.java b/src/main/java/junit/extensions/ActiveTestSuite.java index 95c5e2e..6f0f99d 100644 --- a/src/main/java/junit/extensions/ActiveTestSuite.java +++ b/src/main/java/junit/extensions/ActiveTestSuite.java @@ -63,7 +63,7 @@ public class ActiveTestSuite extends TestSuite { } } - synchronized public void runFinished() { + public synchronized void runFinished() { fActiveTestDeathCount++; notifyAll(); } diff --git a/src/main/java/junit/extensions/TestDecorator.java b/src/main/java/junit/extensions/TestDecorator.java index 2b74f30..a3c5e08 100644 --- a/src/main/java/junit/extensions/TestDecorator.java +++ b/src/main/java/junit/extensions/TestDecorator.java @@ -9,6 +9,7 @@ import junit.framework.TestResult; * test decorators. Test decorator subclasses can be introduced to add behaviour * before or after a test is run. */ +@SuppressWarnings("deprecation") public class TestDecorator extends Assert implements Test { protected Test fTest; diff --git a/src/main/java/junit/framework/Assert.java b/src/main/java/junit/framework/Assert.java index 663461c..43482a1 100644 --- a/src/main/java/junit/framework/Assert.java +++ b/src/main/java/junit/framework/Assert.java @@ -17,7 +17,7 @@ public class Assert { * Asserts that a condition is true. If it isn't it throws * an AssertionFailedError with the given message. */ - static public void assertTrue(String message, boolean condition) { + public static void assertTrue(String message, boolean condition) { if (!condition) { fail(message); } @@ -27,7 +27,7 @@ public class Assert { * Asserts that a condition is true. If it isn't it throws * an AssertionFailedError. */ - static public void assertTrue(boolean condition) { + public static void assertTrue(boolean condition) { assertTrue(null, condition); } @@ -35,7 +35,7 @@ public class Assert { * Asserts that a condition is false. If it isn't it throws * an AssertionFailedError with the given message. */ - static public void assertFalse(String message, boolean condition) { + public static void assertFalse(String message, boolean condition) { assertTrue(message, !condition); } @@ -43,14 +43,14 @@ public class Assert { * Asserts that a condition is false. If it isn't it throws * an AssertionFailedError. */ - static public void assertFalse(boolean condition) { + public static void assertFalse(boolean condition) { assertFalse(null, condition); } /** * Fails a test with the given message. */ - static public void fail(String message) { + public static void fail(String message) { if (message == null) { throw new AssertionFailedError(); } @@ -60,7 +60,7 @@ public class Assert { /** * Fails a test with no message. */ - static public void fail() { + public static void fail() { fail(null); } @@ -68,7 +68,7 @@ public class Assert { * Asserts that two objects are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - static public void assertEquals(String message, Object expected, Object actual) { + public static void assertEquals(String message, Object expected, Object actual) { if (expected == null && actual == null) { return; } @@ -82,14 +82,14 @@ public class Assert { * Asserts that two objects are equal. If they are not * an AssertionFailedError is thrown. */ - static public void assertEquals(Object expected, Object actual) { + public static void assertEquals(Object expected, Object actual) { assertEquals(null, expected, actual); } /** * Asserts that two Strings are equal. */ - static public void assertEquals(String message, String expected, String actual) { + public static void assertEquals(String message, String expected, String actual) { if (expected == null && actual == null) { return; } @@ -103,7 +103,7 @@ public class Assert { /** * Asserts that two Strings are equal. */ - static public void assertEquals(String expected, String actual) { + public static void assertEquals(String expected, String actual) { assertEquals(null, expected, actual); } @@ -112,12 +112,12 @@ public class Assert { * an AssertionFailedError is thrown with the given message. If the expected * value is infinity then the delta value is ignored. */ - static public void assertEquals(String message, double expected, double actual, double delta) { + public static void assertEquals(String message, double expected, double actual, double delta) { if (Double.compare(expected, actual) == 0) { return; } if (!(Math.abs(expected - actual) <= delta)) { - failNotEquals(message, new Double(expected), new Double(actual)); + failNotEquals(message, Double.valueOf(expected), Double.valueOf(actual)); } } @@ -125,7 +125,7 @@ public class Assert { * Asserts that two doubles are equal concerning a delta. If the expected * value is infinity then the delta value is ignored. */ - static public void assertEquals(double expected, double actual, double delta) { + public static void assertEquals(double expected, double actual, double delta) { assertEquals(null, expected, actual, delta); } @@ -134,12 +134,12 @@ public class Assert { * are not an AssertionFailedError is thrown with the given message. If the * expected value is infinity then the delta value is ignored. */ - static public void assertEquals(String message, float expected, float actual, float delta) { + public static void assertEquals(String message, float expected, float actual, float delta) { if (Float.compare(expected, actual) == 0) { return; } if (!(Math.abs(expected - actual) <= delta)) { - failNotEquals(message, new Float(expected), new Float(actual)); + failNotEquals(message, Float.valueOf(expected), Float.valueOf(actual)); } } @@ -147,7 +147,7 @@ public class Assert { * Asserts that two floats are equal concerning a delta. If the expected * value is infinity then the delta value is ignored. */ - static public void assertEquals(float expected, float actual, float delta) { + public static void assertEquals(float expected, float actual, float delta) { assertEquals(null, expected, actual, delta); } @@ -155,14 +155,14 @@ public class Assert { * Asserts that two longs are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - static public void assertEquals(String message, long expected, long actual) { + public static void assertEquals(String message, long expected, long actual) { assertEquals(message, Long.valueOf(expected), Long.valueOf(actual)); } /** * Asserts that two longs are equal. */ - static public void assertEquals(long expected, long actual) { + public static void assertEquals(long expected, long actual) { assertEquals(null, expected, actual); } @@ -170,14 +170,14 @@ public class Assert { * Asserts that two booleans are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - static public void assertEquals(String message, boolean expected, boolean actual) { + public static void assertEquals(String message, boolean expected, boolean actual) { assertEquals(message, Boolean.valueOf(expected), Boolean.valueOf(actual)); } /** * Asserts that two booleans are equal. */ - static public void assertEquals(boolean expected, boolean actual) { + public static void assertEquals(boolean expected, boolean actual) { assertEquals(null, expected, actual); } @@ -185,14 +185,14 @@ public class Assert { * Asserts that two bytes are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - static public void assertEquals(String message, byte expected, byte actual) { + public static void assertEquals(String message, byte expected, byte actual) { assertEquals(message, Byte.valueOf(expected), Byte.valueOf(actual)); } /** * Asserts that two bytes are equal. */ - static public void assertEquals(byte expected, byte actual) { + public static void assertEquals(byte expected, byte actual) { assertEquals(null, expected, actual); } @@ -200,14 +200,14 @@ public class Assert { * Asserts that two chars are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - static public void assertEquals(String message, char expected, char actual) { + public static void assertEquals(String message, char expected, char actual) { assertEquals(message, Character.valueOf(expected), Character.valueOf(actual)); } /** * Asserts that two chars are equal. */ - static public void assertEquals(char expected, char actual) { + public static void assertEquals(char expected, char actual) { assertEquals(null, expected, actual); } @@ -215,14 +215,14 @@ public class Assert { * Asserts that two shorts are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - static public void assertEquals(String message, short expected, short actual) { + public static void assertEquals(String message, short expected, short actual) { assertEquals(message, Short.valueOf(expected), Short.valueOf(actual)); } /** * Asserts that two shorts are equal. */ - static public void assertEquals(short expected, short actual) { + public static void assertEquals(short expected, short actual) { assertEquals(null, expected, actual); } @@ -230,21 +230,21 @@ public class Assert { * Asserts that two ints are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - static public void assertEquals(String message, int expected, int actual) { + public static void assertEquals(String message, int expected, int actual) { assertEquals(message, Integer.valueOf(expected), Integer.valueOf(actual)); } /** * Asserts that two ints are equal. */ - static public void assertEquals(int expected, int actual) { + public static void assertEquals(int expected, int actual) { assertEquals(null, expected, actual); } /** * Asserts that an object isn't null. */ - static public void assertNotNull(Object object) { + public static void assertNotNull(Object object) { assertNotNull(null, object); } @@ -252,7 +252,7 @@ public class Assert { * Asserts that an object isn't null. If it is * an AssertionFailedError is thrown with the given message. */ - static public void assertNotNull(String message, Object object) { + public static void assertNotNull(String message, Object object) { assertTrue(message, object != null); } @@ -263,7 +263,7 @@ public class Assert { * * @param object Object to check or <code>null</code> */ - static public void assertNull(Object object) { + public static void assertNull(Object object) { if (object != null) { assertNull("Expected: <null> but was: " + object.toString(), object); } @@ -273,7 +273,7 @@ public class Assert { * Asserts that an object is null. If it is not * an AssertionFailedError is thrown with the given message. */ - static public void assertNull(String message, Object object) { + public static void assertNull(String message, Object object) { assertTrue(message, object == null); } @@ -281,7 +281,7 @@ public class Assert { * Asserts that two objects refer to the same object. If they are not * an AssertionFailedError is thrown with the given message. */ - static public void assertSame(String message, Object expected, Object actual) { + public static void assertSame(String message, Object expected, Object actual) { if (expected == actual) { return; } @@ -292,7 +292,7 @@ public class Assert { * Asserts that two objects refer to the same object. If they are not * the same an AssertionFailedError is thrown. */ - static public void assertSame(Object expected, Object actual) { + public static void assertSame(Object expected, Object actual) { assertSame(null, expected, actual); } @@ -301,7 +301,7 @@ public class Assert { * refer to the same object an AssertionFailedError is thrown with the * given message. */ - static public void assertNotSame(String message, Object expected, Object actual) { + public static void assertNotSame(String message, Object expected, Object actual) { if (expected == actual) { failSame(message); } @@ -311,21 +311,21 @@ public class Assert { * Asserts that two objects do not refer to the same object. If they do * refer to the same object an AssertionFailedError is thrown. */ - static public void assertNotSame(Object expected, Object actual) { + public static void assertNotSame(Object expected, Object actual) { assertNotSame(null, expected, actual); } - static public void failSame(String message) { + public static void failSame(String message) { String formatted = (message != null) ? message + " " : ""; fail(formatted + "expected not same"); } - static public void failNotSame(String message, Object expected, Object actual) { + public static void failNotSame(String message, Object expected, Object actual) { String formatted = (message != null) ? message + " " : ""; fail(formatted + "expected same:<" + expected + "> was not:<" + actual + ">"); } - static public void failNotEquals(String message, Object expected, Object actual) { + public static void failNotEquals(String message, Object expected, Object actual) { fail(format(message, expected, actual)); } diff --git a/src/main/java/junit/framework/ComparisonCompactor.java b/src/main/java/junit/framework/ComparisonCompactor.java index fa20a8e..81ddd5b 100644 --- a/src/main/java/junit/framework/ComparisonCompactor.java +++ b/src/main/java/junit/framework/ComparisonCompactor.java @@ -18,6 +18,7 @@ public class ComparisonCompactor { fActual = actual; } + @SuppressWarnings("deprecation") public String compact(String message) { if (fExpected == null || fActual == null || areStringsEqual()) { return Assert.format(message, fExpected, fActual); diff --git a/src/main/java/junit/framework/JUnit4TestAdapter.java b/src/main/java/junit/framework/JUnit4TestAdapter.java index cbb66db..9d32031 100644 --- a/src/main/java/junit/framework/JUnit4TestAdapter.java +++ b/src/main/java/junit/framework/JUnit4TestAdapter.java @@ -9,11 +9,23 @@ import org.junit.runner.Request; import org.junit.runner.Runner; import org.junit.runner.manipulation.Filter; import org.junit.runner.manipulation.Filterable; +import org.junit.runner.manipulation.Orderer; +import org.junit.runner.manipulation.InvalidOrderingException; import org.junit.runner.manipulation.NoTestsRemainException; -import org.junit.runner.manipulation.Sortable; +import org.junit.runner.manipulation.Orderable; import org.junit.runner.manipulation.Sorter; -public class JUnit4TestAdapter implements Test, Filterable, Sortable, Describable { +/** + * The JUnit4TestAdapter enables running JUnit-4-style tests using a JUnit-3-style test runner. + * + * <p> To use it, add the following to a test class: + * <pre> + public static Test suite() { + return new JUnit4TestAdapter(<em>YourJUnit4TestClass</em>.class); + } +</pre> + */ +public class JUnit4TestAdapter implements Test, Filterable, Orderable, Describable { private final Class<?> fNewTestClass; private final Runner fRunner; @@ -83,4 +95,13 @@ public class JUnit4TestAdapter implements Test, Filterable, Sortable, Describabl public void sort(Sorter sorter) { sorter.apply(fRunner); } + + /** + * {@inheritDoc} + * + * @since 4.13 + */ + public void order(Orderer orderer) throws InvalidOrderingException { + orderer.apply(fRunner); + } }
\ No newline at end of file diff --git a/src/main/java/junit/framework/Protectable.java b/src/main/java/junit/framework/Protectable.java index 9f30b10..c5ceb16 100644 --- a/src/main/java/junit/framework/Protectable.java +++ b/src/main/java/junit/framework/Protectable.java @@ -8,7 +8,7 @@ package junit.framework; public interface Protectable { /** - * Run the the following method protected. + * Run the following method protected. */ public abstract void protect() throws Throwable; -}
\ No newline at end of file +} diff --git a/src/main/java/junit/framework/TestCase.java b/src/main/java/junit/framework/TestCase.java index b89ce71..e474a64 100644 --- a/src/main/java/junit/framework/TestCase.java +++ b/src/main/java/junit/framework/TestCase.java @@ -73,6 +73,7 @@ import java.lang.reflect.Modifier; * @see TestResult * @see TestSuite */ +@SuppressWarnings("deprecation") public abstract class TestCase extends Assert implements Test { /** * the name of the test case @@ -102,7 +103,7 @@ public abstract class TestCase extends Assert implements Test { } /** - * Creates a default TestResult object + * Creates a default TestResult object. * * @see TestResult */ @@ -187,7 +188,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that a condition is true. If it isn't it throws * an AssertionFailedError with the given message. */ - @SuppressWarnings("deprecation") public static void assertTrue(String message, boolean condition) { Assert.assertTrue(message, condition); } @@ -196,7 +196,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that a condition is true. If it isn't it throws * an AssertionFailedError. */ - @SuppressWarnings("deprecation") public static void assertTrue(boolean condition) { Assert.assertTrue(condition); } @@ -205,7 +204,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that a condition is false. If it isn't it throws * an AssertionFailedError with the given message. */ - @SuppressWarnings("deprecation") public static void assertFalse(String message, boolean condition) { Assert.assertFalse(message, condition); } @@ -214,7 +212,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that a condition is false. If it isn't it throws * an AssertionFailedError. */ - @SuppressWarnings("deprecation") public static void assertFalse(boolean condition) { Assert.assertFalse(condition); } @@ -222,7 +219,6 @@ public abstract class TestCase extends Assert implements Test { /** * Fails a test with the given message. */ - @SuppressWarnings("deprecation") public static void fail(String message) { Assert.fail(message); } @@ -230,7 +226,6 @@ public abstract class TestCase extends Assert implements Test { /** * Fails a test with no message. */ - @SuppressWarnings("deprecation") public static void fail() { Assert.fail(); } @@ -239,7 +234,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two objects are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - @SuppressWarnings("deprecation") public static void assertEquals(String message, Object expected, Object actual) { Assert.assertEquals(message, expected, actual); } @@ -248,7 +242,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two objects are equal. If they are not * an AssertionFailedError is thrown. */ - @SuppressWarnings("deprecation") public static void assertEquals(Object expected, Object actual) { Assert.assertEquals(expected, actual); } @@ -256,7 +249,6 @@ public abstract class TestCase extends Assert implements Test { /** * Asserts that two Strings are equal. */ - @SuppressWarnings("deprecation") public static void assertEquals(String message, String expected, String actual) { Assert.assertEquals(message, expected, actual); } @@ -264,7 +256,6 @@ public abstract class TestCase extends Assert implements Test { /** * Asserts that two Strings are equal. */ - @SuppressWarnings("deprecation") public static void assertEquals(String expected, String actual) { Assert.assertEquals(expected, actual); } @@ -274,7 +265,6 @@ public abstract class TestCase extends Assert implements Test { * an AssertionFailedError is thrown with the given message. If the expected * value is infinity then the delta value is ignored. */ - @SuppressWarnings("deprecation") public static void assertEquals(String message, double expected, double actual, double delta) { Assert.assertEquals(message, expected, actual, delta); } @@ -283,7 +273,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two doubles are equal concerning a delta. If the expected * value is infinity then the delta value is ignored. */ - @SuppressWarnings("deprecation") public static void assertEquals(double expected, double actual, double delta) { Assert.assertEquals(expected, actual, delta); } @@ -293,7 +282,6 @@ public abstract class TestCase extends Assert implements Test { * are not an AssertionFailedError is thrown with the given message. If the * expected value is infinity then the delta value is ignored. */ - @SuppressWarnings("deprecation") public static void assertEquals(String message, float expected, float actual, float delta) { Assert.assertEquals(message, expected, actual, delta); } @@ -302,7 +290,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two floats are equal concerning a delta. If the expected * value is infinity then the delta value is ignored. */ - @SuppressWarnings("deprecation") public static void assertEquals(float expected, float actual, float delta) { Assert.assertEquals(expected, actual, delta); } @@ -311,7 +298,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two longs are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - @SuppressWarnings("deprecation") public static void assertEquals(String message, long expected, long actual) { Assert.assertEquals(message, expected, actual); } @@ -319,7 +305,6 @@ public abstract class TestCase extends Assert implements Test { /** * Asserts that two longs are equal. */ - @SuppressWarnings("deprecation") public static void assertEquals(long expected, long actual) { Assert.assertEquals(expected, actual); } @@ -328,7 +313,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two booleans are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - @SuppressWarnings("deprecation") public static void assertEquals(String message, boolean expected, boolean actual) { Assert.assertEquals(message, expected, actual); } @@ -336,7 +320,6 @@ public abstract class TestCase extends Assert implements Test { /** * Asserts that two booleans are equal. */ - @SuppressWarnings("deprecation") public static void assertEquals(boolean expected, boolean actual) { Assert.assertEquals(expected, actual); } @@ -345,7 +328,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two bytes are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - @SuppressWarnings("deprecation") public static void assertEquals(String message, byte expected, byte actual) { Assert.assertEquals(message, expected, actual); } @@ -353,7 +335,6 @@ public abstract class TestCase extends Assert implements Test { /** * Asserts that two bytes are equal. */ - @SuppressWarnings("deprecation") public static void assertEquals(byte expected, byte actual) { Assert.assertEquals(expected, actual); } @@ -362,7 +343,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two chars are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - @SuppressWarnings("deprecation") public static void assertEquals(String message, char expected, char actual) { Assert.assertEquals(message, expected, actual); } @@ -370,7 +350,6 @@ public abstract class TestCase extends Assert implements Test { /** * Asserts that two chars are equal. */ - @SuppressWarnings("deprecation") public static void assertEquals(char expected, char actual) { Assert.assertEquals(expected, actual); } @@ -379,7 +358,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two shorts are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - @SuppressWarnings("deprecation") public static void assertEquals(String message, short expected, short actual) { Assert.assertEquals(message, expected, actual); } @@ -387,7 +365,6 @@ public abstract class TestCase extends Assert implements Test { /** * Asserts that two shorts are equal. */ - @SuppressWarnings("deprecation") public static void assertEquals(short expected, short actual) { Assert.assertEquals(expected, actual); } @@ -396,7 +373,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two ints are equal. If they are not * an AssertionFailedError is thrown with the given message. */ - @SuppressWarnings("deprecation") public static void assertEquals(String message, int expected, int actual) { Assert.assertEquals(message, expected, actual); } @@ -404,7 +380,6 @@ public abstract class TestCase extends Assert implements Test { /** * Asserts that two ints are equal. */ - @SuppressWarnings("deprecation") public static void assertEquals(int expected, int actual) { Assert.assertEquals(expected, actual); } @@ -412,7 +387,6 @@ public abstract class TestCase extends Assert implements Test { /** * Asserts that an object isn't null. */ - @SuppressWarnings("deprecation") public static void assertNotNull(Object object) { Assert.assertNotNull(object); } @@ -421,7 +395,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that an object isn't null. If it is * an AssertionFailedError is thrown with the given message. */ - @SuppressWarnings("deprecation") public static void assertNotNull(String message, Object object) { Assert.assertNotNull(message, object); } @@ -433,7 +406,6 @@ public abstract class TestCase extends Assert implements Test { * * @param object Object to check or <code>null</code> */ - @SuppressWarnings("deprecation") public static void assertNull(Object object) { Assert.assertNull(object); } @@ -442,7 +414,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that an object is null. If it is not * an AssertionFailedError is thrown with the given message. */ - @SuppressWarnings("deprecation") public static void assertNull(String message, Object object) { Assert.assertNull(message, object); } @@ -451,7 +422,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two objects refer to the same object. If they are not * an AssertionFailedError is thrown with the given message. */ - @SuppressWarnings("deprecation") public static void assertSame(String message, Object expected, Object actual) { Assert.assertSame(message, expected, actual); } @@ -460,7 +430,6 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two objects refer to the same object. If they are not * the same an AssertionFailedError is thrown. */ - @SuppressWarnings("deprecation") public static void assertSame(Object expected, Object actual) { Assert.assertSame(expected, actual); } @@ -470,7 +439,6 @@ public abstract class TestCase extends Assert implements Test { * refer to the same object an AssertionFailedError is thrown with the * given message. */ - @SuppressWarnings("deprecation") public static void assertNotSame(String message, Object expected, Object actual) { Assert.assertNotSame(message, expected, actual); } @@ -479,27 +447,22 @@ public abstract class TestCase extends Assert implements Test { * Asserts that two objects do not refer to the same object. If they do * refer to the same object an AssertionFailedError is thrown. */ - @SuppressWarnings("deprecation") public static void assertNotSame(Object expected, Object actual) { Assert.assertNotSame(expected, actual); } - @SuppressWarnings("deprecation") public static void failSame(String message) { Assert.failSame(message); } - @SuppressWarnings("deprecation") public static void failNotSame(String message, Object expected, Object actual) { Assert.failNotSame(message, expected, actual); } - @SuppressWarnings("deprecation") public static void failNotEquals(String message, Object expected, Object actual) { Assert.failNotEquals(message, expected, actual); } - @SuppressWarnings("deprecation") public static String format(String message, Object expected, Object actual) { return Assert.format(message, expected, actual); } @@ -519,7 +482,7 @@ public abstract class TestCase extends Assert implements Test { } /** - * Returns a string representation of the test case + * Returns a string representation of the test case. */ @Override public String toString() { @@ -527,7 +490,7 @@ public abstract class TestCase extends Assert implements Test { } /** - * Gets the name of a TestCase + * Gets the name of a TestCase. * * @return the name of the TestCase */ @@ -536,7 +499,7 @@ public abstract class TestCase extends Assert implements Test { } /** - * Sets the name of a TestCase + * Sets the name of a TestCase. * * @param name the name to set */ diff --git a/src/main/java/junit/framework/TestFailure.java b/src/main/java/junit/framework/TestFailure.java index 6168b58..d1ddfbc 100644 --- a/src/main/java/junit/framework/TestFailure.java +++ b/src/main/java/junit/framework/TestFailure.java @@ -1,7 +1,6 @@ package junit.framework; -import java.io.PrintWriter; -import java.io.StringWriter; +import org.junit.internal.Throwables; /** @@ -49,10 +48,7 @@ public class TestFailure { * thrown by TestFailure. */ public String trace() { - StringWriter stringWriter = new StringWriter(); - PrintWriter writer = new PrintWriter(stringWriter); - thrownException().printStackTrace(writer); - return stringWriter.toString(); + return Throwables.getStacktrace(thrownException()); } /** diff --git a/src/main/java/junit/framework/TestResult.java b/src/main/java/junit/framework/TestResult.java index 8332542..e01a2b0 100644 --- a/src/main/java/junit/framework/TestResult.java +++ b/src/main/java/junit/framework/TestResult.java @@ -52,14 +52,14 @@ public class TestResult { } /** - * Registers a TestListener + * Registers a TestListener. */ public synchronized void addListener(TestListener listener) { fListeners.add(listener); } /** - * Unregisters a TestListener + * Unregisters a TestListener. */ public synchronized void removeListener(TestListener listener) { fListeners.remove(listener); @@ -91,7 +91,7 @@ public class TestResult { } /** - * Returns an Enumeration for the errors + * Returns an Enumeration for the errors. */ public synchronized Enumeration<TestFailure> errors() { return Collections.enumeration(fErrors); @@ -106,7 +106,7 @@ public class TestResult { } /** - * Returns an Enumeration for the failures + * Returns an Enumeration for the failures. */ public synchronized Enumeration<TestFailure> failures() { return Collections.enumeration(fFailures); @@ -150,7 +150,7 @@ public class TestResult { } /** - * Checks whether the test run should stop + * Checks whether the test run should stop. */ public synchronized boolean shouldStop() { return fStop; diff --git a/src/main/java/junit/framework/TestSuite.java b/src/main/java/junit/framework/TestSuite.java index 366f1cf..50cd5f8 100644 --- a/src/main/java/junit/framework/TestSuite.java +++ b/src/main/java/junit/framework/TestSuite.java @@ -1,7 +1,5 @@ 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; @@ -12,6 +10,7 @@ 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. @@ -35,7 +34,7 @@ import org.junit.internal.MethodSorter; * <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> * @@ -65,11 +64,11 @@ public class TestSuite implements Test { test = constructor.newInstance(new Object[]{name}); } } catch (InstantiationException e) { - return (warning("Cannot instantiate test case: " + name + " (" + exceptionToString(e) + ")")); + return (warning("Cannot instantiate test case: " + name + " (" + Throwables.getStacktrace(e) + ")")); } catch (InvocationTargetException e) { - return (warning("Exception in constructor: " + name + " (" + exceptionToString(e.getTargetException()) + ")")); + return (warning("Exception in constructor: " + name + " (" + Throwables.getStacktrace(e.getTargetException()) + ")")); } catch (IllegalAccessException e) { - return (warning("Cannot access test case: " + name + " (" + exceptionToString(e) + ")")); + return (warning("Cannot access test case: " + name + " (" + Throwables.getStacktrace(e) + ")")); } return (Test) test; } @@ -99,16 +98,6 @@ 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 @@ -210,7 +199,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)); @@ -262,21 +251,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(); diff --git a/src/main/java/junit/runner/BaseTestRunner.java b/src/main/java/junit/runner/BaseTestRunner.java index 8268323..d63fae7 100644 --- a/src/main/java/junit/runner/BaseTestRunner.java +++ b/src/main/java/junit/runner/BaseTestRunner.java @@ -20,6 +20,8 @@ import junit.framework.Test; import junit.framework.TestListener; import junit.framework.TestSuite; +import org.junit.internal.Throwables; + /** * Base class for all test runners. * This class was born live on stage in Sardinia during XP2000. @@ -233,6 +235,7 @@ public abstract class BaseTestRunner implements TestListener { setPreferences(new Properties(getPreferences())); getPreferences().load(is); } catch (IOException ignored) { + } catch (SecurityException ignored) { } finally { try { if (is != null) { @@ -264,11 +267,7 @@ public abstract class BaseTestRunner implements TestListener { * Returns a filtered stack trace */ public static String getFilteredTrace(Throwable e) { - StringWriter stringWriter = new StringWriter(); - PrintWriter writer = new PrintWriter(stringWriter); - e.printStackTrace(writer); - String trace = stringWriter.toString(); - return BaseTestRunner.getFilteredTrace(trace); + return BaseTestRunner.getFilteredTrace(Throwables.getStacktrace(e)); } /** diff --git a/src/main/java/junit/runner/TestRunListener.java b/src/main/java/junit/runner/TestRunListener.java index b5e22f5..ce5b3d5 100644 --- a/src/main/java/junit/runner/TestRunListener.java +++ b/src/main/java/junit/runner/TestRunListener.java @@ -8,18 +8,18 @@ package junit.runner; */ public interface TestRunListener { /* test status constants*/ - public static final int STATUS_ERROR = 1; - public static final int STATUS_FAILURE = 2; + int STATUS_ERROR = 1; + int STATUS_FAILURE = 2; - public void testRunStarted(String testSuiteName, int testCount); + void testRunStarted(String testSuiteName, int testCount); - public void testRunEnded(long elapsedTime); + void testRunEnded(long elapsedTime); - public void testRunStopped(long elapsedTime); + void testRunStopped(long elapsedTime); - public void testStarted(String testName); + void testStarted(String testName); - public void testEnded(String testName); + void testEnded(String testName); - public void testFailed(int status, String testName, String trace); + void testFailed(int status, String testName, String trace); } diff --git a/src/main/java/junit/runner/Version.java b/src/main/java/junit/runner/Version.java index eaf3db7..6c7862e 100644 --- a/src/main/java/junit/runner/Version.java +++ b/src/main/java/junit/runner/Version.java @@ -9,7 +9,7 @@ public class Version { } public static String id() { - return "4.12-SNAPSHOT"; + return "4.13.3-SNAPSHOT"; } public static void main(String[] args) { diff --git a/src/main/java/junit/textui/TestRunner.java b/src/main/java/junit/textui/TestRunner.java index 4d78f77..913020a 100644 --- a/src/main/java/junit/textui/TestRunner.java +++ b/src/main/java/junit/textui/TestRunner.java @@ -131,7 +131,7 @@ public class TestRunner extends BaseTestRunner { } } - public static void main(String args[]) { + public static void main(String[] args) { TestRunner aTestRunner = new TestRunner(); try { TestResult r = aTestRunner.start(args); @@ -149,7 +149,7 @@ public class TestRunner extends BaseTestRunner { * Starts a test run. Analyzes the command line arguments and runs the given * test suite. */ - public TestResult start(String args[]) throws Exception { + public TestResult start(String[] args) throws Exception { String testCase = ""; String method = ""; boolean wait = false; |