diff -wcr junit3.7a/junit/awtui/TestRunner.java junit3.7/junit/awtui/TestRunner.java *** junit3.7a/junit/awtui/TestRunner.java Mon Sep 17 16:48:01 2001 --- junit3.7/junit/awtui/TestRunner.java Mon Sep 17 17:41:34 2001 *************** *** 124,132 **** mb.add(createJUnitMenu()); } protected TestResult createTestResult() { ! TestResult result = new TestResult(); ! Assert.setResult(result); ! return result; } protected Frame createUI(String suiteName) { --- 124,130 ---- mb.add(createJUnitMenu()); } protected TestResult createTestResult() { ! return new TestResult(); } protected Frame createUI(String suiteName) { diff -wcr junit3.7a/junit/framework/Assert.java junit3.7/junit/framework/Assert.java *** junit3.7a/junit/framework/Assert.java Fri Sep 21 14:53:52 2001 --- junit3.7/junit/framework/Assert.java Mon Sep 17 17:41:35 2001 *************** *** 2,78 **** /** * A set of assert methods. - * Modified to allow for multiple failures by Shane Celis - * */ - public class Assert { - - /** - * Needed for doing multiple failures in one test. - **/ - private static TestResult result; - - /** - * The test that will be calling the asserts (usually just - * this, by virtue of extension a la TestCase) - **/ - private final Test test; - private boolean fatal = true; // default behavior is fatal asserts - /** - * Public constructor for performing asserts on a test which extends Assert. - */ - public Assert() { - if (this instanceof Test) - this.test = (Test) this; - else - this.test = null; - } - - /** - * Public constructor for performing asserts on tests which don't extend - * Assert. - **/ - public Assert(Test test) { - if (test == null) { - throw new NullPointerException(); - } - this.test = test; - } - - /** - * @param fatal sets assert to fatal (one failure per test) or non fatal - * (multiple failures per test) - **/ - public void setFatal(boolean fatal) { - if (test == null && !fatal) { - throw new IllegalArgumentException("Must provide Assert with a " + - "Test during construction, if it's not being used from an " + - "extending class."); - } - this.fatal = fatal; - } - - /** - * @return whether asserts are currently fatal - **/ - public boolean isFatal() { - return fatal; - } /** ! * Returns the test that's currently using the asserts. This is ! * necessary in order to the logging of the assert, rather than ! * simply throwing an exception ! **/ ! private Test getTest() { ! return test; } /** * Asserts that a condition is true. If it isn't it throws * an AssertionFailedError with the given message. * @deprecated use assertTrue */ ! public void assert(String message, boolean condition) { if (!condition) fail(message); } --- 2,21 ---- /** * A set of assert methods. */ + public class Assert { /** ! * Protect constructor since it is a static only class ! */ ! protected Assert() { } /** * Asserts that a condition is true. If it isn't it throws * an AssertionFailedError with the given message. * @deprecated use assertTrue */ ! static public void assert(String message, boolean condition) { if (!condition) fail(message); } *************** *** 82,88 **** * @deprecated use assertTrue * */ ! public void assert(boolean condition) { assert(null, condition); } --- 25,31 ---- * @deprecated use assertTrue * */ ! static public void assert(boolean condition) { assert(null, condition); } *************** *** 90,96 **** * Asserts that a condition is true. If it isn't it throws * an AssertionFailedError with the given message. */ ! public void assertTrue(String message, boolean condition) { if (!condition) fail(message); } --- 33,39 ---- * 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) { if (!condition) fail(message); } *************** *** 98,143 **** * Asserts that a condition is true. If it isn't it throws * an AssertionFailedError. */ ! public void assertTrue(boolean condition) { assertTrue(null, condition); } /** * Fails a test with the given message. */ ! public void fail(String message) { ! TestResult result = getResult(); ! if (result != null && !isFatal()) { ! //New behavior (multiple failures per test) ! result.addFailure(getTest(), ! new AssertionFailedError(message)); ! } else { ! if (!isFatal()) { ! System.err.println("setResult on Assert is not being " + ! "called to allow for NonFatalAsserts to work properly"); ! } ! //Old behavior (one failure per test) throw new AssertionFailedError(message); } - } - - public static TestResult getResult() { - return result; - } - - public static void setResult(TestResult result) { - Assert.result = result; - } /** * Fails a test with no message. */ ! public void fail() { fail(null); } /** * Asserts that two objects are equal. If they are not * an AssertionFailedError is thrown. */ ! public void assertEquals(String message, Object expected, Object actual) { if (expected == null && actual == null) return; if (expected != null && expected.equals(actual)) --- 41,66 ---- * Asserts that a condition is true. If it isn't it throws * an AssertionFailedError. */ ! static public void assertTrue(boolean condition) { assertTrue(null, condition); } /** * Fails a test with the given message. */ ! static public void fail(String message) { throw new AssertionFailedError(message); } /** * Fails a test with no message. */ ! static public void fail() { fail(null); } /** * Asserts that two objects are equal. If they are not * an AssertionFailedError is thrown. */ ! static public void assertEquals(String message, Object expected, Object actual) { if (expected == null && actual == null) return; if (expected != null && expected.equals(actual)) *************** *** 148,161 **** * Asserts that two objects are equal. If they are not * an AssertionFailedError is thrown. */ ! public void assertEquals(Object expected, Object actual) { assertEquals(null, expected, actual); } /** * Asserts that two doubles are equal concerning a delta. If the expected * value is infinity then the delta value is ignored. */ ! public void assertEquals(String message, double expected, double actual, double delta) { // handle infinity specially since subtracting to infinite values gives NaN and the // the following test fails if (Double.isInfinite(expected)) { --- 71,84 ---- * Asserts that two objects are equal. If they are not * an AssertionFailedError is thrown. */ ! static public void assertEquals(Object expected, Object actual) { assertEquals(null, expected, actual); } /** * 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(String message, double expected, double actual, double delta) { // handle infinity specially since subtracting to infinite values gives NaN and the // the following test fails if (Double.isInfinite(expected)) { *************** *** 168,181 **** * Asserts that two doubles are equal concerning a delta. If the expected * value is infinity then the delta value is ignored. */ ! public void assertEquals(double expected, double actual, double delta) { assertEquals(null, expected, actual, delta); } /** * Asserts that two floats are equal concerning a delta. If the expected * value is infinity then the delta value is ignored. */ ! public void assertEquals(String message, float expected, float actual, float delta) { // handle infinity specially since subtracting to infinite values gives NaN and the // the following test fails if (Float.isInfinite(expected)) { --- 91,104 ---- * 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) { assertEquals(null, expected, actual, delta); } /** * 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(String message, float expected, float actual, float delta) { // handle infinity specially since subtracting to infinite values gives NaN and the // the following test fails if (Float.isInfinite(expected)) { *************** *** 188,297 **** * Asserts that two floats are equal concerning a delta. If the expected * value is infinity then the delta value is ignored. */ ! public void assertEquals(float expected, float actual, float delta) { assertEquals(null, expected, actual, delta); } /** * Asserts that two longs are equal. */ ! public void assertEquals(String message, long expected, long actual) { assertEquals(message, new Long(expected), new Long(actual)); } /** * Asserts that two longs are equal. */ ! public void assertEquals(long expected, long actual) { assertEquals(null, expected, actual); } /** * Asserts that two booleans are equal. */ ! public void assertEquals(String message, boolean expected, boolean actual) { assertEquals(message, new Boolean(expected), new Boolean(actual)); } /** * Asserts that two booleans are equal. */ ! public void assertEquals(boolean expected, boolean actual) { assertEquals(null, expected, actual); } /** * Asserts that two bytes are equal. */ ! public void assertEquals(String message, byte expected, byte actual) { assertEquals(message, new Byte(expected), new Byte(actual)); } /** * Asserts that two bytes are equal. */ ! public void assertEquals(byte expected, byte actual) { assertEquals(null, expected, actual); } /** * Asserts that two chars are equal. */ ! public void assertEquals(String message, char expected, char actual) { assertEquals(message, new Character(expected), new Character(actual)); } /** * Asserts that two chars are equal. */ ! public void assertEquals(char expected, char actual) { assertEquals(null, expected, actual); } /** * Asserts that two shorts are equal. */ ! public void assertEquals(String message, short expected, short actual) { assertEquals(message, new Short(expected), new Short(actual)); } /** * Asserts that two shorts are equal. */ ! public void assertEquals(short expected, short actual) { assertEquals(null, expected, actual); } /** * Asserts that two ints are equal. */ ! public void assertEquals(String message, int expected, int actual) { assertEquals(message, new Integer(expected), new Integer(actual)); } /** * Asserts that two ints are equal. */ ! public void assertEquals(int expected, int actual) { assertEquals(null, expected, actual); } /** * Asserts that an object isn't null. */ ! public void assertNotNull(Object object) { assertNotNull(null, object); } /** * Asserts that an object isn't null. */ ! public void assertNotNull(String message, Object object) { assertTrue(message, object != null); } /** * Asserts that an object is null. */ ! public void assertNull(Object object) { assertNull(null, object); } /** * Asserts that an object is null. */ ! public void assertNull(String message, Object object) { assertTrue(message, object == null); } /** * Asserts that two objects refer to the same object. If they are not * an AssertionFailedError is thrown. */ ! public void assertSame(String message, Object expected, Object actual) { if (expected == actual) return; failNotSame(message, expected, actual); --- 111,220 ---- * 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) { assertEquals(null, expected, actual, delta); } /** * Asserts that two longs are equal. */ ! static public void assertEquals(String message, long expected, long actual) { assertEquals(message, new Long(expected), new Long(actual)); } /** * Asserts that two longs are equal. */ ! static public void assertEquals(long expected, long actual) { assertEquals(null, expected, actual); } /** * Asserts that two booleans are equal. */ ! static public void assertEquals(String message, boolean expected, boolean actual) { assertEquals(message, new Boolean(expected), new Boolean(actual)); } /** * Asserts that two booleans are equal. */ ! static public void assertEquals(boolean expected, boolean actual) { assertEquals(null, expected, actual); } /** * Asserts that two bytes are equal. */ ! static public void assertEquals(String message, byte expected, byte actual) { assertEquals(message, new Byte(expected), new Byte(actual)); } /** * Asserts that two bytes are equal. */ ! static public void assertEquals(byte expected, byte actual) { assertEquals(null, expected, actual); } /** * Asserts that two chars are equal. */ ! static public void assertEquals(String message, char expected, char actual) { assertEquals(message, new Character(expected), new Character(actual)); } /** * Asserts that two chars are equal. */ ! static public void assertEquals(char expected, char actual) { assertEquals(null, expected, actual); } /** * Asserts that two shorts are equal. */ ! static public void assertEquals(String message, short expected, short actual) { assertEquals(message, new Short(expected), new Short(actual)); } /** * Asserts that two shorts are equal. */ ! static public void assertEquals(short expected, short actual) { assertEquals(null, expected, actual); } /** * Asserts that two ints are equal. */ ! static public void assertEquals(String message, int expected, int actual) { assertEquals(message, new Integer(expected), new Integer(actual)); } /** * Asserts that two ints are equal. */ ! static public void assertEquals(int expected, int actual) { assertEquals(null, expected, actual); } /** * Asserts that an object isn't null. */ ! static public void assertNotNull(Object object) { assertNotNull(null, object); } /** * Asserts that an object isn't null. */ ! static public void assertNotNull(String message, Object object) { assertTrue(message, object != null); } /** * Asserts that an object is null. */ ! static public void assertNull(Object object) { assertNull(null, object); } /** * Asserts that an object is null. */ ! static public void assertNull(String message, Object object) { assertTrue(message, object == null); } /** * Asserts that two objects refer to the same object. If they are not * an AssertionFailedError is thrown. */ ! static public void assertSame(String message, Object expected, Object actual) { if (expected == actual) return; failNotSame(message, expected, actual); *************** *** 300,317 **** * Asserts that two objects refer to the same object. If they are not * the same an AssertionFailedError is thrown. */ ! public void assertSame(Object expected, Object actual) { assertSame(null, expected, actual); } ! private void failNotEquals(String message, Object expected, Object actual) { String formatted= ""; if (message != null) formatted= message+" "; fail(formatted+"expected:<"+expected+"> but was:<"+actual+">"); } ! private void failNotSame(String message, Object expected, Object actual) { String formatted= ""; if (message != null) formatted= message+" "; --- 223,240 ---- * 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) { assertSame(null, expected, actual); } ! static private void failNotEquals(String message, Object expected, Object actual) { String formatted= ""; if (message != null) formatted= message+" "; fail(formatted+"expected:<"+expected+"> but was:<"+actual+">"); } ! static private void failNotSame(String message, Object expected, Object actual) { String formatted= ""; if (message != null) formatted= message+" "; diff -wcr junit3.7a/junit/samples/SimpleTest.java junit3.7/junit/samples/SimpleTest.java *** junit3.7a/junit/samples/SimpleTest.java Fri Sep 21 14:57:52 2001 --- junit3.7/junit/samples/SimpleTest.java Mon May 21 10:18:56 2001 *************** *** 11,18 **** protected int fValue2; public SimpleTest(String name) { super(name); - // comment out the following line, to see the regular results - setFatal(false); // use nonfatal asserts } protected void setUp() { fValue1= 2; --- 11,16 ---- *************** *** 60,68 **** assertEquals("Size", 12, 13); assertEquals("Capacity", 12.0, 11.99, 0.0); } - public void testMultipleFailures() { - fail("failing once"); - fail("failing twice"); - fail("failing once again"); - } } --- 58,61 ---- diff -wcr junit3.7a/junit/swingui/TestRunner.java junit3.7/junit/swingui/TestRunner.java *** junit3.7a/junit/swingui/TestRunner.java Mon Sep 17 16:50:29 2001 --- junit3.7/junit/swingui/TestRunner.java Mon Sep 17 17:41:35 2001 *************** *** 375,383 **** } protected TestResult createTestResult() { ! TestResult result = new TestResult(); ! Assert.setResult(result); ! return result; } protected JFrame createUI(String suiteName) { --- 375,381 ---- } protected TestResult createTestResult() { ! return new TestResult(); } protected JFrame createUI(String suiteName) { diff -wcr junit3.7a/junit/textui/TestRunner.java junit3.7/junit/textui/TestRunner.java *** junit3.7a/junit/textui/TestRunner.java Mon Sep 17 15:40:11 2001 --- junit3.7/junit/textui/TestRunner.java Mon Sep 17 17:41:35 2001 *************** *** 24,31 **** *

* TestRunner prints a trace as the tests are executed followed by a * summary at the end. - * - * Modified to allow for multiple Test Failures by Shane Celis */ public class TestRunner extends BaseTestRunner { PrintStream fWriter= System.out; --- 24,29 ---- *************** *** 66,74 **** * Creates the TestResult to be used for the test run. */ protected TestResult createTestResult() { ! TestResult result = new TestResult(); ! Assert.setResult(result); ! return result; } public TestResult doRun(Test suite, boolean wait) { --- 64,70 ---- * Creates the TestResult to be used for the test run. */ protected TestResult createTestResult() { ! return new TestResult(); } public TestResult doRun(Test suite, boolean wait) {