# HG changeset patch # User cawthron # Date 1259948994 21600 # Node ID 3ef299ba838f57d2ad8387b3e26647934c708c4d # Parent 8d56403172bcfee27a7770c945e765fa16c6e12b add files for RCL_2_2 diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/META-INF/MANIFEST.MF --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/META-INF/MANIFEST.MF Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-Vendor: %providerName +Bundle-Version: 3.5.0.r20080925 +Bundle-Localization: plugin +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.test.source; singleton=true + + diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/plugin.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/plugin.xml Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,9 @@ + + + + + + + + + diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.eclipse.test.performance_3.5.0.v20090511/src.zip Binary file carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.eclipse.test.performance_3.5.0.v20090511/src.zip has changed diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.eclipse.test_3.2.0/automatedsrc.zip Binary file carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.eclipse.test_3.2.0/automatedsrc.zip has changed diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/about.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/about.html Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,44 @@ + + + + +About + + +

About This Content

+ +

April 17, 2009

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ +

Third Party Content

+ +

The Content includes items that have been sourced from third parties as set out below. If you +did not receive this Content directly from the Eclipse Foundation, the following is provided +for informational purposes only, and you should look to the Redistributor’s license for +terms and conditions of use.

+ +

The Content includes items that have been sourced from third parties as follows:

+ +

JUnit 4.5

+ +

The plug-in is accompanied by software developed by JUnit.org. The JUnit 4.5 code included with the plug-in includes no modifications. +Your use of JUnit 4.5 in both source and binary code form contained in the plug-in is subject to the terms and conditions of the +Common Public License Version 1.0 ("CPL"). A copy of the CPL is available at http://www.eclipse.org/legal/cpl-v10.html. +The binary code is located in junit.jar and the source code is located in junitsrc.zip.

+ + + \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc.zip Binary file carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc.zip has changed diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/META-INF/MANIFEST.MF --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/META-INF/MANIFEST.MF Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Ant-Version: Apache Ant 1.7.0 +Created-By: 1.5.0_13-119 (Apple Inc.) + diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/extensions/ActiveTestSuite.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/extensions/ActiveTestSuite.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,70 @@ +package junit.extensions; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestResult; +import junit.framework.TestSuite; + +/** + * A TestSuite for active Tests. It runs each + * test in a separate thread and waits until all + * threads have terminated. + * -- Aarhus Radisson Scandinavian Center 11th floor + */ +public class ActiveTestSuite extends TestSuite { + private volatile int fActiveTestDeathCount; + + public ActiveTestSuite() { + } + + public ActiveTestSuite(Class theClass) { + super(theClass); + } + + public ActiveTestSuite(String name) { + super (name); + } + + public ActiveTestSuite(Class theClass, String name) { + super(theClass, name); + } + + @Override + public void run(TestResult result) { + fActiveTestDeathCount= 0; + super.run(result); + waitUntilFinished(); + } + + @Override + public void runTest(final Test test, final TestResult result) { + Thread t= new Thread() { + @Override + public void run() { + try { + // inlined due to limitation in VA/Java + //ActiveTestSuite.super.runTest(test, result); + test.run(result); + } finally { + ActiveTestSuite.this.runFinished(); + } + } + }; + t.start(); + } + + synchronized void waitUntilFinished() { + while (fActiveTestDeathCount < testCount()) { + try { + wait(); + } catch (InterruptedException e) { + return; // ignore + } + } + } + + synchronized public void runFinished() { + fActiveTestDeathCount++; + notifyAll(); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/extensions/RepeatedTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/extensions/RepeatedTest.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,38 @@ +package junit.extensions; + +import junit.framework.Test; +import junit.framework.TestResult; + +/** + * A Decorator that runs a test repeatedly. + * + */ +public class RepeatedTest extends TestDecorator { + private int fTimesRepeat; + + public RepeatedTest(Test test, int repeat) { + super(test); + if (repeat < 0) + throw new IllegalArgumentException("Repetition count must be >= 0"); + fTimesRepeat= repeat; + } + + @Override + public int countTestCases() { + return super.countTestCases() * fTimesRepeat; + } + + @Override + public void run(TestResult result) { + for (int i= 0; i < fTimesRepeat; i++) { + if (result.shouldStop()) + break; + super.run(result); + } + } + + @Override + public String toString() { + return super.toString() + "(repeated)"; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/extensions/TestDecorator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/extensions/TestDecorator.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,43 @@ +package junit.extensions; + +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestResult; + +/** + * A Decorator for Tests. Use TestDecorator as the base class for defining new + * test decorators. Test decorator subclasses can be introduced to add behaviour + * before or after a test is run. + * + */ +public class TestDecorator extends Assert implements Test { + protected Test fTest; + + public TestDecorator(Test test) { + fTest= test; + } + + /** + * The basic run behaviour. + */ + public void basicRun(TestResult result) { + fTest.run(result); + } + + public int countTestCases() { + return fTest.countTestCases(); + } + + public void run(TestResult result) { + basicRun(result); + } + + @Override + public String toString() { + return fTest.toString(); + } + + public Test getTest() { + return fTest; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/extensions/TestSetup.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/extensions/TestSetup.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,42 @@ +package junit.extensions; + +import junit.framework.Protectable; +import junit.framework.Test; +import junit.framework.TestResult; + +/** + * A Decorator to set up and tear down additional fixture state. Subclass + * TestSetup and insert it into your tests when you want to set up additional + * state once before the tests are run. + */ +public class TestSetup extends TestDecorator { + + public TestSetup(Test test) { + super(test); + } + + @Override + public void run(final TestResult result) { + Protectable p= new Protectable() { + public void protect() throws Exception { + setUp(); + basicRun(result); + tearDown(); + } + }; + result.runProtected(this, p); + } + + /** + * Sets up the fixture. Override to set up additional fixture state. + */ + protected void setUp() throws Exception { + } + + /** + * Tears down the fixture. Override to tear down the additional fixture + * state. + */ + protected void tearDown() throws Exception { + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/extensions/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/extensions/package-info.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,4 @@ +/** + * Provides extended functionality for JUnit v3.x. + */ +package junit.extensions; \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/Assert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/Assert.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,286 @@ +package junit.framework; + +/** + * A set of assert methods. Messages are only displayed when an assert fails. + */ + +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. + */ + static public void assertTrue(String message, boolean condition) { + if (!condition) + fail(message); + } + /** + * Asserts that a condition is true. If it isn't it throws + * an AssertionFailedError. + */ + static public void assertTrue(boolean condition) { + assertTrue(null, condition); + } + /** + * 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) { + assertTrue(message, !condition); + } + /** + * Asserts that a condition is false. If it isn't it throws + * an AssertionFailedError. + */ + static public void assertFalse(boolean condition) { + assertFalse(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 with the given message. + */ + static public void assertEquals(String message, Object expected, Object actual) { + if (expected == null && actual == null) + return; + if (expected != null && expected.equals(actual)) + return; + failNotEquals(message, expected, actual); + } + /** + * 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 Strings are equal. + */ + static public void assertEquals(String message, String expected, String actual) { + if (expected == null && actual == null) + return; + if (expected != null && expected.equals(actual)) + return; + throw new ComparisonFailure(message, expected, actual); + } + /** + * Asserts that two Strings are equal. + */ + static public void assertEquals(String expected, String actual) { + assertEquals(null, expected, actual); + } + /** + * Asserts that two doubles are equal concerning a delta. If they 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, 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)); + } + /** + * 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 positive delta. If they + * 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) { + if (Float.compare(expected, actual) == 0) + return; + if (!(Math.abs(expected - actual) <= delta)) + failNotEquals(message, new Float(expected), new Float(actual)); + } + /** + * 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. If they are not + * an AssertionFailedError is thrown with the given message. + */ + 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. If they are not + * an AssertionFailedError is thrown with the given message. + */ + static public 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) { + assertEquals(null, expected, actual); + } + /** + * 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) { + 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. If they are not + * an AssertionFailedError is thrown with the given message. + */ + 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. If they are not + * an AssertionFailedError is thrown with the given message. + */ + 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. If they are not + * an AssertionFailedError is thrown with the given message. + */ + 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. If it is + * an AssertionFailedError is thrown with the given message. + */ + 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. If it is not + * an AssertionFailedError is thrown with the given message. + */ + 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 with the given message. + */ + static public void assertSame(String message, Object expected, Object actual) { + if (expected == actual) + return; + failNotSame(message, expected, actual); + } + /** + * 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); + } + /** + * Asserts that two objects do not refer to the same object. If they do + * refer to the same object an AssertionFailedError is thrown with the + * given message. + */ + static public void assertNotSame(String message, Object expected, Object actual) { + if (expected == actual) + failSame(message); + } + /** + * 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) { + assertNotSame(null, expected, actual); + } + + static public void failSame(String message) { + String formatted= ""; + if (message != null) + formatted= message+" "; + fail(formatted+"expected not same"); + } + + static public void failNotSame(String message, Object expected, Object actual) { + String formatted= ""; + if (message != null) + formatted= message+" "; + fail(formatted+"expected same:<"+expected+"> was not:<"+actual+">"); + } + + static public void failNotEquals(String message, Object expected, Object actual) { + fail(format(message, expected, actual)); + } + + public static String format(String message, Object expected, Object actual) { + String formatted= ""; + if (message != null) + formatted= message+" "; + return formatted+"expected:<"+expected+"> but was:<"+actual+">"; + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/AssertionFailedError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/AssertionFailedError.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,16 @@ +package junit.framework; + +/** + * Thrown when an assertion failed. + */ +public class AssertionFailedError extends AssertionError { + + private static final long serialVersionUID= 1L; + + public AssertionFailedError() { + } + + public AssertionFailedError(String message) { + super(message); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/ComparisonCompactor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/ComparisonCompactor.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,72 @@ +package junit.framework; + +public class ComparisonCompactor { + + private static final String ELLIPSIS= "..."; + private static final String DELTA_END= "]"; + private static final String DELTA_START= "["; + + private int fContextLength; + private String fExpected; + private String fActual; + private int fPrefix; + private int fSuffix; + + public ComparisonCompactor(int contextLength, String expected, String actual) { + fContextLength= contextLength; + fExpected= expected; + fActual= actual; + } + + public String compact(String message) { + if (fExpected == null || fActual == null || areStringsEqual()) + return Assert.format(message, fExpected, fActual); + + findCommonPrefix(); + findCommonSuffix(); + String expected= compactString(fExpected); + String actual= compactString(fActual); + return Assert.format(message, expected, actual); + } + + private String compactString(String source) { + String result= DELTA_START + source.substring(fPrefix, source.length() - fSuffix + 1) + DELTA_END; + if (fPrefix > 0) + result= computeCommonPrefix() + result; + if (fSuffix > 0) + result= result + computeCommonSuffix(); + return result; + } + + private void findCommonPrefix() { + fPrefix= 0; + int end= Math.min(fExpected.length(), fActual.length()); + for (; fPrefix < end; fPrefix++) { + if (fExpected.charAt(fPrefix) != fActual.charAt(fPrefix)) + break; + } + } + + private void findCommonSuffix() { + int expectedSuffix= fExpected.length() - 1; + int actualSuffix= fActual.length() - 1; + for (; actualSuffix >= fPrefix && expectedSuffix >= fPrefix; actualSuffix--, expectedSuffix--) { + if (fExpected.charAt(expectedSuffix) != fActual.charAt(actualSuffix)) + break; + } + fSuffix= fExpected.length() - expectedSuffix; + } + + private String computeCommonPrefix() { + return (fPrefix > fContextLength ? ELLIPSIS : "") + fExpected.substring(Math.max(0, fPrefix - fContextLength), fPrefix); + } + + private String computeCommonSuffix() { + int end= Math.min(fExpected.length() - fSuffix + 1 + fContextLength, fExpected.length()); + return fExpected.substring(fExpected.length() - fSuffix + 1, end) + (fExpected.length() - fSuffix + 1 < fExpected.length() - fContextLength ? ELLIPSIS : ""); + } + + private boolean areStringsEqual() { + return fExpected.equals(fActual); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/ComparisonFailure.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/ComparisonFailure.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,52 @@ +package junit.framework; + +/** + * Thrown when an assert equals for Strings failed. + * + * Inspired by a patch from Alex Chaffee mailto:alex@purpletech.com + */ +public class ComparisonFailure extends AssertionFailedError { + private static final int MAX_CONTEXT_LENGTH= 20; + private static final long serialVersionUID= 1L; + + private String fExpected; + private String fActual; + + /** + * Constructs a comparison failure. + * @param message the identifying message or null + * @param expected the expected string value + * @param actual the actual string value + */ + public ComparisonFailure (String message, String expected, String actual) { + super (message); + fExpected= expected; + fActual= actual; + } + + /** + * Returns "..." in place of common prefix and "..." in + * place of common suffix between expected and actual. + * + * @see Throwable#getMessage() + */ + @Override + public String getMessage() { + return new ComparisonCompactor(MAX_CONTEXT_LENGTH, fExpected, fActual).compact(super.getMessage()); + } + + /** + * Gets the actual string value + * @return the actual string value + */ + public String getActual() { + return fActual; + } + /** + * Gets the expected string value + * @return the expected string value + */ + public String getExpected() { + return fExpected; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/JUnit4TestAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/JUnit4TestAdapter.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,85 @@ +package junit.framework; + +import java.util.List; + +import org.junit.Ignore; +import org.junit.runner.Describable; +import org.junit.runner.Description; +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.NoTestsRemainException; +import org.junit.runner.manipulation.Sortable; +import org.junit.runner.manipulation.Sorter; + +public class JUnit4TestAdapter implements Test, Filterable, Sortable, Describable { + private final Class fNewTestClass; + + private Runner fRunner; + + private JUnit4TestAdapterCache fCache; + + public JUnit4TestAdapter(Class newTestClass) { + this(newTestClass, JUnit4TestAdapterCache.getDefault()); + } + + public JUnit4TestAdapter(final Class newTestClass, + JUnit4TestAdapterCache cache) { + fCache = cache; + fNewTestClass = newTestClass; + fRunner = Request.classWithoutSuiteMethod(newTestClass).getRunner(); + } + + public int countTestCases() { + return fRunner.testCount(); + } + + public void run(TestResult result) { + fRunner.run(fCache.getNotifier(result, this)); + } + + // reflective interface for Eclipse + public List getTests() { + return fCache.asTestList(getDescription()); + } + + // reflective interface for Eclipse + public Class getTestClass() { + return fNewTestClass; + } + + public Description getDescription() { + Description description= fRunner.getDescription(); + return removeIgnored(description); + } + + private Description removeIgnored(Description description) { + if (isIgnored(description)) + return Description.EMPTY; + Description result = description.childlessCopy(); + for (Description each : description.getChildren()) { + Description child= removeIgnored(each); + if (! child.isEmpty()) + result.addChild(child); + } + return result; + } + + private boolean isIgnored(Description description) { + return description.getAnnotation(Ignore.class) != null; + } + + @Override + public String toString() { + return fNewTestClass.getName(); + } + + public void filter(Filter filter) throws NoTestsRemainException { + filter.apply(fRunner); + } + + public void sort(Sorter sorter) { + sorter.apply(fRunner); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/JUnit4TestAdapterCache.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/JUnit4TestAdapterCache.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,81 @@ +/** + * + */ +package junit.framework; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import org.junit.runner.Description; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunListener; +import org.junit.runner.notification.RunNotifier; + +public class JUnit4TestAdapterCache extends HashMap { + private static final long serialVersionUID = 1L; + private static final JUnit4TestAdapterCache fInstance = new JUnit4TestAdapterCache(); + + public static JUnit4TestAdapterCache getDefault() { + return fInstance; + } + + public Test asTest(Description description) { + if (description.isSuite()) + return createTest(description); + else { + if (!containsKey(description)) + put(description, createTest(description)); + return get(description); + } + } + + Test createTest(Description description) { + if (description.isTest()) + return new JUnit4TestCaseFacade(description); + else { + TestSuite suite = new TestSuite(description.getDisplayName()); + for (Description child : description.getChildren()) + suite.addTest(asTest(child)); + return suite; + } + } + + public RunNotifier getNotifier(final TestResult result, + final JUnit4TestAdapter adapter) { + RunNotifier notifier = new RunNotifier(); + notifier.addListener(new RunListener() { + @Override + public void testFailure(Failure failure) throws Exception { + result.addError(asTest(failure.getDescription()), failure.getException()); + } + + @Override + public void testFinished(Description description) + throws Exception { + result.endTest(asTest(description)); + } + + @Override + public void testStarted(Description description) + throws Exception { + result.startTest(asTest(description)); + } + }); + return notifier; + } + + public List asTestList(Description description) { + if (description.isTest()) + return Arrays.asList(asTest(description)); + else { + List returnThis = new ArrayList(); + for (Description child : description.getChildren()) { + returnThis.add(asTest(child)); + } + return returnThis; + } + } + +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/JUnit4TestCaseFacade.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/JUnit4TestCaseFacade.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,33 @@ +/** + * + */ +package junit.framework; + +import org.junit.runner.Describable; +import org.junit.runner.Description; + +public class JUnit4TestCaseFacade implements Test, Describable { + private final Description fDescription; + + JUnit4TestCaseFacade(Description description) { + fDescription = description; + } + + @Override + public String toString() { + return getDescription().toString(); + } + + public int countTestCases() { + return 1; + } + + public void run(TestResult result) { + throw new RuntimeException( + "This test stub created only for informational purposes."); + } + + public Description getDescription() { + return fDescription; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/Protectable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/Protectable.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,14 @@ +package junit.framework; + +/** + * A Protectable can be run and can throw a Throwable. + * + * @see TestResult + */ +public interface Protectable { + + /** + * Run the the following method protected. + */ + public abstract void protect() throws Throwable; +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/Test.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/Test.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,17 @@ +package junit.framework; + +/** + * A Test can be run and collect its results. + * + * @see TestResult + */ +public interface Test { + /** + * Counts the number of test cases that will be run by this test. + */ + public abstract int countTestCases(); + /** + * Runs a test and collects its result in a TestResult instance. + */ + public abstract void run(TestResult result); +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/TestCase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/TestCase.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,212 @@ +package junit.framework; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +/** + * A test case defines the fixture to run multiple tests. To define a test case
+ *
    + *
  1. implement a subclass of TestCase
  2. + *
  3. define instance variables that store the state of the fixture
  4. + *
  5. initialize the fixture state by overriding {@link #setUp()}
  6. + *
  7. clean-up after a test by overriding {@link #tearDown()}.
  8. + *
+ * Each test runs in its own fixture so there + * can be no side effects among test runs. + * Here is an example: + *
+ * public class MathTest extends TestCase {
+ *    protected double fValue1;
+ *    protected double fValue2;
+ *
+ *    protected void setUp() {
+ *       fValue1= 2.0;
+ *       fValue2= 3.0;
+ *    }
+ * }
+ * 
+ * + * For each test implement a method which interacts + * with the fixture. Verify the expected results with assertions specified + * by calling {@link junit.framework.Assert#assertTrue(String, boolean)} with a boolean. + *
+ *    public void testAdd() {
+ *       double result= fValue1 + fValue2;
+ *       assertTrue(result == 5.0);
+ *    }
+ * 
+ * + * Once the methods are defined you can run them. The framework supports + * both a static type safe and more dynamic way to run a test. + * In the static way you override the runTest method and define the method to + * be invoked. A convenient way to do so is with an anonymous inner class. + *
+ * TestCase test= new MathTest("add") {
+ *    public void runTest() {
+ *       testAdd();
+ *    }
+ * };
+ * test.run();
+ * 
+ * + * The dynamic way uses reflection to implement {@link #runTest()}. It dynamically finds + * and invokes a method. + * In this case the name of the test case has to correspond to the test method + * to be run. + *
+ * TestCase test= new MathTest("testAdd");
+ * test.run();
+ * 
+ * + * The tests to be run can be collected into a TestSuite. JUnit provides + * different test runners which can run a test suite and collect the results. + * A test runner either expects a static method suite as the entry + * point to get a test to run or it will extract the suite automatically. + *
+ * public static Test suite() {
+ *    suite.addTest(new MathTest("testAdd"));
+ *    suite.addTest(new MathTest("testDivideByZero"));
+ *    return suite;
+ * }
+ * 
+ * @see TestResult + * @see TestSuite + */ +public abstract class TestCase extends Assert implements Test { + /** + * the name of the test case + */ + private String fName; + + /** + * No-arg constructor to enable serialization. This method + * is not intended to be used by mere mortals without calling setName(). + */ + public TestCase() { + fName= null; + } + /** + * Constructs a test case with the given name. + */ + public TestCase(String name) { + fName= name; + } + /** + * Counts the number of test cases executed by run(TestResult result). + */ + public int countTestCases() { + return 1; + } + /** + * Creates a default TestResult object + * + * @see TestResult + */ + protected TestResult createResult() { + return new TestResult(); + } + /** + * A convenience method to run this test, collecting the results with a + * default TestResult object. + * + * @see TestResult + */ + public TestResult run() { + TestResult result= createResult(); + run(result); + return result; + } + /** + * Runs the test case and collects the results in TestResult. + */ + public void run(TestResult result) { + result.run(this); + } + /** + * Runs the bare test sequence. + * @throws Throwable if any exception is thrown + */ + public void runBare() throws Throwable { + Throwable exception= null; + setUp(); + try { + runTest(); + } catch (Throwable running) { + exception= running; + } + finally { + try { + tearDown(); + } catch (Throwable tearingDown) { + if (exception == null) exception= tearingDown; + } + } + if (exception != null) throw exception; + } + /** + * Override to run the test and assert its state. + * @throws Throwable if any exception is thrown + */ + protected void runTest() throws Throwable { + assertNotNull("TestCase.fName cannot be null", fName); // Some VMs crash when calling getMethod(null,null); + Method runMethod= null; + try { + // use getMethod to get all public inherited + // methods. getDeclaredMethods returns all + // methods of this class but excludes the + // inherited ones. + runMethod= getClass().getMethod(fName, (Class[])null); + } catch (NoSuchMethodException e) { + fail("Method \""+fName+"\" not found"); + } + if (!Modifier.isPublic(runMethod.getModifiers())) { + fail("Method \""+fName+"\" should be public"); + } + + try { + runMethod.invoke(this); + } + catch (InvocationTargetException e) { + e.fillInStackTrace(); + throw e.getTargetException(); + } + catch (IllegalAccessException e) { + e.fillInStackTrace(); + throw e; + } + } + /** + * Sets up the fixture, for example, open a network connection. + * This method is called before a test is executed. + */ + protected void setUp() throws Exception { + } + /** + * Tears down the fixture, for example, close a network connection. + * This method is called after a test is executed. + */ + protected void tearDown() throws Exception { + } + /** + * Returns a string representation of the test case + */ + @Override + public String toString() { + return getName() + "(" + getClass().getName() + ")"; + } + /** + * Gets the name of a TestCase + * @return the name of the TestCase + */ + public String getName() { + return fName; + } + /** + * Sets the name of a TestCase + * @param name the name to set + */ + public void setName(String name) { + fName= name; + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/TestFailure.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/TestFailure.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,58 @@ +package junit.framework; + +import java.io.PrintWriter; +import java.io.StringWriter; + + +/** + * A TestFailure collects a failed test together with + * the caught exception. + * @see TestResult + */ +public class TestFailure extends Object { + protected Test fFailedTest; + protected Throwable fThrownException; + + + /** + * Constructs a TestFailure with the given test and exception. + */ + public TestFailure(Test failedTest, Throwable thrownException) { + fFailedTest= failedTest; + fThrownException= thrownException; + } + /** + * Gets the failed test. + */ + public Test failedTest() { + return fFailedTest; + } + /** + * Gets the thrown exception. + */ + public Throwable thrownException() { + return fThrownException; + } + /** + * Returns a short description of the failure. + */ + @Override + public String toString() { + StringBuffer buffer= new StringBuffer(); + buffer.append(fFailedTest+": "+fThrownException.getMessage()); + return buffer.toString(); + } + public String trace() { + StringWriter stringWriter= new StringWriter(); + PrintWriter writer= new PrintWriter(stringWriter); + thrownException().printStackTrace(writer); + StringBuffer buffer= stringWriter.getBuffer(); + return buffer.toString(); + } + public String exceptionMessage() { + return thrownException().getMessage(); + } + public boolean isFailure() { + return thrownException() instanceof AssertionFailedError; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/TestListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/TestListener.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,23 @@ +package junit.framework; + +/** + * A Listener for test progress + */ +public interface TestListener { + /** + * An error occurred. + */ + public void addError(Test test, Throwable t); + /** + * A failure occurred. + */ + public void addFailure(Test test, AssertionFailedError t); + /** + * A test ended. + */ + public void endTest(Test test); + /** + * A test started. + */ + public void startTest(Test test); +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/TestResult.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/TestResult.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,169 @@ +package junit.framework; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; + +/** + * A TestResult collects the results of executing + * a test case. It is an instance of the Collecting Parameter pattern. + * The test framework distinguishes between failures and errors. + * A failure is anticipated and checked for with assertions. Errors are + * unanticipated problems like an {@link ArrayIndexOutOfBoundsException}. + * + * @see Test + */ +public class TestResult extends Object { + protected List fFailures; + protected List fErrors; + protected List fListeners; + protected int fRunTests; + private boolean fStop; + + public TestResult() { + fFailures= new ArrayList(); + fErrors= new ArrayList(); + fListeners= new ArrayList(); + fRunTests= 0; + fStop= false; + } + /** + * Adds an error to the list of errors. The passed in exception + * caused the error. + */ + public synchronized void addError(Test test, Throwable t) { + fErrors.add(new TestFailure(test, t)); + for (TestListener each : cloneListeners()) + each.addError(test, t); + } + /** + * Adds a failure to the list of failures. The passed in exception + * caused the failure. + */ + public synchronized void addFailure(Test test, AssertionFailedError t) { + fFailures.add(new TestFailure(test, t)); + for (TestListener each : cloneListeners()) + each.addFailure(test, t); + } + /** + * Registers a TestListener + */ + public synchronized void addListener(TestListener listener) { + fListeners.add(listener); + } + /** + * Unregisters a TestListener + */ + public synchronized void removeListener(TestListener listener) { + fListeners.remove(listener); + } + /** + * Returns a copy of the listeners. + */ + private synchronized List cloneListeners() { + List result= new ArrayList(); + result.addAll(fListeners); + return result; + } + /** + * Informs the result that a test was completed. + */ + public void endTest(Test test) { + for (TestListener each : cloneListeners()) + each.endTest(test); + } + /** + * Gets the number of detected errors. + */ + public synchronized int errorCount() { + return fErrors.size(); + } + /** + * Returns an Enumeration for the errors + */ + public synchronized Enumeration errors() { + return Collections.enumeration(fErrors); + } + + + /** + * Gets the number of detected failures. + */ + public synchronized int failureCount() { + return fFailures.size(); + } + /** + * Returns an Enumeration for the failures + */ + public synchronized Enumeration failures() { + return Collections.enumeration(fFailures); + } + + /** + * Runs a TestCase. + */ + protected void run(final TestCase test) { + startTest(test); + Protectable p= new Protectable() { + public void protect() throws Throwable { + test.runBare(); + } + }; + runProtected(test, p); + + endTest(test); + } + /** + * Gets the number of run tests. + */ + public synchronized int runCount() { + return fRunTests; + } + /** + * Runs a TestCase. + */ + public void runProtected(final Test test, Protectable p) { + try { + p.protect(); + } + catch (AssertionFailedError e) { + addFailure(test, e); + } + catch (ThreadDeath e) { // don't catch ThreadDeath by accident + throw e; + } + catch (Throwable e) { + addError(test, e); + } + } + /** + * Checks whether the test run should stop + */ + public synchronized boolean shouldStop() { + return fStop; + } + /** + * Informs the result that a test will be started. + */ + public void startTest(Test test) { + final int count= test.countTestCases(); + synchronized(this) { + fRunTests+= count; + } + for (TestListener each : cloneListeners()) + each.startTest(test); + } + /** + * Marks that the test run should stop. + */ + public synchronized void stop() { + fStop= true; + } + /** + * Returns whether the entire test was successful or not. + */ + public synchronized boolean wasSuccessful() { + return failureCount() == 0 && errorCount() == 0; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/TestSuite.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/TestSuite.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,296 @@ +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; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Vector; + +/** + *

A TestSuite is a Composite of Tests. + * It runs a collection of test cases. Here is an example using + * the dynamic test definition. + *

+ * TestSuite suite= new TestSuite();
+ * suite.addTest(new MathTest("testAdd"));
+ * suite.addTest(new MathTest("testDivideByZero"));
+ * 
+ *

+ * + *

Alternatively, a TestSuite can extract the tests to be run automatically. + * To do so you pass the class of your TestCase class to the + * TestSuite constructor. + *

+ * TestSuite suite= new TestSuite(MathTest.class);
+ * 
+ *

+ * + *

This constructor creates a suite with all the methods + * starting with "test" that take no arguments.

+ * + *

A final option is to do the same for a large array of test classes. + *

+ * Class[] testClasses = { MathTest.class, AnotherTest.class }
+ * TestSuite suite= new TestSuite(testClasses);
+ * 
+ *

+ * + * @see Test + */ +public class TestSuite implements Test { + + /** + * ...as the moon sets over the early morning Merlin, Oregon + * mountains, our intrepid adventurers type... + */ + static public Test createTest(Class theClass, String name) { + Constructor constructor; + try { + constructor= getTestConstructor(theClass); + } catch (NoSuchMethodException e) { + return warning("Class "+theClass.getName()+" has no public constructor TestCase(String name) or TestCase()"); + } + Object test; + try { + if (constructor.getParameterTypes().length == 0) { + test= constructor.newInstance(new Object[0]); + if (test instanceof TestCase) + ((TestCase) test).setName(name); + } else { + test= constructor.newInstance(new Object[]{name}); + } + } catch (InstantiationException e) { + return(warning("Cannot instantiate test case: "+name+" ("+exceptionToString(e)+")")); + } catch (InvocationTargetException e) { + return(warning("Exception in constructor: "+name+" ("+exceptionToString(e.getTargetException())+")")); + } catch (IllegalAccessException e) { + return(warning("Cannot access test case: "+name+" ("+exceptionToString(e)+")")); + } + return (Test) test; + } + + /** + * Gets a constructor which takes a single String as + * its argument or a no arg constructor. + */ + public static Constructor getTestConstructor(Class theClass) throws NoSuchMethodException { + try { + return theClass.getConstructor(String.class); + } catch (NoSuchMethodException e) { + // fall through + } + return theClass.getConstructor(new Class[0]); + } + + /** + * Returns a test which will fail and log a warning message. + */ + public static Test warning(final String message) { + return new TestCase("warning") { + @Override + protected void runTest() { + fail(message); + } + }; + } + + /** + * Converts the stack trace into a string + */ + private static String exceptionToString(Throwable t) { + StringWriter stringWriter= new StringWriter(); + PrintWriter writer= new PrintWriter(stringWriter); + t.printStackTrace(writer); + return stringWriter.toString(); + } + + private String fName; + + private Vector fTests= new Vector(10); // Cannot convert this to List because it is used directly by some test runners + + /** + * Constructs an empty TestSuite. + */ + public TestSuite() { + } + + /** + * Constructs a TestSuite from the given class. Adds all the methods + * starting with "test" as test cases to the suite. + * Parts of this method were written at 2337 meters in the Hueffihuette, + * Kanton Uri + */ + public TestSuite(final Class theClass) { + fName= theClass.getName(); + try { + getTestConstructor(theClass); // Avoid generating multiple error messages + } catch (NoSuchMethodException e) { + addTest(warning("Class "+theClass.getName()+" has no public constructor TestCase(String name) or TestCase()")); + return; + } + + if (!Modifier.isPublic(theClass.getModifiers())) { + addTest(warning("Class "+theClass.getName()+" is not public")); + return; + } + + Class superClass= theClass; + List names= new ArrayList(); + while (Test.class.isAssignableFrom(superClass)) { + for (Method each : superClass.getDeclaredMethods()) + addTestMethod(each, names, theClass); + superClass= superClass.getSuperclass(); + } + if (fTests.size() == 0) + addTest(warning("No tests found in "+theClass.getName())); + } + + /** + * Constructs a TestSuite from the given class with the given name. + * @see TestSuite#TestSuite(Class) + */ + public TestSuite(Class theClass, String name) { + this(theClass); + setName(name); + } + + /** + * Constructs an empty TestSuite. + */ + public TestSuite(String name) { + setName(name); + } + + /** + * Constructs a TestSuite from the given array of classes. + * @param classes {@link TestCase}s + */ + public TestSuite (Class... classes) { + for (Class each : classes) + addTest(new TestSuite(each.asSubclass(TestCase.class))); + } + + /** + * Constructs a TestSuite from the given array of classes with the given name. + * @see TestSuite#TestSuite(Class[]) + */ + public TestSuite(Class[] classes, String name) { + this(classes); + setName(name); + } + + /** + * Adds a test to the suite. + */ + public void addTest(Test test) { + fTests.add(test); + } + + /** + * Adds the tests from the given class to the suite + */ + public void addTestSuite(Class testClass) { + addTest(new TestSuite(testClass)); + } + + /** + * Counts the number of test cases that will be run by this test. + */ + public int countTestCases() { + int count= 0; + for (Test each : fTests) + count+= each.countTestCases(); + return count; + } + + /** + * Returns the name of the suite. Not all + * test suites have a name and this method + * can return null. + */ + public String getName() { + return fName; + } + + /** + * Runs the tests and collects their result in a TestResult. + */ + public void run(TestResult result) { + for (Test each : fTests) { + if (result.shouldStop() ) + break; + runTest(each, result); + } + } + + public void runTest(Test test, TestResult result) { + test.run(result); + } + + /** + * Sets the name of the suite. + * @param name the name to set + */ + public void setName(String name) { + fName= name; + } + + /** + * Returns the test at the given index + */ + public Test testAt(int index) { + return fTests.get(index); + } + + /** + * Returns the number of tests in this suite + */ + public int testCount() { + return fTests.size(); + } + + /** + * Returns the tests as an enumeration + */ + public Enumeration tests() { + return fTests.elements(); + } + + /** + */ + @Override + public String toString() { + if (getName() != null) + return getName(); + return super.toString(); + } + + private void addTestMethod(Method m, List names, Class theClass) { + String name= m.getName(); + if (names.contains(name)) + return; + if (! isPublicTestMethod(m)) { + if (isTestMethod(m)) + addTest(warning("Test method isn't public: "+m.getName())); + return; + } + names.add(name); + addTest(createTest(theClass, name)); + } + + private boolean isPublicTestMethod(Method m) { + return isTestMethod(m) && Modifier.isPublic(m.getModifiers()); + } + + private boolean isTestMethod(Method m) { + return + m.getParameterTypes().length == 0 && + m.getName().startsWith("test") && + m.getReturnType().equals(Void.TYPE); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/framework/package-info.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,4 @@ +/** + * Provides JUnit v3.x core classes. + */ +package junit.framework; \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/BaseTestRunner.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/BaseTestRunner.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,319 @@ +package junit.runner; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.io.StringReader; +import java.io.StringWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.text.NumberFormat; +import java.util.Properties; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestListener; +import junit.framework.TestSuite; + +/** + * Base class for all test runners. + * This class was born live on stage in Sardinia during XP2000. + */ +public abstract class BaseTestRunner implements TestListener { + public static final String SUITE_METHODNAME= "suite"; + + private static Properties fPreferences; + static int fgMaxMessageLength= 500; + static boolean fgFilterStack= true; + boolean fLoading= true; + + /* + * Implementation of TestListener + */ + public synchronized void startTest(Test test) { + testStarted(test.toString()); + } + + protected static void setPreferences(Properties preferences) { + fPreferences= preferences; + } + + protected static Properties getPreferences() { + if (fPreferences == null) { + fPreferences= new Properties(); + fPreferences.put("loading", "true"); + fPreferences.put("filterstack", "true"); + readPreferences(); + } + return fPreferences; + } + + public static void savePreferences() throws IOException { + FileOutputStream fos= new FileOutputStream(getPreferencesFile()); + try { + getPreferences().store(fos, ""); + } finally { + fos.close(); + } + } + + public static void setPreference(String key, String value) { + getPreferences().put(key, value); + } + + public synchronized void endTest(Test test) { + testEnded(test.toString()); + } + + public synchronized void addError(final Test test, final Throwable t) { + testFailed(TestRunListener.STATUS_ERROR, test, t); + } + + public synchronized void addFailure(final Test test, final AssertionFailedError t) { + testFailed(TestRunListener.STATUS_FAILURE, test, t); + } + + // TestRunListener implementation + + public abstract void testStarted(String testName); + + public abstract void testEnded(String testName); + + public abstract void testFailed(int status, Test test, Throwable t); + + /** + * Returns the Test corresponding to the given suite. This is + * a template method, subclasses override runFailed(), clearStatus(). + */ + public Test getTest(String suiteClassName) { + if (suiteClassName.length() <= 0) { + clearStatus(); + return null; + } + Class testClass= null; + try { + testClass= loadSuiteClass(suiteClassName); + } catch (ClassNotFoundException e) { + String clazz= e.getMessage(); + if (clazz == null) + clazz= suiteClassName; + runFailed("Class not found \""+clazz+"\""); + return null; + } catch(Exception e) { + runFailed("Error: "+e.toString()); + return null; + } + Method suiteMethod= null; + try { + suiteMethod= testClass.getMethod(SUITE_METHODNAME, new Class[0]); + } catch(Exception e) { + // try to extract a test suite automatically + clearStatus(); + return new TestSuite(testClass); + } + if (! Modifier.isStatic(suiteMethod.getModifiers())) { + runFailed("Suite() method must be static"); + return null; + } + Test test= null; + try { + test= (Test)suiteMethod.invoke(null, (Object[])new Class[0]); // static method + if (test == null) + return test; + } + catch (InvocationTargetException e) { + runFailed("Failed to invoke suite():" + e.getTargetException().toString()); + return null; + } + catch (IllegalAccessException e) { + runFailed("Failed to invoke suite():" + e.toString()); + return null; + } + + clearStatus(); + return test; + } + + /** + * Returns the formatted string of the elapsed time. + */ + public String elapsedTimeAsString(long runTime) { + return NumberFormat.getInstance().format((double)runTime/1000); + } + + /** + * Processes the command line arguments and + * returns the name of the suite class to run or null + */ + protected String processArguments(String[] args) { + String suiteName= null; + for (int i= 0; i < args.length; i++) { + if (args[i].equals("-noloading")) { + setLoading(false); + } else if (args[i].equals("-nofilterstack")) { + fgFilterStack= false; + } else if (args[i].equals("-c")) { + if (args.length > i+1) + suiteName= extractClassName(args[i+1]); + else + System.out.println("Missing Test class name"); + i++; + } else { + suiteName= args[i]; + } + } + return suiteName; + } + + /** + * Sets the loading behaviour of the test runner + */ + public void setLoading(boolean enable) { + fLoading= enable; + } + /** + * Extract the class name from a String in VA/Java style + */ + public String extractClassName(String className) { + if(className.startsWith("Default package for")) + return className.substring(className.lastIndexOf(".")+1); + return className; + } + + /** + * Truncates a String to the maximum length. + */ + public static String truncate(String s) { + if (fgMaxMessageLength != -1 && s.length() > fgMaxMessageLength) + s= s.substring(0, fgMaxMessageLength)+"..."; + return s; + } + + /** + * Override to define how to handle a failed loading of + * a test suite. + */ + protected abstract void runFailed(String message); + + /** + * Returns the loaded Class for a suite name. + */ + protected Class loadSuiteClass(String suiteClassName) throws ClassNotFoundException { + return Class.forName(suiteClassName).asSubclass(TestCase.class); + } + + /** + * Clears the status message. + */ + protected void clearStatus() { // Belongs in the GUI TestRunner class + } + + protected boolean useReloadingTestSuiteLoader() { + return getPreference("loading").equals("true") && fLoading; + } + + private static File getPreferencesFile() { + String home= System.getProperty("user.home"); + return new File(home, "junit.properties"); + } + + private static void readPreferences() { + InputStream is= null; + try { + is= new FileInputStream(getPreferencesFile()); + setPreferences(new Properties(getPreferences())); + getPreferences().load(is); + } catch (IOException e) { + try { + if (is != null) + is.close(); + } catch (IOException e1) { + } + } + } + + public static String getPreference(String key) { + return getPreferences().getProperty(key); + } + + public static int getPreference(String key, int dflt) { + String value= getPreference(key); + int intValue= dflt; + if (value == null) + return intValue; + try { + intValue= Integer.parseInt(value); + } catch (NumberFormatException ne) { + } + return intValue; + } + + /** + * Returns a filtered stack trace + */ + public static String getFilteredTrace(Throwable t) { + StringWriter stringWriter= new StringWriter(); + PrintWriter writer= new PrintWriter(stringWriter); + t.printStackTrace(writer); + StringBuffer buffer= stringWriter.getBuffer(); + String trace= buffer.toString(); + return BaseTestRunner.getFilteredTrace(trace); + } + + /** + * Filters stack frames from internal JUnit classes + */ + public static String getFilteredTrace(String stack) { + if (showStackRaw()) + return stack; + + StringWriter sw= new StringWriter(); + PrintWriter pw= new PrintWriter(sw); + StringReader sr= new StringReader(stack); + BufferedReader br= new BufferedReader(sr); + + String line; + try { + while ((line= br.readLine()) != null) { + if (!filterLine(line)) + pw.println(line); + } + } catch (Exception IOException) { + return stack; // return the stack unfiltered + } + return sw.toString(); + } + + protected static boolean showStackRaw() { + return !getPreference("filterstack").equals("true") || fgFilterStack == false; + } + + static boolean filterLine(String line) { + String[] patterns= new String[] { + "junit.framework.TestCase", + "junit.framework.TestResult", + "junit.framework.TestSuite", + "junit.framework.Assert.", // don't filter AssertionFailure + "junit.swingui.TestRunner", + "junit.awtui.TestRunner", + "junit.textui.TestRunner", + "java.lang.reflect.Method.invoke(" + }; + for (int i= 0; i < patterns.length; i++) { + if (line.indexOf(patterns[i]) > 0) + return true; + } + return false; + } + + static { + fgMaxMessageLength= getPreference("maxmessage", fgMaxMessageLength); + } + +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/TestRunListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/TestRunListener.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,19 @@ +package junit.runner; +/** + * A listener interface for observing the + * execution of a test run. Unlike TestListener, + * this interface using only primitive objects, + * making it suitable for remote test execution. + */ + public interface TestRunListener { + /* test status constants*/ + public static final int STATUS_ERROR= 1; + public static final int STATUS_FAILURE= 2; + + public void testRunStarted(String testSuiteName, int testCount); + public void testRunEnded(long elapsedTime); + public void testRunStopped(long elapsedTime); + public void testStarted(String testName); + public void testEnded(String testName); + public void testFailed(int status, String testName, String trace); +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/Version.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/Version.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,18 @@ +package junit.runner; + +/** + * This class defines the current version of JUnit + */ +public class Version { + private Version() { + // don't instantiate + } + + public static String id() { + return "4.5"; + } + + public static void main(String[] args) { + System.out.println(id()); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/Version.java.template --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/Version.java.template Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,18 @@ +package junit.runner; + +/** + * This class defines the current version of JUnit + */ +public class Version { + private Version() { + // don't instantiate + } + + public static String id() { + return "@version@"; + } + + public static void main(String[] args) { + System.out.println(id()); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/logo.gif Binary file carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/logo.gif has changed diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/package-info.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,4 @@ +/** + * Provides JUnit v3.x test runners. + */ +package junit.runner; \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/smalllogo.gif Binary file carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/runner/smalllogo.gif has changed diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/textui/ResultPrinter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/textui/ResultPrinter.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,139 @@ + +package junit.textui; + +import java.io.PrintStream; +import java.text.NumberFormat; +import java.util.Enumeration; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; +import junit.framework.TestFailure; +import junit.framework.TestListener; +import junit.framework.TestResult; +import junit.runner.BaseTestRunner; + +public class ResultPrinter implements TestListener { + PrintStream fWriter; + int fColumn= 0; + + public ResultPrinter(PrintStream writer) { + fWriter= writer; + } + + /* API for use by textui.TestRunner + */ + + synchronized void print(TestResult result, long runTime) { + printHeader(runTime); + printErrors(result); + printFailures(result); + printFooter(result); + } + + void printWaitPrompt() { + getWriter().println(); + getWriter().println(" to continue"); + } + + /* Internal methods + */ + + protected void printHeader(long runTime) { + getWriter().println(); + getWriter().println("Time: "+elapsedTimeAsString(runTime)); + } + + protected void printErrors(TestResult result) { + printDefects(result.errors(), result.errorCount(), "error"); + } + + protected void printFailures(TestResult result) { + printDefects(result.failures(), result.failureCount(), "failure"); + } + + protected void printDefects(Enumeration booBoos, int count, String type) { + if (count == 0) return; + if (count == 1) + getWriter().println("There was " + count + " " + type + ":"); + else + getWriter().println("There were " + count + " " + type + "s:"); + for (int i= 1; booBoos.hasMoreElements(); i++) { + printDefect(booBoos.nextElement(), i); + } + } + + public void printDefect(TestFailure booBoo, int count) { // only public for testing purposes + printDefectHeader(booBoo, count); + printDefectTrace(booBoo); + } + + protected void printDefectHeader(TestFailure booBoo, int count) { + // I feel like making this a println, then adding a line giving the throwable a chance to print something + // before we get to the stack trace. + getWriter().print(count + ") " + booBoo.failedTest()); + } + + protected void printDefectTrace(TestFailure booBoo) { + getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace())); + } + + protected void printFooter(TestResult result) { + if (result.wasSuccessful()) { + getWriter().println(); + getWriter().print("OK"); + getWriter().println (" (" + result.runCount() + " test" + (result.runCount() == 1 ? "": "s") + ")"); + + } else { + getWriter().println(); + getWriter().println("FAILURES!!!"); + getWriter().println("Tests run: "+result.runCount()+ + ", Failures: "+result.failureCount()+ + ", Errors: "+result.errorCount()); + } + getWriter().println(); + } + + + /** + * Returns the formatted string of the elapsed time. + * Duplicated from BaseTestRunner. Fix it. + */ + protected String elapsedTimeAsString(long runTime) { + return NumberFormat.getInstance().format((double)runTime/1000); + } + + public PrintStream getWriter() { + return fWriter; + } + /** + * @see junit.framework.TestListener#addError(Test, Throwable) + */ + public void addError(Test test, Throwable t) { + getWriter().print("E"); + } + + /** + * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError) + */ + public void addFailure(Test test, AssertionFailedError t) { + getWriter().print("F"); + } + + /** + * @see junit.framework.TestListener#endTest(Test) + */ + public void endTest(Test test) { + } + + /** + * @see junit.framework.TestListener#startTest(Test) + */ + public void startTest(Test test) { + getWriter().print("."); + if (fColumn++ >= 40) { + getWriter().println(); + fColumn= 0; + } + } + +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/textui/TestRunner.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/textui/TestRunner.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,203 @@ +package junit.textui; + + +import java.io.PrintStream; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestResult; +import junit.framework.TestSuite; +import junit.runner.BaseTestRunner; +import junit.runner.Version; + +/** + * A command line based tool to run tests. + *
+ * java junit.textui.TestRunner [-wait] TestCaseClass
+ * 
+ * + *

TestRunner expects the name of a TestCase class as argument. + * If this class defines a static suite method it + * will be invoked and the returned test is run. Otherwise all + * the methods starting with "test" having no arguments are run.

+ * + *

When the wait command line argument is given TestRunner + * waits until the users types RETURN.

+ * + *

TestRunner prints a trace as the tests are executed followed by a + * summary at the end.

+ */ +public class TestRunner extends BaseTestRunner { + private ResultPrinter fPrinter; + + public static final int SUCCESS_EXIT= 0; + public static final int FAILURE_EXIT= 1; + public static final int EXCEPTION_EXIT= 2; + + /** + * Constructs a TestRunner. + */ + public TestRunner() { + this(System.out); + } + + /** + * Constructs a TestRunner using the given stream for all the output + */ + public TestRunner(PrintStream writer) { + this(new ResultPrinter(writer)); + } + + /** + * Constructs a TestRunner using the given ResultPrinter all the output + */ + public TestRunner(ResultPrinter printer) { + fPrinter= printer; + } + + /** + * Runs a suite extracted from a TestCase subclass. + */ + static public void run(Class testClass) { + run(new TestSuite(testClass)); + } + + /** + * Runs a single test and collects its results. + * This method can be used to start a test run + * from your program. + *
+	 * public static void main (String[] args) {
+	 *    test.textui.TestRunner.run(suite());
+	 * }
+	 * 
+ */ + static public TestResult run(Test test) { + TestRunner runner= new TestRunner(); + return runner.doRun(test); + } + + /** + * Runs a single test and waits until the user + * types RETURN. + */ + static public void runAndWait(Test suite) { + TestRunner aTestRunner= new TestRunner(); + aTestRunner.doRun(suite, true); + } + + @Override + public void testFailed(int status, Test test, Throwable t) { + } + + @Override + public void testStarted(String testName) { + } + + @Override + public void testEnded(String testName) { + } + + /** + * Creates the TestResult to be used for the test run. + */ + protected TestResult createTestResult() { + return new TestResult(); + } + + public TestResult doRun(Test test) { + return doRun(test, false); + } + + public TestResult doRun(Test suite, boolean wait) { + TestResult result= createTestResult(); + result.addListener(fPrinter); + long startTime= System.currentTimeMillis(); + suite.run(result); + long endTime= System.currentTimeMillis(); + long runTime= endTime-startTime; + fPrinter.print(result, runTime); + + pause(wait); + return result; + } + + protected void pause(boolean wait) { + if (!wait) return; + fPrinter.printWaitPrompt(); + try { + System.in.read(); + } + catch(Exception e) { + } + } + + public static void main(String args[]) { + TestRunner aTestRunner= new TestRunner(); + try { + TestResult r= aTestRunner.start(args); + if (!r.wasSuccessful()) + System.exit(FAILURE_EXIT); + System.exit(SUCCESS_EXIT); + } catch(Exception e) { + System.err.println(e.getMessage()); + System.exit(EXCEPTION_EXIT); + } + } + + /** + * Starts a test run. Analyzes the command line arguments and runs the given + * test suite. + */ + public TestResult start(String args[]) throws Exception { + String testCase= ""; + String method= ""; + boolean wait= false; + + for (int i= 0; i < args.length; i++) { + if (args[i].equals("-wait")) + wait= true; + else if (args[i].equals("-c")) + testCase= extractClassName(args[++i]); + else if (args[i].equals("-m")) { + String arg= args[++i]; + int lastIndex= arg.lastIndexOf('.'); + testCase= arg.substring(0, lastIndex); + method= arg.substring(lastIndex + 1); + } else if (args[i].equals("-v")) + System.err.println("JUnit " + Version.id() + " by Kent Beck and Erich Gamma"); + else + testCase= args[i]; + } + + if (testCase.equals("")) + throw new Exception("Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class"); + + try { + if (!method.equals("")) + return runSingleMethod(testCase, method, wait); + Test suite= getTest(testCase); + return doRun(suite, wait); + } catch (Exception e) { + throw new Exception("Could not create and run test suite: " + e); + } + } + + protected TestResult runSingleMethod(String testCase, String method, boolean wait) throws Exception { + Class testClass= loadSuiteClass(testCase); + Test test= TestSuite.createTest(testClass, method); + return doRun(test, wait); + } + + @Override + protected void runFailed(String message) { + System.err.println(message); + System.exit(FAILURE_EXIT); + } + + public void setPrinter(ResultPrinter printer) { + fPrinter= printer; + } + + +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/textui/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/junit/textui/package-info.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,4 @@ +/** + * Provides JUnit v3.x command line based tool to run tests. + */ +package junit.textui; \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/After.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/After.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,40 @@ +package org.junit; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + *

If you allocate external resources in a {@link org.junit.Before} method you need to release them + * after the test runs. Annotating a public void method + * with @After causes that method to be run after the {@link org.junit.Test} method. All @After + * methods are guaranteed to run even if a {@link org.junit.Before} or {@link org.junit.Test} method throws an + * exception. The @After methods declared in superclasses will be run after those of the current + * class.

+ * + * Here is a simple example: +*
+ * public class Example {
+ *    File output;
+ *    @Before public void createOutputFile() {
+ *          output= new File(...);
+ *    }
+ *    @Test public void something() {
+ *          ...
+ *    }
+ *    @After public void deleteOutputFile() {
+ *          output.delete();
+ *    }
+ * }
+ * 
+ * + * @see org.junit.Before + * @see org.junit.Test + */ + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface After { +} + diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/AfterClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/AfterClass.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,41 @@ +package org.junit; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + *

If you allocate expensive external resources in a {@link org.junit.BeforeClass} method you need to release them + * after all the tests in the class have run. Annotating a public static void method + * with @AfterClass causes that method to be run after all the tests in the class have been run. All @AfterClass + * methods are guaranteed to run even if a {@link org.junit.BeforeClass} method throws an + * exception. The @AfterClass methods declared in superclasses will be run after those of the current + * class.

+ * + * Here is a simple example: +*
+ * public class Example {
+ *    DatabaseConnection database;
+ *    @BeforeClass public static void login() {
+ *          database= ...;
+ *    }
+ *    @Test public void something() {
+ *          ...
+ *    }
+ *    @Test public void somethingElse() {
+ *          ...
+ *    }
+ *    @AfterClass public static void logout() {
+ *          database.logout();
+ *    }
+ * }
+ * 
+ * + * @see org.junit.BeforeClass + * @see org.junit.Test + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface AfterClass { +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/Assert.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/Assert.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,753 @@ +package org.junit; + +import java.lang.reflect.Array; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.StringDescription; +import org.junit.internal.ArrayComparisonFailure; + +/** + * A set of assertion methods useful for writing tests. Only failed assertions + * are recorded. These methods can be used directly: + * Assert.assertEquals(...), however, they read better if they + * are referenced through static import:
+ * + *
+ * import static org.junit.Assert.*;
+ *    ...
+ *    assertEquals(...);
+ * 
+ * + * @see AssertionError + */ +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 + * {@link AssertionError} with the given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param condition + * condition to be checked + */ + static public void assertTrue(String message, boolean condition) { + if (!condition) + fail(message); + } + + /** + * Asserts that a condition is true. If it isn't it throws an + * {@link AssertionError} without a message. + * + * @param condition + * condition to be checked + */ + static public void assertTrue(boolean condition) { + assertTrue(null, condition); + } + + /** + * Asserts that a condition is false. If it isn't it throws an + * {@link AssertionError} with the given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param condition + * condition to be checked + */ + static public void assertFalse(String message, boolean condition) { + assertTrue(message, !condition); + } + + /** + * Asserts that a condition is false. If it isn't it throws an + * {@link AssertionError} without a message. + * + * @param condition + * condition to be checked + */ + static public void assertFalse(boolean condition) { + assertFalse(null, condition); + } + + /** + * Fails a test with the given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @see AssertionError + */ + static public void fail(String message) { + throw new AssertionError(message == null ? "" : message); + } + + /** + * Fails a test with no message. + */ + static public void fail() { + fail(null); + } + + /** + * Asserts that two objects are equal. If they are not, an + * {@link AssertionError} is thrown with the given message. If + * expected and actual are null, + * they are considered equal. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param expected + * expected value + * @param actual + * actual value + */ + static public void assertEquals(String message, Object expected, + Object actual) { + if (expected == null && actual == null) + return; + if (expected != null && isEquals(expected, actual)) + return; + else if (expected instanceof String && actual instanceof String) { + String cleanMessage= message == null ? "" : message; + throw new ComparisonFailure(cleanMessage, (String) expected, + (String) actual); + } else + failNotEquals(message, expected, actual); + } + + private static boolean isEquals(Object expected, Object actual) { + return expected.equals(actual); + } + + /** + * Asserts that two objects are equal. If they are not, an + * {@link AssertionError} without a message is thrown. If + * expected and actual are null, + * they are considered equal. + * + * @param expected + * expected value + * @param actual + * the value to check against expected + */ + static public void assertEquals(Object expected, Object actual) { + assertEquals(null, expected, actual); + } + + /** + * Asserts that two object arrays are equal. If they are not, an + * {@link AssertionError} is thrown with the given message. If + * expecteds and actuals are null, + * they are considered equal. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param expecteds + * Object array or array of arrays (multi-dimensional array) with + * expected values. + * @param actuals + * Object array or array of arrays (multi-dimensional array) with + * actual values + */ + public static void assertArrayEquals(String message, Object[] expecteds, + Object[] actuals) throws ArrayComparisonFailure { + internalArrayEquals(message, expecteds, actuals); + } + + /** + * Asserts that two object arrays are equal. If they are not, an + * {@link AssertionError} is thrown. If expected and + * actual are null, they are considered + * equal. + * + * @param expecteds + * Object array or array of arrays (multi-dimensional array) with + * expected values + * @param actuals + * Object array or array of arrays (multi-dimensional array) with + * actual values + */ + public static void assertArrayEquals(Object[] expecteds, Object[] actuals) { + assertArrayEquals(null, expecteds, actuals); + } + + /** + * Asserts that two byte arrays are equal. If they are not, an + * {@link AssertionError} is thrown with the given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param expecteds + * byte array with expected values. + * @param actuals + * byte array with actual values + */ + public static void assertArrayEquals(String message, byte[] expecteds, + byte[] actuals) throws ArrayComparisonFailure { + internalArrayEquals(message, expecteds, actuals); + } + + /** + * Asserts that two byte arrays are equal. If they are not, an + * {@link AssertionError} is thrown. + * + * @param expecteds + * byte array with expected values. + * @param actuals + * byte array with actual values + */ + public static void assertArrayEquals(byte[] expecteds, byte[] actuals) { + assertArrayEquals(null, expecteds, actuals); + } + + /** + * Asserts that two char arrays are equal. If they are not, an + * {@link AssertionError} is thrown with the given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param expecteds + * char array with expected values. + * @param actuals + * char array with actual values + */ + public static void assertArrayEquals(String message, char[] expecteds, + char[] actuals) throws ArrayComparisonFailure { + internalArrayEquals(message, expecteds, actuals); + } + + /** + * Asserts that two char arrays are equal. If they are not, an + * {@link AssertionError} is thrown. + * + * @param expecteds + * char array with expected values. + * @param actuals + * char array with actual values + */ + public static void assertArrayEquals(char[] expecteds, char[] actuals) { + assertArrayEquals(null, expecteds, actuals); + } + + /** + * Asserts that two short arrays are equal. If they are not, an + * {@link AssertionError} is thrown with the given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param expecteds + * short array with expected values. + * @param actuals + * short array with actual values + */ + public static void assertArrayEquals(String message, short[] expecteds, + short[] actuals) throws ArrayComparisonFailure { + internalArrayEquals(message, expecteds, actuals); + } + + /** + * Asserts that two short arrays are equal. If they are not, an + * {@link AssertionError} is thrown. + * + * @param expecteds + * short array with expected values. + * @param actuals + * short array with actual values + */ + public static void assertArrayEquals(short[] expecteds, short[] actuals) { + assertArrayEquals(null, expecteds, actuals); + } + + /** + * Asserts that two int arrays are equal. If they are not, an + * {@link AssertionError} is thrown with the given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param expecteds + * int array with expected values. + * @param actuals + * int array with actual values + */ + public static void assertArrayEquals(String message, int[] expecteds, + int[] actuals) throws ArrayComparisonFailure { + internalArrayEquals(message, expecteds, actuals); + } + + /** + * Asserts that two int arrays are equal. If they are not, an + * {@link AssertionError} is thrown. + * + * @param expecteds + * int array with expected values. + * @param actuals + * int array with actual values + */ + public static void assertArrayEquals(int[] expecteds, int[] actuals) { + assertArrayEquals(null, expecteds, actuals); + } + + /** + * Asserts that two long arrays are equal. If they are not, an + * {@link AssertionError} is thrown with the given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param expecteds + * long array with expected values. + * @param actuals + * long array with actual values + */ + public static void assertArrayEquals(String message, long[] expecteds, + long[] actuals) throws ArrayComparisonFailure { + internalArrayEquals(message, expecteds, actuals); + } + + /** + * Asserts that two long arrays are equal. If they are not, an + * {@link AssertionError} is thrown. + * + * @param expecteds + * long array with expected values. + * @param actuals + * long array with actual values + */ + public static void assertArrayEquals(long[] expecteds, long[] actuals) { + assertArrayEquals(null, expecteds, actuals); + } + + /** + * Asserts that two object arrays are equal. If they are not, an + * {@link AssertionError} is thrown with the given message. If + * expecteds and actuals are null, + * they are considered equal. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param expecteds + * Object array or array of arrays (multi-dimensional array) with + * expected values. + * @param actuals + * Object array or array of arrays (multi-dimensional array) with + * actual values + */ + private static void internalArrayEquals(String message, Object expecteds, + Object actuals) throws ArrayComparisonFailure { + if (expecteds == actuals) + return; + String header= message == null ? "" : message + ": "; + if (expecteds == null) + fail(header + "expected array was null"); + if (actuals == null) + fail(header + "actual array was null"); + int actualsLength= Array.getLength(actuals); + int expectedsLength= Array.getLength(expecteds); + if (actualsLength != expectedsLength) + fail(header + "array lengths differed, expected.length=" + + expectedsLength + " actual.length=" + actualsLength); + + for (int i= 0; i < expectedsLength; i++) { + Object expected= Array.get(expecteds, i); + Object actual= Array.get(actuals, i); + if (isArray(expected) && isArray(actual)) { + try { + internalArrayEquals(message, expected, actual); + } catch (ArrayComparisonFailure e) { + e.addDimension(i); + throw e; + } + } else + try { + assertEquals(expected, actual); + } catch (AssertionError e) { + throw new ArrayComparisonFailure(header, e, i); + } + } + } + + private static boolean isArray(Object expected) { + return expected != null && expected.getClass().isArray(); + } + + /** + * Asserts that two doubles or floats are equal to within a positive delta. + * If they are not, an {@link AssertionError} is thrown with the given + * message. If the expected value is infinity then the delta value is + * ignored. NaNs are considered equal: + * assertEquals(Double.NaN, Double.NaN, *) passes + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param expected + * expected value + * @param actual + * the value to check against expected + * @param delta + * the maximum delta between expected and + * actual for which both numbers are still + * considered equal. + */ + static public 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)); + } + + /** + * Asserts that two longs are equal. If they are not, an + * {@link AssertionError} is thrown. + * + * @param expected + * expected long value. + * @param actual + * actual long value + */ + static public void assertEquals(long expected, long actual) { + assertEquals(null, expected, actual); + } + + /** + * Asserts that two longs are equal. If they are not, an + * {@link AssertionError} is thrown with the given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param expected + * long expected value. + * @param actual + * long actual value + */ + static public void assertEquals(String message, long expected, long actual) { + assertEquals(message, (Long) expected, (Long) actual); + } + + /** + * @deprecated Use + * assertEquals(double expected, double actual, double epsilon) + * instead + */ + @Deprecated + static public void assertEquals(double expected, double actual) { + assertEquals(null, expected, actual); + } + + /** + * @deprecated Use + * assertEquals(String message, double expected, double actual, double epsilon) + * instead + */ + @Deprecated + static public void assertEquals(String message, double expected, + double actual) { + fail("Use assertEquals(expected, actual, delta) to compare floating-point numbers"); + } + + /** + * Asserts that two doubles or floats are equal to within a positive delta. + * If they are not, an {@link AssertionError} is thrown. If the expected + * value is infinity then the delta value is ignored.NaNs are considered + * equal: assertEquals(Double.NaN, Double.NaN, *) passes + * + * @param expected + * expected value + * @param actual + * the value to check against expected + * @param delta + * the maximum delta between expected and + * actual for which both numbers are still + * considered equal. + */ + static public void assertEquals(double expected, double actual, double delta) { + assertEquals(null, expected, actual, delta); + } + + /** + * Asserts that an object isn't null. If it is an {@link AssertionError} is + * thrown with the given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param object + * Object to check or null + */ + static public void assertNotNull(String message, Object object) { + assertTrue(message, object != null); + } + + /** + * Asserts that an object isn't null. If it is an {@link AssertionError} is + * thrown. + * + * @param object + * Object to check or null + */ + static public void assertNotNull(Object object) { + assertNotNull(null, object); + } + + /** + * Asserts that an object is null. If it is not, an {@link AssertionError} + * is thrown with the given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param object + * Object to check or null + */ + static public void assertNull(String message, Object object) { + assertTrue(message, object == null); + } + + /** + * Asserts that an object is null. If it isn't an {@link AssertionError} is + * thrown. + * + * @param object + * Object to check or null + */ + static public void assertNull(Object object) { + assertNull(null, object); + } + + /** + * Asserts that two objects refer to the same object. If they are not, an + * {@link AssertionError} is thrown with the given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param expected + * the expected object + * @param actual + * the object to compare to expected + */ + static public void assertSame(String message, Object expected, Object actual) { + if (expected == actual) + return; + failNotSame(message, expected, actual); + } + + /** + * Asserts that two objects refer to the same object. If they are not the + * same, an {@link AssertionError} without a message is thrown. + * + * @param expected + * the expected object + * @param actual + * the object to compare to expected + */ + static public void assertSame(Object expected, Object actual) { + assertSame(null, expected, actual); + } + + /** + * Asserts that two objects do not refer to the same object. If they do + * refer to the same object, an {@link AssertionError} is thrown with the + * given message. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param unexpected + * the object you don't expect + * @param actual + * the object to compare to unexpected + */ + static public void assertNotSame(String message, Object unexpected, + Object actual) { + if (unexpected == actual) + failSame(message); + } + + /** + * Asserts that two objects do not refer to the same object. If they do + * refer to the same object, an {@link AssertionError} without a message is + * thrown. + * + * @param unexpected + * the object you don't expect + * @param actual + * the object to compare to unexpected + */ + static public void assertNotSame(Object unexpected, Object actual) { + assertNotSame(null, unexpected, actual); + } + + static private void failSame(String message) { + String formatted= ""; + if (message != null) + formatted= message + " "; + fail(formatted + "expected not same"); + } + + static private void failNotSame(String message, Object expected, + Object actual) { + String formatted= ""; + if (message != null) + formatted= message + " "; + fail(formatted + "expected same:<" + expected + "> was not:<" + actual + + ">"); + } + + static private void failNotEquals(String message, Object expected, + Object actual) { + fail(format(message, expected, actual)); + } + + static String format(String message, Object expected, Object actual) { + String formatted= ""; + if (message != null && !message.equals("")) + formatted= message + " "; + String expectedString= String.valueOf(expected); + String actualString= String.valueOf(actual); + if (expectedString.equals(actualString)) + return formatted + "expected: " + + formatClassAndValue(expected, expectedString) + + " but was: " + formatClassAndValue(actual, actualString); + else + return formatted + "expected:<" + expectedString + "> but was:<" + + actualString + ">"; + } + + private static String formatClassAndValue(Object value, String valueString) { + String className= value == null ? "null" : value.getClass().getName(); + return className + "<" + valueString + ">"; + } + + /** + * Asserts that two object arrays are equal. If they are not, an + * {@link AssertionError} is thrown with the given message. If + * expecteds and actuals are null, + * they are considered equal. + * + * @param message + * the identifying message for the {@link AssertionError} (null + * okay) + * @param expecteds + * Object array or array of arrays (multi-dimensional array) with + * expected values. + * @param actuals + * Object array or array of arrays (multi-dimensional array) with + * actual values + * @deprecated use assertArrayEquals + */ + @Deprecated + public static void assertEquals(String message, Object[] expecteds, + Object[] actuals) { + assertArrayEquals(message, expecteds, actuals); + } + + /** + * Asserts that two object arrays are equal. If they are not, an + * {@link AssertionError} is thrown. If expected and + * actual are null, they are considered + * equal. + * + * @param expecteds + * Object array or array of arrays (multi-dimensional array) with + * expected values + * @param actuals + * Object array or array of arrays (multi-dimensional array) with + * actual values + * @deprecated use assertArrayEquals + */ + @Deprecated + public static void assertEquals(Object[] expecteds, Object[] actuals) { + assertArrayEquals(expecteds, actuals); + } + + /** + * Asserts that actual satisfies the condition specified by + * matcher. If not, an {@link AssertionError} is thrown with + * information about the matcher and failing value. Example: + * + *
+	 *   assertThat(0, is(1)); // fails:
+	 *     // failure message:
+	 *     // expected: is <1> 
+	 *     // got value: <0>
+	 *   assertThat(0, is(not(1))) // passes
+	 * 
+ * + * @param + * the static type accepted by the matcher (this can flag obvious + * compile-time problems such as {@code assertThat(1, is("a"))} + * @param actual + * the computed value being compared + * @param matcher + * an expression, built of {@link Matcher}s, specifying allowed + * values + * + * @see org.hamcrest.CoreMatchers + * @see org.junit.matchers.JUnitMatchers + */ + public static void assertThat(T actual, Matcher matcher) { + assertThat("", actual, matcher); + } + + /** + * Asserts that actual satisfies the condition specified by + * matcher. If not, an {@link AssertionError} is thrown with + * the reason and information about the matcher and failing value. Example: + * + *
+	 * :
+	 *   assertThat("Help! Integers don't work", 0, is(1)); // fails:
+	 *     // failure message:
+	 *     // Help! Integers don't work
+	 *     // expected: is <1> 
+	 *     // got value: <0>
+	 *   assertThat("Zero is one", 0, is(not(1))) // passes
+	 * 
+ * + * @param reason + * additional information about the error + * @param + * the static type accepted by the matcher (this can flag obvious + * compile-time problems such as {@code assertThat(1, is("a"))} + * @param actual + * the computed value being compared + * @param matcher + * an expression, built of {@link Matcher}s, specifying allowed + * values + * + * @see org.hamcrest.CoreMatchers + * @see org.junit.matchers.JUnitMatchers + */ + public static void assertThat(String reason, T actual, + Matcher matcher) { + if (!matcher.matches(actual)) { + Description description= new StringDescription(); + description.appendText(reason); + description.appendText("\nExpected: "); + matcher.describeTo(description); + description.appendText("\n got: ").appendValue(actual) + .appendText("\n"); + throw new java.lang.AssertionError(description.toString()); + } + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/Assume.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/Assume.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,94 @@ +package org.junit; + +import static java.util.Arrays.asList; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import org.hamcrest.Matcher; +import org.junit.internal.AssumptionViolatedException; +import org.junit.internal.matchers.Each; + +/** + * A set of methods useful for stating assumptions about the conditions in which a test is meaningful. + * A failed assumption does not mean the code is broken, but that the test provides no useful information. + * The default JUnit runner treats tests with failing assumptions as ignored. Custom runners may behave differently. + * + * For example: + *
+ * // only provides information if database is reachable.
+ * \@Test public void calculateTotalSalary() {
+ *    DBConnection dbc = Database.connect();
+ *    assumeNotNull(dbc);
+ *    // ...
+ * }
+ * 
+ * These methods can be used directly: Assume.assumeTrue(...), however, they + * read better if they are referenced through static import:
+ *
+ * import static org.junit.Assume.*;
+ *    ...
+ *    assumeTrue(...);
+ * 
+ */ +public class Assume { + /** + * If called with an expression evaluating to {@code false}, the test will halt and be ignored. + * @param b + */ + public static void assumeTrue(boolean b) { + assumeThat(b, is(true)); + } + + /** + * If called with one or more null elements in objects, the test will halt and be ignored. + * @param objects + */ + public static void assumeNotNull(Object... objects) { + assumeThat(asList(objects), Each.each(notNullValue())); + } + + /** + * Call to assume that actual satisfies the condition specified by matcher. + * If not, the test halts and is ignored. + * Example: + *
:
+	     *   assumeThat(1, is(1)); // passes
+	     *   foo(); // will execute
+	     *   assumeThat(0, is(1)); // assumption failure! test halts
+	     *   int x = 1 / 0; // will never execute
+	     * 
+ * + * @param the static type accepted by the matcher (this can flag obvious compile-time problems such as {@code assumeThat(1, is("a"))} + * @param actual the computed value being compared + * @param matcher an expression, built of {@link Matcher}s, specifying allowed values + * + * @see org.hamcrest.CoreMatchers + * @see org.junit.matchers.JUnitMatchers + */ + public static void assumeThat(T actual, Matcher matcher) { + if (!matcher.matches(actual)) + throw new AssumptionViolatedException(actual, matcher); + } + + /** + * Use to assume that an operation completes normally. If {@code t} is non-null, the test will halt and be ignored. + * + * For example: + *
+	 * \@Test public void parseDataFile() {
+	 *   DataFile file;
+	 *   try {
+	 *     file = DataFile.open("sampledata.txt");
+	 *   } catch (IOException e) {
+	 *     // stop test and ignore if data can't be opened
+	 *     assumeNoException(e);
+	 *   }
+	 *   // ...
+	 * }
+	 * 
+ * @param t if non-null, the offending exception + */ + public static void assumeNoException(Throwable t) { + assumeThat(t, nullValue()); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/Before.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/Before.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,37 @@ +package org.junit; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + *

When writing tests, it is common to find that several tests need similar + * objects created before they can run. Annotating a public void method + * with @Before causes that method to be run before the {@link org.junit.Test} method. + * The @Before methods of superclasses will be run before those of the current class.

+ * + * Here is a simple example: + *
+ * public class Example {
+ *    List empty;
+ *    @Before public void initialize() {
+ *       empty= new ArrayList();
+ *    }
+ *    @Test public void size() {
+ *       ...
+ *    }
+ *    @Test public void remove() {
+ *       ...
+ *    }
+ * }
+ * 
+ * + * @see org.junit.BeforeClass + * @see org.junit.After + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Before { +} + diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/BeforeClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/BeforeClass.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,35 @@ +package org.junit; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + *

Sometimes several tests need to share computationally expensive setup + * (like logging into a database). While this can compromise the independence of + * tests, sometimes it is a necessary optimization. Annotating a public static void no-arg method + * with @BeforeClass causes it to be run once before any of + * the test methods in the class. The @BeforeClass methods of superclasses + * will be run before those the current class.

+ * + * For example: + *
+ * public class Example {
+ *    @BeforeClass public static void onlyOnce() {
+ *       ...
+ *    }
+ *    @Test public void one() {
+ *       ...
+ *    }
+ *    @Test public void two() {
+ *       ...
+ *    }
+ * }
+ * 
+ * @see org.junit.AfterClass + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface BeforeClass { +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/ComparisonFailure.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/ComparisonFailure.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,138 @@ +package org.junit; + +/** + * Thrown when an {@link org.junit.Assert#assertEquals(Object, Object) assertEquals(String, String)} fails. Create and throw + * a ComparisonFailure manually if you want to show users the difference between two complex + * strings. + * + * Inspired by a patch from Alex Chaffee (alex@purpletech.com) + */ +public class ComparisonFailure extends AssertionError { + /** + * The maximum length for fExpected and fActual. If it is exceeded, the strings should be shortened. + * @see ComparisonCompactor + */ + private static final int MAX_CONTEXT_LENGTH= 20; + private static final long serialVersionUID= 1L; + + private String fExpected; + private String fActual; + + /** + * Constructs a comparison failure. + * @param message the identifying message or null + * @param expected the expected string value + * @param actual the actual string value + */ + public ComparisonFailure (String message, String expected, String actual) { + super (message); + fExpected= expected; + fActual= actual; + } + + /** + * Returns "..." in place of common prefix and "..." in + * place of common suffix between expected and actual. + * + * @see Throwable#getMessage() + */ + @Override + public String getMessage() { + return new ComparisonCompactor(MAX_CONTEXT_LENGTH, fExpected, fActual).compact(super.getMessage()); + } + + /** + * Returns the actual string value + * @return the actual string value + */ + public String getActual() { + return fActual; + } + /** + * Returns the expected string value + * @return the expected string value + */ + public String getExpected() { + return fExpected; + } + + private static class ComparisonCompactor { + private static final String ELLIPSIS= "..."; + private static final String DELTA_END= "]"; + private static final String DELTA_START= "["; + + /** + * The maximum length for expected and actual. When contextLength + * is exceeded, the Strings are shortened + */ + private int fContextLength; + private String fExpected; + private String fActual; + private int fPrefix; + private int fSuffix; + + /** + * @param contextLength the maximum length for expected and actual. When contextLength + * is exceeded, the Strings are shortened + * @param expected the expected string value + * @param actual the actual string value + */ + public ComparisonCompactor(int contextLength, String expected, String actual) { + fContextLength= contextLength; + fExpected= expected; + fActual= actual; + } + + private String compact(String message) { + if (fExpected == null || fActual == null || areStringsEqual()) + return Assert.format(message, fExpected, fActual); + + findCommonPrefix(); + findCommonSuffix(); + String expected= compactString(fExpected); + String actual= compactString(fActual); + return Assert.format(message, expected, actual); + } + + private String compactString(String source) { + String result= DELTA_START + source.substring(fPrefix, source.length() - fSuffix + 1) + DELTA_END; + if (fPrefix > 0) + result= computeCommonPrefix() + result; + if (fSuffix > 0) + result= result + computeCommonSuffix(); + return result; + } + + private void findCommonPrefix() { + fPrefix= 0; + int end= Math.min(fExpected.length(), fActual.length()); + for (; fPrefix < end; fPrefix++) { + if (fExpected.charAt(fPrefix) != fActual.charAt(fPrefix)) + break; + } + } + + private void findCommonSuffix() { + int expectedSuffix= fExpected.length() - 1; + int actualSuffix= fActual.length() - 1; + for (; actualSuffix >= fPrefix && expectedSuffix >= fPrefix; actualSuffix--, expectedSuffix--) { + if (fExpected.charAt(expectedSuffix) != fActual.charAt(actualSuffix)) + break; + } + fSuffix= fExpected.length() - expectedSuffix; + } + + private String computeCommonPrefix() { + return (fPrefix > fContextLength ? ELLIPSIS : "") + fExpected.substring(Math.max(0, fPrefix - fContextLength), fPrefix); + } + + private String computeCommonSuffix() { + int end= Math.min(fExpected.length() - fSuffix + 1 + fContextLength, fExpected.length()); + return fExpected.substring(fExpected.length() - fSuffix + 1, end) + (fExpected.length() - fSuffix + 1 < fExpected.length() - fContextLength ? ELLIPSIS : ""); + } + + private boolean areStringsEqual() { + return fExpected.equals(fActual); + } + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/Ignore.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/Ignore.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,39 @@ +package org.junit; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + *

Sometimes you want to temporarily disable a test or a group of tests. Methods annotated with + * {@link org.junit.Test} that are also annotated with @Ignore will not be executed as tests. + * Also, you can annotate a class containing test methods with @Ignore and none of the containing + * tests will be executed. Native JUnit 4 test runners should report the number of ignored tests along with the + * number of tests that ran and the number of tests that failed.

+ * + * For example: + *
+ *    @Ignore @Test public void something() { ...
+ * 
+ * @Ignore takes an optional default parameter if you want to record why a test is being ignored:
+ *
+ *    @Ignore("not ready yet") @Test public void something() { ...
+ * 
+ * @Ignore can also be applied to the test class:
+ *
+ *		@Ignore public class IgnoreMe {
+ *			@Test public void test1() { ... }
+ *			@Test public void test2() { ... }
+ *		}
+ * 
+ * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +public @interface Ignore { + /** + * The optional reason why the test is ignored. + */ + String value() default ""; +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/Test.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/Test.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,68 @@ +package org.junit; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + *

The Test annotation tells JUnit that the public void method + * to which it is attached can be run as a test case. To run the method, + * JUnit first constructs a fresh instance of the class then invokes the + * annotated method. Any exceptions thrown by the test will be reported + * by JUnit as a failure. If no exceptions are thrown, the test is assumed + * to have succeeded.

+ * + *

A simple test looks like this: + *

+ * public class Example {
+ *    @Test 
+ *    public void method() {
+ *       org.junit.Assert.assertTrue( new ArrayList().isEmpty() );
+ *    }
+ * }
+ * 
+ *

+ * + *

The Test annotation supports two optional parameters. + * The first, expected, declares that a test method should throw + * an exception. If it doesn't throw an exception or if it throws a different exception + * than the one declared, the test fails. For example, the following test succeeds: + *

+ *    @Test(expected=IndexOutOfBoundsException.class) public void outOfBounds() {
+ *       new ArrayList<Object>().get(1);
+ *    }
+ * 

+ * + *

The second optional parameter, timeout, causes a test to fail if it takes + * longer than a specified amount of clock time (measured in milliseconds). The following test fails: + *

+ *    @Test(timeout=100) public void infinity() {
+ *       while(true);
+ *    }
+ * 

+ */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD}) +public @interface Test { + + /** + * Default empty exception + */ + static class None extends Throwable { + private static final long serialVersionUID= 1L; + private None() { + } + } + + /** + * Optionally specify expected, a Throwable, to cause a test method to succeed iff + * an exception of the specified class is thrown by the method. + */ + Class expected() default None.class; + + /** + * Optionally specify timeout in milliseconds to cause a test method to fail if it + * takes longer than that number of milliseconds.*/ + long timeout() default 0L; +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/results/FailureList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/results/FailureList.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,31 @@ +/** + * + */ +package org.junit.experimental.results; + +import java.util.List; + +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunListener; + +public class FailureList { + private final List failures; + + public FailureList(List failures) { + this.failures= failures; + } + + public Result result() { + Result result= new Result(); + RunListener listener= result.createListener(); + for (Failure failure : failures) { + try { + listener.testFailure(failure); + } catch (Exception e) { + throw new RuntimeException("I can't believe this happened"); + } + } + return result; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/results/PrintableResult.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/results/PrintableResult.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,44 @@ +/** + * + */ +package org.junit.experimental.results; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.List; + +import org.junit.internal.TextListener; +import org.junit.runner.JUnitCore; +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; + +public class PrintableResult { + public static PrintableResult testResult(Class type) { + return new PrintableResult(type); + } + + private Result result; + + public PrintableResult(List failures) { + this(new FailureList(failures).result()); + } + + public PrintableResult(Result result) { + this.result = result; + } + + public PrintableResult(Class type) { + this(JUnitCore.runClasses(type)); + } + + @Override + public String toString() { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + new TextListener(new PrintStream(stream)).testRunFinished(result); + return stream.toString(); + } + + public List getFailures() { + return result.getFailures(); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/results/ResultMatchers.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/results/ResultMatchers.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,49 @@ +package org.junit.experimental.results; + +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.junit.internal.matchers.TypeSafeMatcher; + +public class ResultMatchers { + public static Matcher isSuccessful() { + return failureCountIs(0); + } + + public static Matcher failureCountIs(final int count) { + return new TypeSafeMatcher() { + public void describeTo(Description description) { + description.appendText("has " + count + " failures"); + } + + @Override + public boolean matchesSafely(PrintableResult item) { + return item.getFailures().size() == count; + } + }; + } + + public static Matcher hasSingleFailureContaining(final String string) { + return new BaseMatcher() { + public boolean matches(Object item) { + return item.toString().contains(string) && failureCountIs(1).matches(item); + } + + public void describeTo(Description description) { + description.appendText("has single failure containing " + string); + } + }; + } + + public static Matcher hasFailureContaining(final String string) { + return new BaseMatcher() { + public boolean matches(Object item) { + return item.toString().contains(string); + } + + public void describeTo(Description description) { + description.appendText("has failure containing " + string); + } + }; + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/runners/Enclosed.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/runners/Enclosed.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,31 @@ +package org.junit.experimental.runners; + +import org.junit.runners.Suite; +import org.junit.runners.model.RunnerBuilder; + + +/** + * If you put tests in inner classes, Ant, for example, won't find them. By running the outer class + * with Enclosed, the tests in the inner classes will be run. You might put tests in inner classes + * to group them for convenience or to share constants. + * + * So, for example: + *
+ *  \@RunWith(Enclosed.class)
+ *  public class ListTests {
+ *  	...useful shared stuff...
+ *  	public static class OneKindOfListTest {...}
+ *  	public static class AnotherKind {...}
+ *  }
+ *  
+ * + * For a real example, @see org.junit.tests.manipulation.SortableTest. + */ +public class Enclosed extends Suite { + /** + * Only called reflectively. Do not use programmatically. + */ + public Enclosed(Class klass, RunnerBuilder builder) throws Throwable { + super(builder, klass, klass.getClasses()); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/DataPoint.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/DataPoint.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,9 @@ +package org.junit.experimental.theories; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface DataPoint { + +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/DataPoints.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/DataPoints.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,9 @@ +package org.junit.experimental.theories; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface DataPoints { + +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/ParameterSignature.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/ParameterSignature.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,90 @@ +/** + * + */ +package org.junit.experimental.theories; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class ParameterSignature { + public static ArrayList signatures(Method method) { + return signatures(method.getParameterTypes(), method + .getParameterAnnotations()); + } + + public static List signatures(Constructor constructor) { + return signatures(constructor.getParameterTypes(), constructor + .getParameterAnnotations()); + } + + private static ArrayList signatures( + Class[] parameterTypes, Annotation[][] parameterAnnotations) { + ArrayList sigs= new ArrayList(); + for (int i= 0; i < parameterTypes.length; i++) { + sigs.add(new ParameterSignature(parameterTypes[i], + parameterAnnotations[i])); + } + return sigs; + } + + private final Class type; + + private final Annotation[] annotations; + + private ParameterSignature(Class type, Annotation[] annotations) { + this.type= type; + this.annotations= annotations; + } + + public boolean canAcceptType(Class candidate) { + return type.isAssignableFrom(candidate); + } + + public Class getType() { + return type; + } + + public List getAnnotations() { + return Arrays.asList(annotations); + } + + public boolean canAcceptArrayType(Class type) { + return type.isArray() && canAcceptType(type.getComponentType()); + } + + public boolean hasAnnotation(Class type) { + return getAnnotation(type) != null; + } + + public T findDeepAnnotation(Class annotationType) { + Annotation[] annotations2= annotations; + return findDeepAnnotation(annotations2, annotationType, 3); + } + + private T findDeepAnnotation( + Annotation[] annotations, Class annotationType, int depth) { + if (depth == 0) + return null; + for (Annotation each : annotations) { + if (annotationType.isInstance(each)) + return annotationType.cast(each); + Annotation candidate= findDeepAnnotation(each.annotationType() + .getAnnotations(), annotationType, depth - 1); + if (candidate != null) + return annotationType.cast(candidate); + } + + return null; + } + + public T getAnnotation(Class annotationType) { + for (Annotation each : getAnnotations()) + if (annotationType.isInstance(each)) + return annotationType.cast(each); + return null; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/ParameterSupplier.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/ParameterSupplier.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,8 @@ +package org.junit.experimental.theories; + +import java.util.List; + + +public abstract class ParameterSupplier { + public abstract List getValueSources(ParameterSignature sig); +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/ParametersSuppliedBy.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/ParametersSuppliedBy.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,12 @@ +package org.junit.experimental.theories; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + + +@Retention(RetentionPolicy.RUNTIME) +public @interface ParametersSuppliedBy { + + Class value(); + +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/PotentialAssignment.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/PotentialAssignment.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,31 @@ +package org.junit.experimental.theories; + +public abstract class PotentialAssignment { + public static class CouldNotGenerateValueException extends Exception { + private static final long serialVersionUID= 1L; + } + + public static PotentialAssignment forValue(final String name, final Object value) { + return new PotentialAssignment() { + @Override + public Object getValue() throws CouldNotGenerateValueException { + return value; + } + + @Override + public String toString() { + return String.format("[%s]", value); + } + + @Override + public String getDescription() + throws CouldNotGenerateValueException { + return name; + } + }; + } + + public abstract Object getValue() throws CouldNotGenerateValueException; + + public abstract String getDescription() throws CouldNotGenerateValueException; +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/Theories.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/Theories.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,189 @@ +/** + * + */ +package org.junit.experimental.theories; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.experimental.theories.PotentialAssignment.CouldNotGenerateValueException; +import org.junit.experimental.theories.internal.Assignments; +import org.junit.experimental.theories.internal.ParameterizedAssertionError; +import org.junit.internal.AssumptionViolatedException; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.Statement; + +public class Theories extends BlockJUnit4ClassRunner { + public Theories(Class klass) throws InitializationError { + super(klass); + } + + @Override + protected void collectInitializationErrors(List errors) { + super.collectInitializationErrors(errors); + validateDataPointFields(errors); + } + + private void validateDataPointFields(List errors) { + Field[] fields= getTestClass().getJavaClass().getDeclaredFields(); + + for (Field each : fields) + if (each.getAnnotation(DataPoint.class) != null && !Modifier.isStatic(each.getModifiers())) + errors.add(new Error("DataPoint field " + each.getName() + " must be static")); + } + + @Override + protected void validateZeroArgConstructor(List errors) { + // constructor can have args + } + + @Override + protected void validateTestMethods(List errors) { + for (FrameworkMethod each : computeTestMethods()) + each.validatePublicVoid(false, errors); + } + + @Override + protected List computeTestMethods() { + List testMethods= super.computeTestMethods(); + List theoryMethods= getTestClass().getAnnotatedMethods(Theory.class); + testMethods.removeAll(theoryMethods); + testMethods.addAll(theoryMethods); + return testMethods; + } + + @Override + public Statement methodBlock(final FrameworkMethod method) { + return new TheoryAnchor(method); + } + + public class TheoryAnchor extends Statement { + private int successes= 0; + + private FrameworkMethod fTestMethod; + + private List fInvalidParameters= new ArrayList(); + + public TheoryAnchor(FrameworkMethod method) { + fTestMethod= method; + } + + @Override + public void evaluate() throws Throwable { + runWithAssignment(Assignments.allUnassigned( + fTestMethod.getMethod(), getTestClass())); + + if (successes == 0) + Assert + .fail("Never found parameters that satisfied method assumptions. Violated assumptions: " + + fInvalidParameters); + } + + protected void runWithAssignment(Assignments parameterAssignment) + throws Throwable { + if (!parameterAssignment.isComplete()) { + runWithIncompleteAssignment(parameterAssignment); + } else { + runWithCompleteAssignment(parameterAssignment); + } + } + + protected void runWithIncompleteAssignment(Assignments incomplete) + throws InstantiationException, IllegalAccessException, + Throwable { + for (PotentialAssignment source : incomplete + .potentialsForNextUnassigned()) { + runWithAssignment(incomplete.assignNext(source)); + } + } + + protected void runWithCompleteAssignment(final Assignments complete) + throws InstantiationException, IllegalAccessException, + InvocationTargetException, NoSuchMethodException, Throwable { + new BlockJUnit4ClassRunner(getTestClass().getJavaClass()) { + @Override + protected void collectInitializationErrors( + List errors) { + // do nothing + } + + @Override + public Statement methodBlock(FrameworkMethod method) { + final Statement statement= super.methodBlock(method); + return new Statement() { + @Override + public void evaluate() throws Throwable { + try { + statement.evaluate(); + handleDataPointSuccess(); + } catch (AssumptionViolatedException e) { + handleAssumptionViolation(e); + } catch (Throwable e) { + reportParameterizedError(e, complete + .getArgumentStrings(nullsOk())); + } + } + + }; + } + + @Override + protected Statement methodInvoker(FrameworkMethod method, Object test) { + return methodCompletesWithParameters(method, complete, test); + } + + @Override + public Object createTest() throws Exception { + return getTestClass().getOnlyConstructor().newInstance( + complete.getConstructorArguments(nullsOk())); + } + }.methodBlock(fTestMethod).evaluate(); + } + + private Statement methodCompletesWithParameters( + final FrameworkMethod method, final Assignments complete, final Object freshInstance) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + try { + final Object[] values= complete.getMethodArguments( + nullsOk()); + method.invokeExplosively(freshInstance, values); + } catch (CouldNotGenerateValueException e) { + // ignore + } + } + }; + } + + protected void handleAssumptionViolation(AssumptionViolatedException e) { + fInvalidParameters.add(e); + } + + protected void reportParameterizedError(Throwable e, Object... params) + throws Throwable { + if (params.length == 0) + throw e; + throw new ParameterizedAssertionError(e, fTestMethod.getName(), + params); + } + + private boolean nullsOk() { + Theory annotation= fTestMethod.getMethod().getAnnotation( + Theory.class); + if (annotation == null) + return false; + return annotation.nullsAccepted(); + } + + protected void handleDataPointSuccess() { + successes++; + } + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/Theory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/Theory.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,12 @@ +/** + * + */ +package org.junit.experimental.theories; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Theory { + boolean nullsAccepted() default true; +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/internal/AllMembersSupplier.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/internal/AllMembersSupplier.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,121 @@ +/** + * + */ +package org.junit.experimental.theories.internal; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import org.junit.experimental.theories.DataPoint; +import org.junit.experimental.theories.DataPoints; +import org.junit.experimental.theories.ParameterSignature; +import org.junit.experimental.theories.ParameterSupplier; +import org.junit.experimental.theories.PotentialAssignment; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.TestClass; + +public class AllMembersSupplier extends ParameterSupplier { + static class MethodParameterValue extends PotentialAssignment { + private final FrameworkMethod fMethod; + + private MethodParameterValue(FrameworkMethod dataPointMethod) { + fMethod= dataPointMethod; + } + + @Override + public Object getValue() throws CouldNotGenerateValueException { + try { + return fMethod.invokeExplosively(null); + } catch (IllegalArgumentException e) { + throw new RuntimeException( + "unexpected: argument length is checked"); + } catch (IllegalAccessException e) { + throw new RuntimeException( + "unexpected: getMethods returned an inaccessible method"); + } catch (Throwable e) { + throw new CouldNotGenerateValueException(); + // do nothing, just look for more values + } + } + + @Override + public String getDescription() throws CouldNotGenerateValueException { + return fMethod.getName(); + } + } + + private final TestClass fClass; + + public AllMembersSupplier(TestClass type) { + fClass= type; + } + + @Override + public List getValueSources(ParameterSignature sig) { + List list= new ArrayList(); + + addFields(sig, list); + addSinglePointMethods(sig, list); + addMultiPointMethods(list); + + return list; + } + + private void addMultiPointMethods(List list) { + for (FrameworkMethod dataPointsMethod : fClass + .getAnnotatedMethods(DataPoints.class)) + try { + addArrayValues(dataPointsMethod.getName(), list, dataPointsMethod.invokeExplosively(null)); + } catch (Throwable e) { + // ignore and move on + } + } + + private void addSinglePointMethods(ParameterSignature sig, + List list) { + for (FrameworkMethod dataPointMethod : fClass + .getAnnotatedMethods(DataPoint.class)) { + Class type= sig.getType(); + if ((dataPointMethod.producesType(type))) + list.add(new MethodParameterValue(dataPointMethod)); + } + } + + private void addFields(ParameterSignature sig, + List list) { + for (final Field field : fClass.getJavaClass().getFields()) { + if (Modifier.isStatic(field.getModifiers())) { + Class type= field.getType(); + if (sig.canAcceptArrayType(type) + && field.getAnnotation(DataPoints.class) != null) { + addArrayValues(field.getName(), list, getStaticFieldValue(field)); + } else if (sig.canAcceptType(type)) { + list.add(PotentialAssignment + .forValue(field.getName(), getStaticFieldValue(field))); + } + } + } + } + + private void addArrayValues(String name, List list, Object array) { + for (int i= 0; i < Array.getLength(array); i++) + list.add(PotentialAssignment.forValue(name + "[" + i + "]", Array.get(array, i))); + } + + private Object getStaticFieldValue(final Field field) { + try { + return field.get(null); + } catch (IllegalArgumentException e) { + throw new RuntimeException( + "unexpected: field from getClass doesn't exist on object"); + } catch (IllegalAccessException e) { + throw new RuntimeException( + "unexpected: getFields returned an inaccessible field"); + } + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/internal/Assignments.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/internal/Assignments.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,123 @@ +/** + * + */ +package org.junit.experimental.theories.internal; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import org.junit.experimental.theories.ParameterSignature; +import org.junit.experimental.theories.ParameterSupplier; +import org.junit.experimental.theories.ParametersSuppliedBy; +import org.junit.experimental.theories.PotentialAssignment; +import org.junit.experimental.theories.PotentialAssignment.CouldNotGenerateValueException; +import org.junit.runners.model.TestClass; + +public class Assignments { + private List fAssigned; + + private final List fUnassigned; + + private final TestClass fClass; + + public Assignments(List assigned, + List unassigned, TestClass testClass) { + fUnassigned= unassigned; + fAssigned= assigned; + fClass= testClass; + } + + public static Assignments allUnassigned(Method testMethod, + TestClass testClass) throws Exception { + List signatures; + signatures= ParameterSignature.signatures(testClass.getOnlyConstructor()); + signatures.addAll(ParameterSignature.signatures(testMethod)); + return new Assignments(new ArrayList(), + signatures, testClass); + } + + public boolean isComplete() { + return fUnassigned.size() == 0; + } + + public ParameterSignature nextUnassigned() { + return fUnassigned.get(0); + } + + public Assignments assignNext(PotentialAssignment source) { + List assigned= new ArrayList( + fAssigned); + assigned.add(source); + + return new Assignments(assigned, fUnassigned.subList(1, fUnassigned + .size()), fClass); + } + + public Object[] getActualValues(int start, int stop, boolean nullsOk) + throws CouldNotGenerateValueException { + Object[] values= new Object[stop - start]; + for (int i= start; i < stop; i++) { + Object value= fAssigned.get(i).getValue(); + if (value == null && !nullsOk) + throw new CouldNotGenerateValueException(); + values[i - start]= value; + } + return values; + } + + public List potentialsForNextUnassigned() + throws InstantiationException, IllegalAccessException { + ParameterSignature unassigned= nextUnassigned(); + return getSupplier(unassigned).getValueSources(unassigned); + } + + public ParameterSupplier getSupplier(ParameterSignature unassigned) + throws InstantiationException, IllegalAccessException { + ParameterSupplier supplier= getAnnotatedSupplier(unassigned); + if (supplier != null) + return supplier; + + return new AllMembersSupplier(fClass); + } + + public ParameterSupplier getAnnotatedSupplier(ParameterSignature unassigned) + throws InstantiationException, IllegalAccessException { + ParametersSuppliedBy annotation= unassigned + .findDeepAnnotation(ParametersSuppliedBy.class); + if (annotation == null) + return null; + return annotation.value().newInstance(); + } + + public Object[] getConstructorArguments(boolean nullsOk) + throws CouldNotGenerateValueException { + return getActualValues(0, getConstructorParameterCount(), nullsOk); + } + + public Object[] getMethodArguments(boolean nullsOk) + throws CouldNotGenerateValueException { + return getActualValues(getConstructorParameterCount(), + fAssigned.size(), nullsOk); + } + + public Object[] getAllArguments(boolean nullsOk) + throws CouldNotGenerateValueException { + return getActualValues(0, fAssigned.size(), nullsOk); + } + + private int getConstructorParameterCount() { + List signatures= ParameterSignature + .signatures(fClass.getOnlyConstructor()); + int constructorParameterCount= signatures.size(); + return constructorParameterCount; + } + + public Object[] getArgumentStrings(boolean nullsOk) throws CouldNotGenerateValueException { + Object[] values= new Object[fAssigned.size()]; + for (int i= 0; i < values.length; i++) { + values[i]= fAssigned.get(i).getDescription(); + } + return values; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/internal/ParameterizedAssertionError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/internal/ParameterizedAssertionError.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,49 @@ +/** + * + */ +package org.junit.experimental.theories.internal; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; + + +public class ParameterizedAssertionError extends RuntimeException { + private static final long serialVersionUID = 1L; + + public ParameterizedAssertionError(Throwable targetException, + String methodName, Object... params) { + super(String.format("%s(%s)", methodName, join(", ", params)), + targetException); + } + + @Override public boolean equals(Object obj) { + return toString().equals(obj.toString()); + } + + public static String join(String delimiter, Object... params) { + return join(delimiter, Arrays.asList(params)); + } + + public static String join(String delimiter, + Collection values) { + StringBuffer buffer = new StringBuffer(); + Iterator iter = values.iterator(); + while (iter.hasNext()) { + Object next = iter.next(); + buffer.append(stringValueOf(next)); + if (iter.hasNext()) { + buffer.append(delimiter); + } + } + return buffer.toString(); + } + + private static String stringValueOf(Object next) { + try { + return String.valueOf(next); + } catch (Throwable e) { + return "[toString failed]"; + } + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/suppliers/TestedOn.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/suppliers/TestedOn.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,13 @@ +package org.junit.experimental.theories.suppliers; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.junit.experimental.theories.ParametersSuppliedBy; + + +@ParametersSuppliedBy(TestedOnSupplier.class) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestedOn { + int[] ints(); +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/suppliers/TestedOnSupplier.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/experimental/theories/suppliers/TestedOnSupplier.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,23 @@ +package org.junit.experimental.theories.suppliers; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.experimental.theories.ParameterSignature; +import org.junit.experimental.theories.ParameterSupplier; +import org.junit.experimental.theories.PotentialAssignment; + + + +public class TestedOnSupplier extends ParameterSupplier { + @Override public List getValueSources(ParameterSignature sig) { + List list = new ArrayList(); + TestedOn testedOn = sig.getAnnotation(TestedOn.class); + int[] ints = testedOn.ints(); + for (final int i : ints) { + list.add(PotentialAssignment.forValue(Arrays.asList(ints).toString(), i)); + } + return list; + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/ArrayComparisonFailure.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/ArrayComparisonFailure.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,59 @@ +package org.junit.internal; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; + +/** + * Thrown when two array elements differ + * @see Assert#assertArrayEquals(String, Object[], Object[]) + */ +public class ArrayComparisonFailure extends AssertionError { + + private static final long serialVersionUID= 1L; + + private List fIndices= new ArrayList(); + private final String fMessage; + private final AssertionError fCause; + + /** + * Construct a new ArrayComparisonFailure with an error text and the array's + * dimension that was not equal + * @param cause the exception that caused the array's content to fail the assertion test + * @param index the array position of the objects that are not equal. + * @see Assert#assertArrayEquals(String, Object[], Object[]) + */ + public ArrayComparisonFailure(String message, AssertionError cause, int index) { + fMessage= message; + fCause= cause; + addDimension(index); + } + + public void addDimension(int index) { + fIndices.add(0, index); + } + + @Override + public String getMessage() { + StringBuilder builder= new StringBuilder(); + if (fMessage != null) + builder.append(fMessage); + builder.append("arrays first differed at element "); + for (int each : fIndices) { + builder.append("["); + builder.append(each); + builder.append("]"); + } + builder.append("; "); + builder.append(fCause.getMessage()); + return builder.toString(); + } + + /** + * {@inheritDoc} + */ + @Override public String toString() { + return getMessage(); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/AssumptionViolatedException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/AssumptionViolatedException.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,40 @@ +package org.junit.internal; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.SelfDescribing; +import org.hamcrest.StringDescription; + +public class AssumptionViolatedException extends RuntimeException implements SelfDescribing { + private static final long serialVersionUID= 1L; + + private final Object fValue; + + private final Matcher fMatcher; + + public AssumptionViolatedException(Object value, Matcher matcher) { + super(value instanceof Throwable ? (Throwable) value : null); + fValue= value; + fMatcher= matcher; + } + + public AssumptionViolatedException(String assumption) { + this(assumption, null); + } + + @Override + public String getMessage() { + return StringDescription.asString(this); + } + + public void describeTo(Description description) { + if (fMatcher != null) { + description.appendText("got: "); + description.appendValue(fValue); + description.appendText(", expected: "); + description.appendDescriptionOf(fMatcher); + } else { + description.appendText("failed assumption: " + fValue); + } + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/JUnitSystem.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/JUnitSystem.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,8 @@ +package org.junit.internal; + +import java.io.PrintStream; + +public interface JUnitSystem { + void exit(int i); + PrintStream out(); +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/RealSystem.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/RealSystem.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,15 @@ +package org.junit.internal; + +import java.io.PrintStream; + +public class RealSystem implements JUnitSystem { + + public void exit(int code) { + System.exit(code); + } + + public PrintStream out() { + return System.out; + } + +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/TextListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/TextListener.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,98 @@ +package org.junit.internal; + +import java.io.PrintStream; +import java.text.NumberFormat; +import java.util.List; + +import org.junit.runner.Description; +import org.junit.runner.Result; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunListener; + +public class TextListener extends RunListener { + + private final PrintStream fWriter; + + public TextListener(JUnitSystem system) { + this(system.out()); + } + + public TextListener(PrintStream writer) { + this.fWriter= writer; + } + + @Override + public void testRunFinished(Result result) { + printHeader(result.getRunTime()); + printFailures(result); + printFooter(result); + } + + @Override + public void testStarted(Description description) { + fWriter.append('.'); + } + + @Override + public void testFailure(Failure failure) { + fWriter.append('E'); + } + + @Override + public void testIgnored(Description description) { + fWriter.append('I'); + } + + /* + * Internal methods + */ + + private PrintStream getWriter() { + return fWriter; + } + + protected void printHeader(long runTime) { + getWriter().println(); + getWriter().println("Time: " + elapsedTimeAsString(runTime)); + } + + protected void printFailures(Result result) { + List failures= result.getFailures(); + if (failures.size() == 0) + return; + if (failures.size() == 1) + getWriter().println("There was " + failures.size() + " failure:"); + else + getWriter().println("There were " + failures.size() + " failures:"); + int i= 1; + for (Failure each : failures) + printFailure(each, "" + i++); + } + + protected void printFailure(Failure each, String prefix) { + getWriter().println(prefix + ") " + each.getTestHeader()); + getWriter().print(each.getTrace()); + } + + protected void printFooter(Result result) { + if (result.wasSuccessful()) { + getWriter().println(); + getWriter().print("OK"); + getWriter().println(" (" + result.getRunCount() + " test" + (result.getRunCount() == 1 ? "" : "s") + ")"); + + } else { + getWriter().println(); + getWriter().println("FAILURES!!!"); + getWriter().println("Tests run: " + result.getRunCount() + ", Failures: " + result.getFailureCount()); + } + getWriter().println(); + } + + /** + * Returns the formatted string of the elapsed time. Duplicated from + * BaseTestRunner. Fix it. + */ + protected String elapsedTimeAsString(long runTime) { + return NumberFormat.getInstance().format((double) runTime / 1000); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/AllDefaultPossibilitiesBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/AllDefaultPossibilitiesBuilder.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,57 @@ +/** + * + */ +package org.junit.internal.builders; + +import java.util.Arrays; +import java.util.List; + +import org.junit.runner.Runner; +import org.junit.runners.model.RunnerBuilder; + +public class AllDefaultPossibilitiesBuilder extends RunnerBuilder { + private final boolean fCanUseSuiteMethod; + + public AllDefaultPossibilitiesBuilder(boolean canUseSuiteMethod) { + fCanUseSuiteMethod= canUseSuiteMethod; + } + + @Override + public Runner runnerForClass(Class testClass) throws Throwable { + List builders= Arrays.asList( + ignoredBuilder(), + annotatedBuilder(), + suiteMethodBuilder(), + junit3Builder(), + junit4Builder()); + + for (RunnerBuilder each : builders) { + Runner runner= each.safeRunnerForClass(testClass); + if (runner != null) + return runner; + } + return null; + } + + protected JUnit4Builder junit4Builder() { + return new JUnit4Builder(); + } + + protected JUnit3Builder junit3Builder() { + return new JUnit3Builder(); + } + + protected AnnotatedBuilder annotatedBuilder() { + return new AnnotatedBuilder(this); + } + + protected IgnoredBuilder ignoredBuilder() { + return new IgnoredBuilder(); + } + + protected RunnerBuilder suiteMethodBuilder() { + if (fCanUseSuiteMethod) + return new SuiteMethodBuilder(); + return new NullBuilder(); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/AnnotatedBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/AnnotatedBuilder.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,45 @@ +/** + * + */ +package org.junit.internal.builders; + +import org.junit.runner.RunWith; +import org.junit.runner.Runner; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.RunnerBuilder; + +public class AnnotatedBuilder extends RunnerBuilder { + private static final String CONSTRUCTOR_ERROR_FORMAT= "Custom runner class %s should have a public constructor with signature %s(Class testClass)"; + + private RunnerBuilder fSuiteBuilder; + + public AnnotatedBuilder(RunnerBuilder suiteBuilder) { + fSuiteBuilder= suiteBuilder; + } + + @Override + public Runner runnerForClass(Class testClass) throws Exception { + RunWith annotation= testClass.getAnnotation(RunWith.class); + if (annotation != null) + return buildRunner(annotation.value(), testClass); + return null; + } + + public Runner buildRunner(Class runnerClass, + Class testClass) throws Exception { + try { + return runnerClass.getConstructor(Class.class).newInstance( + new Object[] { testClass }); + } catch (NoSuchMethodException e) { + try { + return runnerClass.getConstructor(Class.class, + RunnerBuilder.class).newInstance( + new Object[] { testClass, fSuiteBuilder }); + } catch (NoSuchMethodException e2) { + String simpleName= runnerClass.getSimpleName(); + throw new InitializationError(String.format( + CONSTRUCTOR_ERROR_FORMAT, simpleName, simpleName)); + } + } + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/IgnoredBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/IgnoredBuilder.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,17 @@ +/** + * + */ +package org.junit.internal.builders; + +import org.junit.Ignore; +import org.junit.runner.Runner; +import org.junit.runners.model.RunnerBuilder; + +public class IgnoredBuilder extends RunnerBuilder { + @Override + public Runner runnerForClass(Class testClass) { + if (testClass.getAnnotation(Ignore.class) != null) + return new IgnoredClassRunner(testClass); + return null; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/IgnoredClassRunner.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/IgnoredClassRunner.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,26 @@ +/** + * + */ +package org.junit.internal.builders; + +import org.junit.runner.Description; +import org.junit.runner.Runner; +import org.junit.runner.notification.RunNotifier; + +public class IgnoredClassRunner extends Runner { + private final Class fTestClass; + + public IgnoredClassRunner(Class testClass) { + fTestClass= testClass; + } + + @Override + public void run(RunNotifier notifier) { + notifier.fireTestIgnored(getDescription()); + } + + @Override + public Description getDescription() { + return Description.createSuiteDescription(fTestClass); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/JUnit3Builder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/JUnit3Builder.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,21 @@ +/** + * + */ +package org.junit.internal.builders; + +import org.junit.internal.runners.JUnit38ClassRunner; +import org.junit.runner.Runner; +import org.junit.runners.model.RunnerBuilder; + +public class JUnit3Builder extends RunnerBuilder { + @Override + public Runner runnerForClass(Class testClass) throws Throwable { + if (isPre4Test(testClass)) + return new JUnit38ClassRunner(testClass); + return null; + } + + boolean isPre4Test(Class testClass) { + return junit.framework.TestCase.class.isAssignableFrom(testClass); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/JUnit4Builder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/JUnit4Builder.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,15 @@ +/** + * + */ +package org.junit.internal.builders; + +import org.junit.runner.Runner; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.RunnerBuilder; + +public class JUnit4Builder extends RunnerBuilder { + @Override + public Runner runnerForClass(Class testClass) throws Throwable { + return new BlockJUnit4ClassRunner(testClass); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/NullBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/NullBuilder.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,14 @@ +/** + * + */ +package org.junit.internal.builders; + +import org.junit.runner.Runner; +import org.junit.runners.model.RunnerBuilder; + +public class NullBuilder extends RunnerBuilder { + @Override + public Runner runnerForClass(Class each) throws Throwable { + return null; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/SuiteMethodBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/builders/SuiteMethodBuilder.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,26 @@ +/** + * + */ +package org.junit.internal.builders; + +import org.junit.internal.runners.SuiteMethod; +import org.junit.runner.Runner; +import org.junit.runners.model.RunnerBuilder; + +public class SuiteMethodBuilder extends RunnerBuilder { + @Override + public Runner runnerForClass(Class each) throws Throwable { + if (hasSuiteMethod(each)) + return new SuiteMethod(each); + return null; + } + + public boolean hasSuiteMethod(Class testClass) { + try { + testClass.getMethod("suite"); + } catch (NoSuchMethodException e) { + return false; + } + return true; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/CombinableMatcher.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/CombinableMatcher.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,34 @@ +package org.junit.internal.matchers; + +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.anyOf; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Matcher; + +public class CombinableMatcher extends BaseMatcher { + + private final Matcher fMatcher; + + public CombinableMatcher(Matcher matcher) { + fMatcher= matcher; + } + + public boolean matches(Object item) { + return fMatcher.matches(item); + } + + public void describeTo(Description description) { + description.appendDescriptionOf(fMatcher); + } + + @SuppressWarnings("unchecked") + public CombinableMatcher and(Matcher matcher) { + return new CombinableMatcher(allOf(matcher, fMatcher)); + } + + @SuppressWarnings("unchecked") + public CombinableMatcher or(Matcher matcher) { + return new CombinableMatcher(anyOf(matcher, fMatcher)); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/Each.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/Each.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,24 @@ +package org.junit.internal.matchers; + +import static org.hamcrest.CoreMatchers.not; +import static org.junit.internal.matchers.IsCollectionContaining.hasItem; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Matcher; + +public class Each { + public static Matcher> each(final Matcher individual) { + final Matcher> allItemsAre = not(hasItem(not(individual))); + + return new BaseMatcher>() { + public boolean matches(Object item) { + return allItemsAre.matches(item); + } + + public void describeTo(Description description) { + description.appendText("each "); + individual.describeTo(description); + } + }; + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/IsCollectionContaining.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/IsCollectionContaining.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,67 @@ +package org.junit.internal.matchers; + +import static org.hamcrest.core.AllOf.allOf; +import static org.hamcrest.core.IsEqual.equalTo; + +import java.util.ArrayList; +import java.util.Collection; + +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; + +// Copied (hopefully temporarily) from hamcrest-library +public class IsCollectionContaining extends TypeSafeMatcher> { + private final Matcher elementMatcher; + + public IsCollectionContaining(Matcher elementMatcher) { + this.elementMatcher = elementMatcher; + } + + @Override + public boolean matchesSafely(Iterable collection) { + for (T item : collection) { + if (elementMatcher.matches(item)){ + return true; + } + } + return false; + } + + public void describeTo(Description description) { + description + .appendText("a collection containing ") + .appendDescriptionOf(elementMatcher); + } + + @Factory + public static Matcher> hasItem(Matcher elementMatcher) { + return new IsCollectionContaining(elementMatcher); + } + + @Factory + public static Matcher> hasItem(T element) { + return hasItem(equalTo(element)); + } + + @Factory + public static Matcher> hasItems(Matcher... elementMatchers) { + Collection>> all + = new ArrayList>>(elementMatchers.length); + for (Matcher elementMatcher : elementMatchers) { + all.add(hasItem(elementMatcher)); + } + return allOf(all); + } + + @Factory + public static Matcher> hasItems(T... elements) { + Collection>> all + = new ArrayList>>(elements.length); + for (T element : elements) { + all.add(hasItem(element)); + } + return allOf(all); + } + +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/StringContains.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/StringContains.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,31 @@ +/* Copyright (c) 2000-2006 hamcrest.org + */ +package org.junit.internal.matchers; + +import org.hamcrest.Factory; +import org.hamcrest.Matcher; + +/** + * Tests if the argument is a string that contains a substring. + */ +public class StringContains extends SubstringMatcher { + public StringContains(String substring) { + super(substring); + } + + @Override + protected boolean evalSubstringOf(String s) { + return s.indexOf(substring) >= 0; + } + + @Override + protected String relationship() { + return "containing"; + } + + @Factory + public static Matcher containsString(String substring) { + return new StringContains(substring); + } + +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/SubstringMatcher.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/SubstringMatcher.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,28 @@ +package org.junit.internal.matchers; + +import org.hamcrest.Description; + +public abstract class SubstringMatcher extends TypeSafeMatcher { + + protected final String substring; + + protected SubstringMatcher(final String substring) { + this.substring = substring; + } + + @Override + public boolean matchesSafely(String item) { + return evalSubstringOf(item); + } + + public void describeTo(Description description) { + description.appendText("a string ") + .appendText(relationship()) + .appendText(" ") + .appendValue(substring); + } + + protected abstract boolean evalSubstringOf(String string); + + protected abstract String relationship(); +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/TypeSafeMatcher.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/matchers/TypeSafeMatcher.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,60 @@ +package org.junit.internal.matchers; + +import java.lang.reflect.Method; + +import org.hamcrest.BaseMatcher; + +/** + * Convenient base class for Matchers that require a non-null value of a specific type. + * This simply implements the null check, checks the type and then casts. + * + * @author Joe Walnes + */ +public abstract class TypeSafeMatcher extends BaseMatcher { + + private Class expectedType; + + /** + * Subclasses should implement this. The item will already have been checked for + * the specific type and will never be null. + */ + public abstract boolean matchesSafely(T item); + + protected TypeSafeMatcher() { + expectedType = findExpectedType(getClass()); + } + + private static Class findExpectedType(Class fromClass) { + for (Class c = fromClass; c != Object.class; c = c.getSuperclass()) { + for (Method method : c.getDeclaredMethods()) { + if (isMatchesSafelyMethod(method)) { + return method.getParameterTypes()[0]; + } + } + } + + throw new Error("Cannot determine correct type for matchesSafely() method."); + } + + private static boolean isMatchesSafelyMethod(Method method) { + return method.getName().equals("matchesSafely") + && method.getParameterTypes().length == 1 + && !method.isSynthetic(); + } + + protected TypeSafeMatcher(Class expectedType) { + this.expectedType = expectedType; + } + + /** + * Method made final to prevent accidental override. + * If you need to override this, there's no point on extending TypeSafeMatcher. + * Instead, extend the {@link BaseMatcher}. + */ + @SuppressWarnings({"unchecked"}) + public final boolean matches(Object item) { + return item != null + && expectedType.isInstance(item) + && matchesSafely((T) item); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/requests/ClassRequest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/requests/ClassRequest.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,26 @@ +package org.junit.internal.requests; + + +import org.junit.internal.builders.AllDefaultPossibilitiesBuilder; +import org.junit.runner.Request; +import org.junit.runner.Runner; + +public class ClassRequest extends Request { + private final Class fTestClass; + + private boolean fCanUseSuiteMethod; + + public ClassRequest(Class testClass, boolean canUseSuiteMethod) { + fTestClass= testClass; + fCanUseSuiteMethod= canUseSuiteMethod; + } + + public ClassRequest(Class testClass) { + this(testClass, true); + } + + @Override + public Runner getRunner() { + return new AllDefaultPossibilitiesBuilder(fCanUseSuiteMethod).safeRunnerForClass(fTestClass); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/requests/FilterRequest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/requests/FilterRequest.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,43 @@ +/** + * + */ +package org.junit.internal.requests; + +import org.junit.internal.runners.ErrorReportingRunner; +import org.junit.runner.Request; +import org.junit.runner.Runner; +import org.junit.runner.manipulation.Filter; +import org.junit.runner.manipulation.NoTestsRemainException; + +/** + * A filtered {@link Request}. + */ +public final class FilterRequest extends Request { + private final Request fRequest; + private final Filter fFilter; + + /** + * Creates a filtered Request + * @param classRequest a {@link Request} describing your Tests + * @param filter {@link Filter} to apply to the Tests described in + * classRequest + */ + public FilterRequest(Request classRequest, Filter filter) { + fRequest= classRequest; + fFilter= filter; + } + + /** @inheritDoc */ + @Override + public Runner getRunner() { + try { + Runner runner= fRequest.getRunner(); + fFilter.apply(runner); + return runner; + } catch (NoTestsRemainException e) { + return new ErrorReportingRunner(Filter.class, new Exception(String + .format("No tests found matching %s from %s", fFilter + .describe(), fRequest.toString()))); + } + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/requests/SortingRequest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/requests/SortingRequest.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,25 @@ +package org.junit.internal.requests; + +import java.util.Comparator; + +import org.junit.runner.Description; +import org.junit.runner.Request; +import org.junit.runner.Runner; +import org.junit.runner.manipulation.Sorter; + +public class SortingRequest extends Request { + private final Request fRequest; + private final Comparator fComparator; + + public SortingRequest(Request request, Comparator comparator) { + fRequest= request; + fComparator= comparator; + } + + @Override + public Runner getRunner() { + Runner runner= fRequest.getRunner(); + new Sorter(fComparator).apply(runner); + return runner; + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/requests/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/requests/package-info.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,6 @@ +/** + * Provides implementations of {@link org.junit.runner.Request}. + * + * @since 4.0 + */ +package org.junit.internal.requests; \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/ClassRoadie.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/ClassRoadie.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,79 @@ +package org.junit.internal.runners; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; + +import org.junit.runner.Description; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.BlockJUnit4ClassRunner; + +/** + * @deprecated Included for backwards compatibility with JUnit 4.4. Will be + * removed in the next release. Please use + * {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}. + */ +@Deprecated +public +class ClassRoadie { + private RunNotifier fNotifier; + private TestClass fTestClass; + private Description fDescription; + private final Runnable fRunnable; + + public ClassRoadie(RunNotifier notifier, TestClass testClass, + Description description, Runnable runnable) { + fNotifier= notifier; + fTestClass= testClass; + fDescription= description; + fRunnable= runnable; + } + + protected void runUnprotected() { + fRunnable.run(); + }; + + protected void addFailure(Throwable targetException) { + fNotifier.fireTestFailure(new Failure(fDescription, targetException)); + } + + public void runProtected() { + try { + runBefores(); + runUnprotected(); + } catch (FailedBefore e) { + } finally { + runAfters(); + } + } + + private void runBefores() throws FailedBefore { + try { + try { + List befores= fTestClass.getBefores(); + for (Method before : befores) + before.invoke(null); + } catch (InvocationTargetException e) { + throw e.getTargetException(); + } + } catch (org.junit.internal.AssumptionViolatedException e) { + throw new FailedBefore(); + } catch (Throwable e) { + addFailure(e); + throw new FailedBefore(); + } + } + + private void runAfters() { + List afters= fTestClass.getAfters(); + for (Method after : afters) + try { + after.invoke(null); + } catch (InvocationTargetException e) { + addFailure(e.getTargetException()); + } catch (Throwable e) { + addFailure(e); // Untested, but seems impossible + } + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/ErrorReportingRunner.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/ErrorReportingRunner.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,61 @@ +package org.junit.internal.runners; + +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.List; + +import org.junit.runner.Description; +import org.junit.runner.Runner; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.ParentRunner; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.Statement; + +public class ErrorReportingRunner extends Runner { + private final List fCauses; + + private final Class fTestClass; + + public ErrorReportingRunner(Class testClass, Throwable cause) { + fTestClass= testClass; + fCauses= getCauses(cause); + } + + @Override + public Description getDescription() { + Description description= Description.createSuiteDescription(fTestClass); + for (Throwable each : fCauses) + description.addChild(describeCause(each)); + return description; + } + + @Override + public void run(RunNotifier notifier) { + for (Throwable each : fCauses) + runCause(each, notifier); + } + + private List getCauses(Throwable cause) { + if (cause instanceof InvocationTargetException) + return getCauses(cause.getCause()); + if (cause instanceof InitializationError) + return ((InitializationError) cause).getCauses(); + if (cause instanceof org.junit.internal.runners.InitializationError) + return ((org.junit.internal.runners.InitializationError) cause) + .getCauses(); + return Arrays.asList(cause); + } + + private Description describeCause(Throwable child) { + return Description.createTestDescription(fTestClass, + "initializationError"); + } + + private void runCause(Throwable child, RunNotifier notifier) { + Description description= describeCause(child); + notifier.fireTestStarted(description); + notifier.fireTestFailure(new Failure(description, child)); + notifier.fireTestFinished(description); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/FailedBefore.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/FailedBefore.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,14 @@ +package org.junit.internal.runners; + +import org.junit.runners.BlockJUnit4ClassRunner; + + +/** + * @deprecated Included for backwards compatibility with JUnit 4.4. Will be + * removed in the next release. Please use + * {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}. + */ +@Deprecated +class FailedBefore extends Exception { + private static final long serialVersionUID= 1L; +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/InitializationError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/InitializationError.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,29 @@ +package org.junit.internal.runners; + +import java.util.Arrays; +import java.util.List; + +@Deprecated +/** + * Use the published version: {@link org.junit.runners.InitializationError} + */ +public class InitializationError extends Exception { + private static final long serialVersionUID= 1L; + private final List fErrors; + + public InitializationError(List errors) { + fErrors= errors; + } + + public InitializationError(Throwable... errors) { + this(Arrays.asList(errors)); + } + + public InitializationError(String string) { + this(new Exception(string)); + } + + public List getCauses() { + return fErrors; + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/JUnit38ClassRunner.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/JUnit38ClassRunner.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,128 @@ +package org.junit.internal.runners; + +import junit.extensions.TestDecorator; +import junit.framework.AssertionFailedError; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestListener; +import junit.framework.TestResult; +import junit.framework.TestSuite; +import org.junit.runner.Describable; +import org.junit.runner.Description; +import org.junit.runner.Runner; +import org.junit.runner.manipulation.Filter; +import org.junit.runner.manipulation.Filterable; +import org.junit.runner.manipulation.NoTestsRemainException; +import org.junit.runner.manipulation.Sortable; +import org.junit.runner.manipulation.Sorter; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunNotifier; + +public class JUnit38ClassRunner extends Runner implements Filterable, Sortable { + private static final class OldTestClassAdaptingListener implements + TestListener { + private final RunNotifier fNotifier; + + private OldTestClassAdaptingListener(RunNotifier notifier) { + fNotifier= notifier; + } + + public void endTest(Test test) { + fNotifier.fireTestFinished(asDescription(test)); + } + + public void startTest(Test test) { + fNotifier.fireTestStarted(asDescription(test)); + } + + // Implement junit.framework.TestListener + public void addError(Test test, Throwable t) { + Failure failure= new Failure(asDescription(test), t); + fNotifier.fireTestFailure(failure); + } + + private Description asDescription(Test test) { + if (test instanceof Describable) { + Describable facade= (Describable) test; + return facade.getDescription(); + } + return Description.createTestDescription(test.getClass(), getName(test)); + } + + private String getName(Test test) { + if (test instanceof TestCase) + return ((TestCase) test).getName(); + else + return test.toString(); + } + + public void addFailure(Test test, AssertionFailedError t) { + addError(test, t); + } + } + + private Test fTest; + + public JUnit38ClassRunner(Class klass) { + this(new TestSuite(klass.asSubclass(TestCase.class))); + } + + public JUnit38ClassRunner(Test test) { + super(); + fTest= test; + } + + @Override + public void run(RunNotifier notifier) { + TestResult result= new TestResult(); + result.addListener(createAdaptingListener(notifier)); + fTest.run(result); + } + + public static TestListener createAdaptingListener(final RunNotifier notifier) { + return new OldTestClassAdaptingListener(notifier); + } + + @Override + public Description getDescription() { + return makeDescription(fTest); + } + + private Description makeDescription(Test test) { + if (test instanceof TestCase) { + TestCase tc= (TestCase) test; + return Description.createTestDescription(tc.getClass(), tc.getName()); + } else if (test instanceof TestSuite) { + TestSuite ts= (TestSuite) test; + String name= ts.getName() == null ? "" : ts.getName(); + Description description= Description.createSuiteDescription(name); + int n= ts.testCount(); + for (int i= 0; i < n; i++) + description.addChild(makeDescription(ts.testAt(i))); + return description; + } else if (test instanceof Describable) { + Describable adapter= (Describable) test; + return adapter.getDescription(); + } else if (test instanceof TestDecorator) { + TestDecorator decorator= (TestDecorator) test; + return makeDescription(decorator.getTest()); + } else { + // This is the best we can do in this case + return Description.createSuiteDescription(test.getClass()); + } + } + + public void filter(Filter filter) throws NoTestsRemainException { + if (fTest instanceof Filterable) { + Filterable adapter= (Filterable) fTest; + adapter.filter(filter); + } + } + + public void sort(Sorter sorter) { + if (fTest instanceof Sortable) { + Sortable adapter= (Sortable) fTest; + adapter.sort(sorter); + } + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/JUnit4ClassRunner.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/JUnit4ClassRunner.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,143 @@ +package org.junit.internal.runners; + +import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +import org.junit.runner.Description; +import org.junit.runner.Runner; +import org.junit.runner.manipulation.Filter; +import org.junit.runner.manipulation.Filterable; +import org.junit.runner.manipulation.NoTestsRemainException; +import org.junit.runner.manipulation.Sortable; +import org.junit.runner.manipulation.Sorter; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.BlockJUnit4ClassRunner; + +/** + * @deprecated Included for backwards compatibility with JUnit 4.4. Will be + * removed in the next release. Please use + * {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}. + */ +@Deprecated +public class JUnit4ClassRunner extends Runner implements Filterable, Sortable { + private final List fTestMethods; + private TestClass fTestClass; + + public JUnit4ClassRunner(Class klass) throws InitializationError { + fTestClass= new TestClass(klass); + fTestMethods= getTestMethods(); + validate(); + } + + protected List getTestMethods() { + return fTestClass.getTestMethods(); + } + + protected void validate() throws InitializationError { + MethodValidator methodValidator= new MethodValidator(fTestClass); + methodValidator.validateMethodsForDefaultRunner(); + methodValidator.assertValid(); + } + + @Override + public void run(final RunNotifier notifier) { + new ClassRoadie(notifier, fTestClass, getDescription(), new Runnable() { + public void run() { + runMethods(notifier); + } + }).runProtected(); + } + + protected void runMethods(final RunNotifier notifier) { + for (Method method : fTestMethods) + invokeTestMethod(method, notifier); + } + + @Override + public Description getDescription() { + Description spec= Description.createSuiteDescription(getName(), classAnnotations()); + List testMethods= fTestMethods; + for (Method method : testMethods) + spec.addChild(methodDescription(method)); + return spec; + } + + protected Annotation[] classAnnotations() { + return fTestClass.getJavaClass().getAnnotations(); + } + + protected String getName() { + return getTestClass().getName(); + } + + protected Object createTest() throws Exception { + return getTestClass().getConstructor().newInstance(); + } + + protected void invokeTestMethod(Method method, RunNotifier notifier) { + Description description= methodDescription(method); + Object test; + try { + test= createTest(); + } catch (InvocationTargetException e) { + testAborted(notifier, description, e.getCause()); + return; + } catch (Exception e) { + testAborted(notifier, description, e); + return; + } + TestMethod testMethod= wrapMethod(method); + new MethodRoadie(test, testMethod, notifier, description).run(); + } + + private void testAborted(RunNotifier notifier, Description description, + Throwable e) { + notifier.fireTestStarted(description); + notifier.fireTestFailure(new Failure(description, e)); + notifier.fireTestFinished(description); + } + + protected TestMethod wrapMethod(Method method) { + return new TestMethod(method, fTestClass); + } + + protected String testName(Method method) { + return method.getName(); + } + + protected Description methodDescription(Method method) { + return Description.createTestDescription(getTestClass().getJavaClass(), testName(method), testAnnotations(method)); + } + + protected Annotation[] testAnnotations(Method method) { + return method.getAnnotations(); + } + + public void filter(Filter filter) throws NoTestsRemainException { + for (Iterator iter= fTestMethods.iterator(); iter.hasNext();) { + Method method= iter.next(); + if (!filter.shouldRun(methodDescription(method))) + iter.remove(); + } + if (fTestMethods.isEmpty()) + throw new NoTestsRemainException(); + } + + public void sort(final Sorter sorter) { + Collections.sort(fTestMethods, new Comparator() { + public int compare(Method o1, Method o2) { + return sorter.compare(methodDescription(o1), methodDescription(o2)); + } + }); + } + + protected TestClass getTestClass() { + return fTestClass; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/MethodRoadie.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/MethodRoadie.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,157 @@ +package org.junit.internal.runners; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.junit.internal.AssumptionViolatedException; +import org.junit.runner.Description; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.BlockJUnit4ClassRunner; + +/** + * @deprecated Included for backwards compatibility with JUnit 4.4. Will be + * removed in the next release. Please use + * {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}. + */ +@Deprecated +public class MethodRoadie { + private final Object fTest; + private final RunNotifier fNotifier; + private final Description fDescription; + private TestMethod fTestMethod; + + public MethodRoadie(Object test, TestMethod method, RunNotifier notifier, Description description) { + fTest= test; + fNotifier= notifier; + fDescription= description; + fTestMethod= method; + } + + public void run() { + if (fTestMethod.isIgnored()) { + fNotifier.fireTestIgnored(fDescription); + return; + } + fNotifier.fireTestStarted(fDescription); + try { + long timeout= fTestMethod.getTimeout(); + if (timeout > 0) + runWithTimeout(timeout); + else + runTest(); + } finally { + fNotifier.fireTestFinished(fDescription); + } + } + + private void runWithTimeout(final long timeout) { + runBeforesThenTestThenAfters(new Runnable() { + + public void run() { + ExecutorService service= Executors.newSingleThreadExecutor(); + Callable callable= new Callable() { + public Object call() throws Exception { + runTestMethod(); + return null; + } + }; + Future result= service.submit(callable); + service.shutdown(); + try { + boolean terminated= service.awaitTermination(timeout, + TimeUnit.MILLISECONDS); + if (!terminated) + service.shutdownNow(); + result.get(0, TimeUnit.MILLISECONDS); // throws the exception if one occurred during the invocation + } catch (TimeoutException e) { + addFailure(new Exception(String.format("test timed out after %d milliseconds", timeout))); + } catch (Exception e) { + addFailure(e); + } + } + }); + } + + public void runTest() { + runBeforesThenTestThenAfters(new Runnable() { + public void run() { + runTestMethod(); + } + }); + } + + public void runBeforesThenTestThenAfters(Runnable test) { + try { + runBefores(); + test.run(); + } catch (FailedBefore e) { + } catch (Exception e) { + throw new RuntimeException("test should never throw an exception to this level"); + } finally { + runAfters(); + } + } + + protected void runTestMethod() { + try { + fTestMethod.invoke(fTest); + if (fTestMethod.expectsException()) + addFailure(new AssertionError("Expected exception: " + fTestMethod.getExpectedException().getName())); + } catch (InvocationTargetException e) { + Throwable actual= e.getTargetException(); + if (actual instanceof AssumptionViolatedException) + return; + else if (!fTestMethod.expectsException()) + addFailure(actual); + else if (fTestMethod.isUnexpected(actual)) { + String message= "Unexpected exception, expected<" + fTestMethod.getExpectedException().getName() + "> but was<" + + actual.getClass().getName() + ">"; + addFailure(new Exception(message, actual)); + } + } catch (Throwable e) { + addFailure(e); + } + } + + private void runBefores() throws FailedBefore { + try { + try { + List befores= fTestMethod.getBefores(); + for (Method before : befores) + before.invoke(fTest); + } catch (InvocationTargetException e) { + throw e.getTargetException(); + } + } catch (AssumptionViolatedException e) { + throw new FailedBefore(); + } catch (Throwable e) { + addFailure(e); + throw new FailedBefore(); + } + } + + private void runAfters() { + List afters= fTestMethod.getAfters(); + for (Method after : afters) + try { + after.invoke(fTest); + } catch (InvocationTargetException e) { + addFailure(e.getTargetException()); + } catch (Throwable e) { + addFailure(e); // Untested, but seems impossible + } + } + + protected void addFailure(Throwable e) { + fNotifier.fireTestFailure(new Failure(fDescription, e)); + } +} + diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/MethodValidator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/MethodValidator.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,91 @@ +package org.junit.internal.runners; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runners.BlockJUnit4ClassRunner; + +/** + * @deprecated Included for backwards compatibility with JUnit 4.4. Will be + * removed in the next release. Please use + * {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}. + */ +@Deprecated +public class MethodValidator { + + private final List fErrors= new ArrayList(); + + private TestClass fTestClass; + + public MethodValidator(TestClass testClass) { + fTestClass = testClass; + } + + public void validateInstanceMethods() { + validateTestMethods(After.class, false); + validateTestMethods(Before.class, false); + validateTestMethods(Test.class, false); + + List methods= fTestClass.getAnnotatedMethods(Test.class); + if (methods.size() == 0) + fErrors.add(new Exception("No runnable methods")); + } + + public void validateStaticMethods() { + validateTestMethods(BeforeClass.class, true); + validateTestMethods(AfterClass.class, true); + } + + public List validateMethodsForDefaultRunner() { + validateNoArgConstructor(); + validateStaticMethods(); + validateInstanceMethods(); + return fErrors; + } + + public void assertValid() throws InitializationError { + if (!fErrors.isEmpty()) + throw new InitializationError(fErrors); + } + + public void validateNoArgConstructor() { + try { + fTestClass.getConstructor(); + } catch (Exception e) { + fErrors.add(new Exception("Test class should have public zero-argument constructor", e)); + } + } + + private void validateTestMethods(Class annotation, + boolean isStatic) { + List methods= fTestClass.getAnnotatedMethods(annotation); + + for (Method each : methods) { + if (Modifier.isStatic(each.getModifiers()) != isStatic) { + String state= isStatic ? "should" : "should not"; + fErrors.add(new Exception("Method " + each.getName() + "() " + + state + " be static")); + } + if (!Modifier.isPublic(each.getDeclaringClass().getModifiers())) + fErrors.add(new Exception("Class " + each.getDeclaringClass().getName() + + " should be public")); + if (!Modifier.isPublic(each.getModifiers())) + fErrors.add(new Exception("Method " + each.getName() + + " should be public")); + if (each.getReturnType() != Void.TYPE) + fErrors.add(new Exception("Method " + each.getName() + + " should be void")); + if (each.getParameterTypes().length != 0) + fErrors.add(new Exception("Method " + each.getName() + + " should have no parameters")); + } + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/SuiteMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/SuiteMethod.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,40 @@ +package org.junit.internal.runners; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +import junit.framework.Test; + +/** Runner for use with JUnit 3.8.x-style AllTests classes + * (those that only implement a static suite() + * method). For example: + *
+ * @RunWith(AllTests.class)
+ * public class ProductTests {
+ *    public static junit.framework.Test suite() {
+ *       ...
+ *    }
+ * }
+ * 
+ */ +public class SuiteMethod extends JUnit38ClassRunner { + public SuiteMethod(Class klass) throws Throwable { + super(testFromSuiteMethod(klass)); + } + + public static Test testFromSuiteMethod(Class klass) throws Throwable { + Method suiteMethod= null; + Test suite= null; + try { + suiteMethod= klass.getMethod("suite"); + if (! Modifier.isStatic(suiteMethod.getModifiers())) { + throw new Exception(klass.getName() + ".suite() must be static"); + } + suite= (Test) suiteMethod.invoke(null); // static method + } catch (InvocationTargetException e) { + throw e.getCause(); + } + return suite; + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/TestClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/TestClass.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,102 @@ +package org.junit.internal.runners; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runners.BlockJUnit4ClassRunner; + +/** + * @deprecated Included for backwards compatibility with JUnit 4.4. Will be + * removed in the next release. Please use + * {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}. + */ +@Deprecated +public class TestClass { + private final Class fClass; + + public TestClass(Class klass) { + fClass= klass; + } + + public List getTestMethods() { + return getAnnotatedMethods(Test.class); + } + + List getBefores() { + return getAnnotatedMethods(BeforeClass.class); + } + + List getAfters() { + return getAnnotatedMethods(AfterClass.class); + } + + public List getAnnotatedMethods(Class annotationClass) { + List results= new ArrayList(); + for (Class eachClass : getSuperClasses(fClass)) { + Method[] methods= eachClass.getDeclaredMethods(); + for (Method eachMethod : methods) { + Annotation annotation= eachMethod.getAnnotation(annotationClass); + if (annotation != null && ! isShadowed(eachMethod, results)) + results.add(eachMethod); + } + } + if (runsTopToBottom(annotationClass)) + Collections.reverse(results); + return results; + } + + private boolean runsTopToBottom(Class< ? extends Annotation> annotation) { + return annotation.equals(Before.class) || annotation.equals(BeforeClass.class); + } + + private boolean isShadowed(Method method, List results) { + for (Method each : results) { + if (isShadowed(method, each)) + return true; + } + return false; + } + + private boolean isShadowed(Method current, Method previous) { + if (! previous.getName().equals(current.getName())) + return false; + if (previous.getParameterTypes().length != current.getParameterTypes().length) + return false; + for (int i= 0; i < previous.getParameterTypes().length; i++) { + if (! previous.getParameterTypes()[i].equals(current.getParameterTypes()[i])) + return false; + } + return true; + } + + private List> getSuperClasses(Class< ?> testClass) { + ArrayList> results= new ArrayList>(); + Class current= testClass; + while (current != null) { + results.add(current); + current= current.getSuperclass(); + } + return results; + } + + public Constructor getConstructor() throws SecurityException, NoSuchMethodException { + return fClass.getConstructor(); + } + + public Class getJavaClass() { + return fClass; + } + + public String getName() { + return fClass.getName(); + } + +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/TestMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/TestMethod.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,69 @@ +package org.junit.internal.runners; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.Test.None; +import org.junit.runners.BlockJUnit4ClassRunner; + +/** + * @deprecated Included for backwards compatibility with JUnit 4.4. Will be + * removed in the next release. Please use + * {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}. + */ +@Deprecated +public class TestMethod { + private final Method fMethod; + private TestClass fTestClass; + + public TestMethod(Method method, TestClass testClass) { + fMethod= method; + fTestClass= testClass; + } + + public boolean isIgnored() { + return fMethod.getAnnotation(Ignore.class) != null; + } + + public long getTimeout() { + Test annotation= fMethod.getAnnotation(Test.class); + if (annotation == null) + return 0; + long timeout= annotation.timeout(); + return timeout; + } + + protected Class getExpectedException() { + Test annotation= fMethod.getAnnotation(Test.class); + if (annotation == null || annotation.expected() == None.class) + return null; + else + return annotation.expected(); + } + + boolean isUnexpected(Throwable exception) { + return ! getExpectedException().isAssignableFrom(exception.getClass()); + } + + boolean expectsException() { + return getExpectedException() != null; + } + + List getBefores() { + return fTestClass.getAnnotatedMethods(Before.class); + } + + List getAfters() { + return fTestClass.getAnnotatedMethods(After.class); + } + + public void invoke(Object test) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { + fMethod.invoke(test); + } + +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/model/EachTestNotifier.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/model/EachTestNotifier.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,47 @@ +/** + * + */ +package org.junit.internal.runners.model; + + +import org.junit.internal.AssumptionViolatedException; +import org.junit.runner.Description; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunNotifier; + +public class EachTestNotifier { + private final RunNotifier fNotifier; + + private final Description fDescription; + + public EachTestNotifier(RunNotifier notifier, Description description) { + fNotifier= notifier; + fDescription= description; + } + + public void addFailure(Throwable targetException) { + if (targetException instanceof MultipleFailureException) { + MultipleFailureException mfe= (MultipleFailureException) targetException; + for (Throwable each : mfe.getFailures()) + addFailure(each); + return; + } + fNotifier.fireTestFailure(new Failure(fDescription, targetException)); + } + + public void addFailedAssumption(AssumptionViolatedException e) { + fNotifier.fireTestAssumptionFailed(new Failure(fDescription, e)); + } + + public void fireTestFinished() { + fNotifier.fireTestFinished(fDescription); + } + + public void fireTestStarted() { + fNotifier.fireTestStarted(fDescription); + } + + public void fireTestIgnored() { + fNotifier.fireTestIgnored(fDescription); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/model/MultipleFailureException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/model/MultipleFailureException.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,17 @@ +package org.junit.internal.runners.model; + +import java.util.List; + +public class MultipleFailureException extends Exception { + private static final long serialVersionUID= 1L; + + private final List fErrors; + + public MultipleFailureException(List errors) { + fErrors= errors; + } + + public List getFailures() { + return fErrors; + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/model/ReflectiveCallable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/model/ReflectiveCallable.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,22 @@ +/** + * + */ +package org.junit.internal.runners.model; + +import java.lang.reflect.InvocationTargetException; + +/** + * When invoked, throws the exception from the reflected method, rather than + * wrapping it in an InvocationTargetException. + */ +public abstract class ReflectiveCallable { + public Object run() throws Throwable { + try { + return runReflectiveCall(); + } catch (InvocationTargetException e) { + throw e.getTargetException(); + } + } + + protected abstract Object runReflectiveCall() throws Throwable; +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/package-info.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,6 @@ +/** + * Provides implementations of {@link org.junit.runner.Runner} + * + * @since 4.0 + */ +package org.junit.internal.runners; \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/ExpectException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/ExpectException.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,36 @@ +/** + * + */ +package org.junit.internal.runners.statements; + +import org.junit.runners.model.Statement; + + +public class ExpectException extends Statement { + private Statement fNext; + private final Class fExpected; + + public ExpectException(Statement next, Class expected) { + fNext= next; + fExpected= expected; + } + + @Override + public void evaluate() throws Exception { + boolean complete = false; + try { + fNext.evaluate(); + complete = true; + } catch (Throwable e) { + if (!fExpected.isAssignableFrom(e.getClass())) { + String message= "Unexpected exception, expected<" + + fExpected.getName() + "> but was<" + + e.getClass().getName() + ">"; + throw new Exception(message, e); + } + } + if (complete) + throw new AssertionError("Expected exception: " + + fExpected.getName()); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/Fail.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/Fail.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,17 @@ +package org.junit.internal.runners.statements; + +import org.junit.runners.model.Statement; + + +public class Fail extends Statement { + private final Throwable fError; + + public Fail(Throwable e) { + fError= e; + } + + @Override + public void evaluate() throws Throwable { + throw fError; + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/FailOnTimeout.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/FailOnTimeout.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,60 @@ +/** + * + */ +package org.junit.internal.runners.statements; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.junit.runners.model.Statement; + + +public class FailOnTimeout extends Statement { + private Statement fNext; + private final long fTimeout; + + public FailOnTimeout(Statement next, long timeout) { + fNext= next; + fTimeout= timeout; + } + + @Override + public void evaluate() throws Throwable { + ExecutorService service= Executors.newSingleThreadExecutor(); + Callable callable= new Callable() { + public Object call() throws Exception { + try { + fNext.evaluate(); + } catch (Throwable e) { + throw new ExecutionException(e); + } + return null; + } + }; + Future result= service.submit(callable); + service.shutdown(); + try { + boolean terminated= service.awaitTermination(fTimeout, + TimeUnit.MILLISECONDS); + if (!terminated) + service.shutdownNow(); + result.get(0, TimeUnit.MILLISECONDS); // throws the exception if one occurred during the invocation + } catch (TimeoutException e) { + throw new Exception(String.format( + "test timed out after %d milliseconds", fTimeout)); + } catch (ExecutionException e) { + throw unwrap(e); + } + } + + private Throwable unwrap(Throwable e) { + if (e instanceof ExecutionException) + return unwrap(e.getCause()); + return e; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/InvokeMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/InvokeMethod.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,22 @@ +/** + * + */ +package org.junit.internal.runners.statements; + +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.Statement; + +public class InvokeMethod extends Statement { + private final FrameworkMethod fTestMethod; + private Object fTarget; + + public InvokeMethod(FrameworkMethod testMethod, Object target) { + fTestMethod= testMethod; + fTarget= target; + } + + @Override + public void evaluate() throws Throwable { + fTestMethod.invokeExplosively(fTarget); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/RunAfters.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/RunAfters.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,48 @@ +/** + * + */ +package org.junit.internal.runners.statements; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.internal.runners.model.MultipleFailureException; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.Statement; + +public class RunAfters extends Statement { + private final Statement fNext; + + private final Object fTarget; + + private final List fAfters; + + public RunAfters(Statement next, List afters, Object target) { + fNext= next; + fAfters= afters; + fTarget= target; + } + + @Override + public void evaluate() throws Throwable { + List fErrors = new ArrayList(); + fErrors.clear(); + try { + fNext.evaluate(); + } catch (Throwable e) { + fErrors.add(e); + } finally { + for (FrameworkMethod each : fAfters) + try { + each.invokeExplosively(fTarget); + } catch (Throwable e) { + fErrors.add(e); + } + } + if (fErrors.isEmpty()) + return; + if (fErrors.size() == 1) + throw fErrors.get(0); + throw new MultipleFailureException(fErrors); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/RunBefores.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/internal/runners/statements/RunBefores.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,30 @@ +/** + * + */ +package org.junit.internal.runners.statements; + +import java.util.List; + +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.Statement; + +public class RunBefores extends Statement { + private final Statement fNext; + + private final Object fTarget; + + private final List fBefores; + + public RunBefores(Statement next, List befores, Object target) { + fNext= next; + fBefores= befores; + fTarget= target; + } + + @Override + public void evaluate() throws Throwable { + for (FrameworkMethod before : fBefores) + before.invokeExplosively(fTarget); + fNext.evaluate(); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/matchers/JUnitMatchers.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/matchers/JUnitMatchers.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,83 @@ +package org.junit.matchers; + +import org.hamcrest.Matcher; +import org.junit.internal.matchers.CombinableMatcher; +import org.junit.internal.matchers.Each; +import org.junit.internal.matchers.IsCollectionContaining; +import org.junit.internal.matchers.StringContains; + +/** + * Convenience import class: these are useful matchers for use with the assertThat method, but they are + * not currently included in the basic CoreMatchers class from hamcrest. + */ +public class JUnitMatchers { + /** + * @param element + * @return A matcher matching any collection containing element + */ + public static org.hamcrest.Matcher> hasItem(T element) { + return IsCollectionContaining.hasItem(element); + } + + /** + * @param elementMatcher + * @return A matcher matching any collection containing an element matching elementMatcher + */ + public static org.hamcrest.Matcher> hasItem(org.hamcrest.Matcher elementMatcher) { + return IsCollectionContaining.hasItem(elementMatcher); + } + + /** + * @param elements + * @return A matcher matching any collection containing every element in elements + */ + public static org.hamcrest.Matcher> hasItems(T... elements) { + return IsCollectionContaining.hasItems(elements); + } + + /** + * @param elementMatchers + * @return A matcher matching any collection containing at least one element that matches + * each matcher in elementMatcher (this may be one element matching all matchers, + * or different elements matching each matcher) + */ + public static org.hamcrest.Matcher> hasItems(org.hamcrest.Matcher... elementMatchers) { + return IsCollectionContaining.hasItems(elementMatchers); + } + + /** + * @param elementMatcher + * @return A matcher matching any collection in which every element matches elementMatcher + */ + public static Matcher> everyItem(final Matcher elementMatcher) { + return Each.each(elementMatcher); + } + + /** + * @param substring + * @return a matcher matching any string that contains substring + */ + public static org.hamcrest.Matcher containsString(java.lang.String substring) { + return StringContains.containsString(substring); + } + + /** + * This is useful for fluently combining matchers that must both pass. For example: + *
+	 *   assertThat(string, both(containsString("a")).and(containsString("b")));
+	 * 
+ */ + public static CombinableMatcher both(Matcher matcher) { + return new CombinableMatcher(matcher); + } + + /** + * This is useful for fluently combining matchers where either may pass, for example: + *
+	 *   assertThat(string, both(containsString("a")).and(containsString("b")));
+	 * 
+ */ + public static CombinableMatcher either(Matcher matcher) { + return new CombinableMatcher(matcher); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/package-info.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,8 @@ +/** + * Provides JUnit core classes and annotations. + * + * Corresponds to junit.framework in Junit 3.x. + * + * @since 4.0 + */ +package org.junit; \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/Describable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/Describable.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,12 @@ +package org.junit.runner; + + +/** + * + */ +public interface Describable { + /** + * @return a {@link Description} showing the tests to be run by the receiver + */ + public abstract Description getDescription(); +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/Description.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/Description.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,192 @@ +package org.junit.runner; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; + +/** + *

A Description describes a test which is to be run or has been run. Descriptions + * can be atomic (a single test) or compound (containing children tests). Descriptions are used + * to provide feedback about the tests that are about to run (for example, the tree view + * visible in many IDEs) or tests that have been run (for example, the failures view).

+ * + *

Descriptions are implemented as a single class rather than a Composite because + * they are entirely informational. They contain no logic aside from counting their tests.

+ * + *

In the past, we used the raw {@link junit.framework.TestCase}s and {@link junit.framework.TestSuite}s + * to display the tree of tests. This was no longer viable in JUnit 4 because atomic tests no longer have + * a superclass below {@link Object}. We needed a way to pass a class and name together. Description + * emerged from this.

+ * + * @see org.junit.runner.Request + * @see org.junit.runner.Runner + */ +public class Description { + + /** + * Create a Description named name. + * Generally, you will add children to this Description. + * @param name the name of the Description + * @param annotations + * @return a Description named name + */ + public static Description createSuiteDescription(String name, Annotation... annotations) { + return new Description(name, annotations); + } + + /** + * Create a Description of a single test named name in the class clazz. + * Generally, this will be a leaf Description. + * @param clazz the class of the test + * @param name the name of the test (a method name for test annotated with {@link org.junit.Test}) + * @param annotations meta-data about the test, for downstream interpreters + * @return a Description named name + */ + public static Description createTestDescription(Class clazz, String name, Annotation... annotations) { + return new Description(String.format("%s(%s)", name, clazz.getName()), annotations); + } + + /** + * Create a Description of a single test named name in the class clazz. + * Generally, this will be a leaf Description. + * (This remains for binary compatibility with clients of JUnit 4.3) + * @param clazz the class of the test + * @param name the name of the test (a method name for test annotated with {@link org.junit.Test}) + * @return a Description named name + */ + public static Description createTestDescription(Class clazz, String name) { + return createTestDescription(clazz, name, new Annotation[0]); + } + + /** + * Create a Description named after testClass + * @param testClass A {@link Class} containing tests + * @return a Description of testClass + */ + public static Description createSuiteDescription(Class testClass) { + return new Description(testClass.getName(), testClass.getAnnotations()); + } + + /** + * Describes a Runner which runs no tests + */ + public static final Description EMPTY= new Description("No Tests"); + + /** + * Describes a step in the test-running mechanism that goes so wrong no + * other description can be used (for example, an exception thrown from a Runner's + * constructor + */ + public static final Description TEST_MECHANISM= new Description("Test mechanism"); + + private final ArrayList fChildren= new ArrayList(); + private final String fDisplayName; + + private final Annotation[] fAnnotations; + + private Description(final String displayName, Annotation... annotations) { + fDisplayName= displayName; + fAnnotations= annotations; + } + + /** + * @return a user-understandable label + */ + public String getDisplayName() { + return fDisplayName; + } + + /** + * Add Description as a child of the receiver. + * @param description the soon-to-be child. + */ + public void addChild(Description description) { + getChildren().add(description); + } + + /** + * @return the receiver's children, if any + */ + public ArrayList getChildren() { + return fChildren; + } + + /** + * @return true if the receiver is a suite + */ + public boolean isSuite() { + return !isTest(); + } + + /** + * @return true if the receiver is an atomic test + */ + public boolean isTest() { + return getChildren().isEmpty(); + } + + /** + * @return the total number of atomic tests in the receiver + */ + public int testCount() { + if (isTest()) + return 1; + int result= 0; + for (Description child : getChildren()) + result+= child.testCount(); + return result; + } + + @Override + public int hashCode() { + return getDisplayName().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Description)) + return false; + Description d = (Description) obj; + return getDisplayName().equals(d.getDisplayName()) + && getChildren().equals(d.getChildren()); + } + + @Override + public String toString() { + return getDisplayName(); + } + + /** + * @return true if this is a description of a Runner that runs no tests + */ + public boolean isEmpty() { + return equals(EMPTY); + } + + /** + * @return a copy of this description, with no children (on the assumption that some of the + * children will be added back) + */ + public Description childlessCopy() { + return new Description(fDisplayName, fAnnotations); + } + + /** + * @return the annotation of type annotationType that is attached to this description node, + * or null if none exists + */ + public T getAnnotation(Class annotationType) { + for (Annotation each : fAnnotations) + if (each.annotationType().equals(annotationType)) + return annotationType.cast(each); + return null; + } + + /** + * @return all of the annotations attached to this description node + */ + public Collection getAnnotations() { + return Arrays.asList(fAnnotations); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/JUnitCore.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/JUnitCore.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,166 @@ +package org.junit.runner; + +import java.util.ArrayList; +import java.util.List; + +import junit.runner.Version; +import org.junit.internal.JUnitSystem; +import org.junit.internal.RealSystem; +import org.junit.internal.TextListener; +import org.junit.internal.runners.JUnit38ClassRunner; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunListener; +import org.junit.runner.notification.RunNotifier; + +/** + * JUnitCore is a facade for running tests. It supports running JUnit 4 tests, + * JUnit 3.8.x tests, and mixtures. To run tests from the command line, run + * java org.junit.runner.JUnitCore TestClass1 TestClass2 .... + * For one-shot test runs, use the static method {@link #runClasses(Class[])}. + * If you want to add special listeners, + * create an instance of {@link org.junit.runner.JUnitCore} first and use it to run the tests. + * + * @see org.junit.runner.Result + * @see org.junit.runner.notification.RunListener + * @see org.junit.runner.Request + */ +public class JUnitCore { + + private RunNotifier fNotifier; + + /** + * Create a new JUnitCore to run tests. + */ + public JUnitCore() { + fNotifier= new RunNotifier(); + } + + /** + * Run the tests contained in the classes named in the args. + * If all tests run successfully, exit with a status of 0. Otherwise exit with a status of 1. + * Write feedback while tests are running and write + * stack traces for all failed tests after the tests all complete. + * @param args names of classes in which to find tests to run + */ + public static void main(String... args) { + runMainAndExit(new RealSystem(), args); + } + + /** + * Do not use. Testing purposes only. + * @param system + */ + public static void runMainAndExit(JUnitSystem system, String... args) { + Result result= new JUnitCore().runMain(system, args); + system.exit(result.wasSuccessful() ? 0 : 1); + } + + /** + * Run the tests contained in classes. Write feedback while the tests + * are running and write stack traces for all failed tests after all tests complete. This is + * similar to {@link #main(String[])}, but intended to be used programmatically. + * @param classes Classes in which to find tests + * @return a {@link Result} describing the details of the test run and the failed tests. + */ + public static Result runClasses(Class... classes) { + return new JUnitCore().run(classes); + } + + /** + * Do not use. Testing purposes only. + * @param system + */ + public Result runMain(JUnitSystem system, String... args) { + system.out().println("JUnit version " + Version.id()); + List> classes= new ArrayList>(); + List missingClasses= new ArrayList(); + for (String each : args) + try { + classes.add(Class.forName(each)); + } catch (ClassNotFoundException e) { + system.out().println("Could not find class: " + each); + Description description= Description.createSuiteDescription(each); + Failure failure= new Failure(description, e); + missingClasses.add(failure); + } + RunListener listener= new TextListener(system); + addListener(listener); + Result result= run(classes.toArray(new Class[0])); + for (Failure each : missingClasses) + result.getFailures().add(each); + return result; + } + + /** + * @return the version number of this release + */ + public String getVersion() { + return Version.id(); + } + + /** + * Run all the tests in classes. + * @param classes the classes containing tests + * @return a {@link Result} describing the details of the test run and the failed tests. + */ + public Result run(Class... classes) { + return run(Request.classes(classes)); + } + + /** + * Run all the tests contained in request. + * @param request the request describing tests + * @return a {@link Result} describing the details of the test run and the failed tests. + */ + public Result run(Request request) { + return run(request.getRunner()); + } + + /** + * Run all the tests contained in JUnit 3.8.x test. Here for backward compatibility. + * @param test the old-style test + * @return a {@link Result} describing the details of the test run and the failed tests. + */ + public Result run(junit.framework.Test test) { + return run(new JUnit38ClassRunner(test)); + } + + /** + * Do not use. Testing purposes only. + */ + public Result run(Runner runner) { + Result result= new Result(); + RunListener listener= result.createListener(); + addFirstListener(listener); + try { + fNotifier.fireTestRunStarted(runner.getDescription()); + runner.run(fNotifier); + fNotifier.fireTestRunFinished(result); + } finally { + removeListener(listener); + } + return result; + } + + private void addFirstListener(RunListener listener) { + fNotifier.addFirstListener(listener); + } + + + /** + * Add a listener to be notified as the tests run. + * @param listener the listener to add + * @see org.junit.runner.notification.RunListener + */ + public void addListener(RunListener listener) { + fNotifier.addListener(listener); + } + + /** + * Remove a listener. + * @param listener the listener to remove + */ + public void removeListener(RunListener listener) { + fNotifier.removeListener(listener); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/Request.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/Request.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,165 @@ +package org.junit.runner; + +import java.util.Comparator; + +import org.junit.internal.builders.AllDefaultPossibilitiesBuilder; +import org.junit.internal.requests.ClassRequest; +import org.junit.internal.requests.FilterRequest; +import org.junit.internal.requests.SortingRequest; +import org.junit.internal.runners.ErrorReportingRunner; +import org.junit.runner.manipulation.Filter; +import org.junit.runners.Suite; +import org.junit.runners.model.InitializationError; + +/** + *

A Request is an abstract description of tests to be run. Older versions of + * JUnit did not need such a concept--tests to be run were described either by classes containing + * tests or a tree of {@link org.junit.Test}s. However, we want to support filtering and sorting, + * so we need a more abstract specification than the tests themselves and a richer + * specification than just the classes.

+ * + *

The flow when JUnit runs tests is that a Request specifies some tests to be run -> + * a {@link org.junit.runner.Runner} is created for each class implied by the Request -> + * the {@link org.junit.runner.Runner} returns a detailed {@link org.junit.runner.Description} + * which is a tree structure of the tests to be run.

+ */ +public abstract class Request { + /** + * Create a Request that, when processed, will run a single test. + * This is done by filtering out all other tests. This method is used to support rerunning + * single tests. + * @param clazz the class of the test + * @param methodName the name of the test + * @return a Request that will cause a single test be run + */ + public static Request method(Class clazz, String methodName) { + Description method= Description.createTestDescription(clazz, methodName); + return Request.aClass(clazz).filterWith(method); + } + + /** + * Create a Request that, when processed, will run all the tests + * in a class. The odd name is necessary because class is a reserved word. + * @param clazz the class containing the tests + * @return a Request that will cause all tests in the class to be run + */ + public static Request aClass(Class clazz) { + return new ClassRequest(clazz); + } + + /** + * Create a Request that, when processed, will run all the tests + * in a class. If the class has a suite() method, it will be ignored. + * @param clazz the class containing the tests + * @return a Request that will cause all tests in the class to be run + */ + public static Request classWithoutSuiteMethod(Class clazz) { + return new ClassRequest(clazz, false); + } + + /** + * Create a Request that, when processed, will run all the tests + * in a set of classes. + * @param classes the classes containing the tests + * @return a Request that will cause all tests in the classes to be run + */ + public static Request classes(Class... classes) { + try { + return runner(new Suite(new AllDefaultPossibilitiesBuilder(true), classes)); + } catch (InitializationError e) { + throw new RuntimeException( + "Bug in saff's brain: Suite constructor, called as above, should always complete"); + } + } + + /** + * Not used within JUnit. Clients should simply instantiate ErrorReportingRunner themselves + */ + @Deprecated + public static Request errorReport(Class klass, Throwable cause) { + return runner(new ErrorReportingRunner(klass, cause)); + } + + /** + * @param runner the runner to return + * @return a Request that will run the given runner when invoked + */ + public static Request runner(final Runner runner) { + return new Request(){ + @Override + public Runner getRunner() { + return runner; + } + }; + } + + /** + * Returns a {@link Runner} for this Request + * @return corresponding {@link Runner} for this Request + */ + public abstract Runner getRunner(); + + /** + * Returns a Request that only contains those tests that should run when + * filter is applied + * @param filter The {@link Filter} to apply to this Request + * @return the filtered Request + */ + public Request filterWith(Filter filter) { + return new FilterRequest(this, filter); + } + + /** + * Returns a Request that only runs contains tests whose {@link Description} + * equals desiredDescription + * @param desiredDescription {@link Description} of those tests that should be run + * @return the filtered Request + */ + public Request filterWith(final Description desiredDescription) { + return filterWith(new Filter() { + @Override + public boolean shouldRun(Description description) { + if (description.isTest()) + return desiredDescription.equals(description); + + // explicitly check if any children want to run + for (Description each : description.getChildren()) + if (shouldRun(each)) + return true; + return false; + } + + @Override + public String describe() { + return String.format("Method %s", desiredDescription.getDisplayName()); + } + }); + } + + /** + * Returns a Request whose Tests can be run in a certain order, defined by + * comparator + * + * For example, here is code to run a test suite in alphabetical order: + * + *
+	private static Comparator forward() {
+		return new Comparator() {
+			public int compare(Description o1, Description o2) {
+				return o1.getDisplayName().compareTo(o2.getDisplayName());
+			}
+		};
+	}
+	
+	public static main() {
+		new JUnitCore().run(Request.aClass(AllTests.class).sortWith(forward()));
+	}
+	 * 
+ * + * @param comparator definition of the order of the tests in this Request + * @return a Request with ordered Tests + */ + public Request sortWith(Comparator comparator) { + return new SortingRequest(this, comparator); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/Result.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/Result.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,107 @@ +package org.junit.runner; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunListener; + +/** + * A Result collects and summarizes information from running multiple + * tests. Since tests are expected to run correctly, successful tests are only noted in + * the count of tests that ran. + */ +public class Result { + private int fCount= 0; + private int fIgnoreCount= 0; + private final List fFailures= new ArrayList(); + private long fRunTime= 0; + private long fStartTime; + + /** + * @return the number of tests run + */ + public int getRunCount() { + return fCount; + } + + /** + * @return the number of tests that failed during the run + */ + public int getFailureCount() { + return fFailures.size(); + } + + /** + * @return the number of milliseconds it took to run the entire suite to run + */ + public long getRunTime() { + return fRunTime; + } + + /** + * @return the {@link Failure}s describing tests that failed and the problems they encountered + */ + public List getFailures() { + return fFailures; + } + + /** + * @return the number of tests ignored during the run + */ + public int getIgnoreCount() { + return fIgnoreCount; + } + + /** + * @return true if all tests succeeded + */ + public boolean wasSuccessful() { + return getFailureCount() == 0; + } + + private class Listener extends RunListener { + private boolean fIgnoredDuringExecution= false; + + @Override + public void testRunStarted(Description description) throws Exception { + fStartTime= System.currentTimeMillis(); + } + + @Override + public void testRunFinished(Result result) throws Exception { + long endTime= System.currentTimeMillis(); + fRunTime+= endTime - fStartTime; + } + + @Override + public void testFinished(Description description) throws Exception { + if (!fIgnoredDuringExecution) + fCount++; + fIgnoredDuringExecution= false; + } + + @Override + public void testFailure(Failure failure) throws Exception { + fFailures.add(failure); + } + + @Override + public void testIgnored(Description description) throws Exception { + fIgnoreCount++; + fIgnoredDuringExecution= true; + } + + @Override + public void testAssumptionFailure(Failure failure) { + // do nothing: same as passing (for 4.5; may change in 4.6) + } + } + + /** + * Internal use only. + */ + public RunListener createListener() { + return new Listener(); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/RunWith.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/RunWith.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,34 @@ +package org.junit.runner; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * When a class is annotated with @RunWith or extends a class annotated + * with @RunWith, JUnit will invoke the class it references to run the + * tests in that class instead of the runner built into JUnit. We added this feature late + * in development. While it seems powerful we expect the runner API to change as we learn + * how people really use it. Some of the classes that are currently internal will likely + * be refined and become public. + * + * For example, suites in JUnit 4 are built using RunWith, and a custom runner named Suite: + * + *
+ * @RunWith(Suite.class)
+ * @SuiteClasses(ATest.class, BTest.class, CTest.class)
+ * public class ABCSuite {
+ * }
+ * 
+ */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface RunWith { + /** + * @return a Runner class (must have a constructor that takes a single Class to run) + */ + Class value(); +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/Runner.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/Runner.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,40 @@ +package org.junit.runner; + +import org.junit.runner.notification.RunNotifier; + +/** + * A Runner runs tests and notifies a {@link org.junit.runner.notification.RunNotifier} + * of significant events as it does so. You will need to subclass Runner + * when using {@link org.junit.runner.RunWith} to invoke a custom runner. When creating + * a custom runner, in addition to implementing the abstract methods here you must + * also provide a constructor that takes as an argument the {@link Class} containing + * the tests. + *

+ * The default runner implementation guarantees that the instances of the test case + * class will be constructed immediately before running the test and that the runner + * will retain no reference to the test case instances, generally making them + * available for garbage collection. + * + * @see org.junit.runner.Description + * @see org.junit.runner.RunWith + */ +public abstract class Runner implements Describable { + /* (non-Javadoc) + * @see org.junit.runner.Describable#getDescription() + */ + public abstract Description getDescription(); + + /** + * Run the tests for this runner. + * @param notifier will be notified of events while tests are being run--tests being + * started, finishing, and failing + */ + public abstract void run(RunNotifier notifier); + + /** + * @return the number of tests to be run by the receiver + */ + public int testCount() { + return getDescription().testCount(); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/manipulation/Filter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/manipulation/Filter.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,55 @@ +package org.junit.runner.manipulation; + +import org.junit.runner.Description; +import org.junit.runner.Request; + +/** + * The canonical case of filtering is when you want to run a single test method in a class. Rather + * than introduce runner API just for that one case, JUnit provides a general filtering mechanism. + * If you want to filter the tests to be run, extend Filter and apply an instance of + * your filter to the {@link org.junit.runner.Request} before running it (see + * {@link org.junit.runner.JUnitCore#run(Request)}. Alternatively, apply a Filter to + * a {@link org.junit.runner.Runner} before running tests (for example, in conjunction with + * {@link org.junit.runner.RunWith}. + */ +public abstract class Filter { + /** + * A null Filter that passes all tests through. + */ + public static Filter ALL= new Filter() { + @Override + public boolean shouldRun(Description description) { + return true; + } + + @Override + public String describe() { + return "all tests"; + } + }; + + /** + * @param description the description of the test to be run + * @return true if the test should be run + */ + public abstract boolean shouldRun(Description description); + + /** + * Returns a textual description of this Filter + * @return a textual description of this Filter + */ + public abstract String describe(); + + /** + * Invoke with a {@link org.junit.runner.Runner} to cause all tests it intends to run + * to first be checked with the filter. Only those that pass the filter will be run. + * @param child the runner to be filtered by the receiver + * @throws NoTestsRemainException if the receiver removes all tests + */ + public void apply(Object child) throws NoTestsRemainException { + if (!(child instanceof Filterable)) + return; + Filterable filterable= (Filterable) child; + filterable.filter(this); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/manipulation/Filterable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/manipulation/Filterable.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,16 @@ +package org.junit.runner.manipulation; + +/** + * Runners that allow filtering should implement this interface. Implement {@link #filter(Filter)} + * to remove tests that don't pass the filter. + */ +public interface Filterable { + + /** + * Remove tests that don't pass the parameter filter. + * @param filter the {@link Filter} to apply + * @throws NoTestsRemainException if all tests are filtered out + */ + void filter(Filter filter) throws NoTestsRemainException; + +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/manipulation/NoTestsRemainException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/manipulation/NoTestsRemainException.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,8 @@ +package org.junit.runner.manipulation; + +/** + * Thrown when a filter removes all tests from a runner. + */ +public class NoTestsRemainException extends Exception { + private static final long serialVersionUID = 1L; +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/manipulation/Sortable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/manipulation/Sortable.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,17 @@ +package org.junit.runner.manipulation; + +/** + * Interface for runners that allow sorting of tests. By sorting tests based on when they last failed, most recently + * failed first, you can reduce the average time to the first test failing. Test sorting should not be used to + * cope with order dependencies between tests. Tests that are isolated from each other are less + * expensive to maintain and can be run individually. + */ +public interface Sortable { + + /** + * Sorts the tests using sorter + * @param sorter the {@link Sorter} to use for sorting the tests + */ + public void sort(Sorter sorter); + +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/manipulation/Sorter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/manipulation/Sorter.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,47 @@ +package org.junit.runner.manipulation; + +import java.util.Comparator; + +import org.junit.runner.Description; + +/** + * A Sorter orders tests. In general you will not need + * to use a Sorter directly. Instead, use {@link org.junit.runner.Request#sortWith(Comparator)}. + * + * + */ +public class Sorter implements Comparator { + /** + * NULL is a Sorter that leaves elements in an undefined order + */ + public static Sorter NULL= new Sorter(new Comparator() { + public int compare(Description o1, Description o2) { + return 0; + }}); + private final Comparator fComparator; + + /** + * Creates a Sorter that uses comparator + * to sort tests + * @param comparator the {@link Comparator} to use when sorting tests + */ + public Sorter(Comparator comparator) { + fComparator= comparator; + } + + /** + * Sorts the test in runner using comparator + * @param object + */ + public void apply(Object object) { + if (object instanceof Sortable) { + Sortable sortable = (Sortable) object; + sortable.sort(this); + } + } + + /** @inheritDoc */ + public int compare(Description o1, Description o2) { + return fComparator.compare(o1, o2); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/manipulation/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/manipulation/package-info.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,7 @@ +/** + * Provides classes to {@link org.junit.runner.manipulation.Filter filter} or {@link org.junit.runner.manipulation.Sorter sort} tests. + * + * @since 4.0 + * @see org.junit.runner.Runner + */ +package org.junit.runner.manipulation; \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/notification/Failure.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/notification/Failure.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,77 @@ +package org.junit.runner.notification; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.junit.runner.Description; + +/** + * A Failure holds a description of the failed test and the + * exception that was thrown while running it. In most cases the {@link org.junit.runner.Description} + * will be of a single test. However, if problems are encountered while constructing the + * test (for example, if a {@link org.junit.BeforeClass} method is not static), it may describe + * something other than a single test. + */ +public class Failure { + private final Description fDescription; + private final Throwable fThrownException; + + /** + * Constructs a Failure with the given description and exception. + * @param description a {@link org.junit.runner.Description} of the test that failed + * @param thrownException the exception that was thrown while running the test + */ + public Failure(Description description, Throwable thrownException) { + fThrownException = thrownException; + fDescription= description; + } + + /** + * @return a user-understandable label for the test + */ + public String getTestHeader() { + return fDescription.getDisplayName(); + } + + /** + * @return the raw description of the context of the failure. + */ + public Description getDescription() { + return fDescription; + } + + /** + * @return the exception thrown + */ + + public Throwable getException() { + return fThrownException; + } + + @Override + public String toString() { + StringBuffer buffer= new StringBuffer(); + buffer.append(getTestHeader() + ": "+fThrownException.getMessage()); + return buffer.toString(); + } + + /** + * Convenience method + * @return the printed form of the exception + */ + public String getTrace() { + StringWriter stringWriter= new StringWriter(); + PrintWriter writer= new PrintWriter(stringWriter); + getException().printStackTrace(writer); + StringBuffer buffer= stringWriter.getBuffer(); + return buffer.toString(); + } + + /** + * Convenience method + * @return the message of the thrown exception + */ + public String getMessage() { + return getException().getMessage(); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/notification/RunListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/notification/RunListener.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,93 @@ +package org.junit.runner.notification; + +import org.junit.internal.AssumptionViolatedException; +import org.junit.runner.Description; +import org.junit.runner.Result; + +/** + *

If you need to respond to the events during a test run, extend RunListener + * and override the appropriate methods. If a listener throws an exception while processing a + * test event, it will be removed for the remainder of the test run.

+ * + *

For example, suppose you have a Cowbell + * class that you want to make a noise whenever a test fails. You could write: + *

+ * public class RingingListener extends RunListener {
+ *    public void testFailure(Failure failure) {
+ *       Cowbell.ring();
+ *    }
+ * }
+ * 
+ *

+ * + *

To invoke your listener, you need to run your tests through JUnitCore. + *

+ * public void main(String... args) {
+ *    JUnitCore core= new JUnitCore();
+ *    core.addListener(new RingingListener());
+ *    core.run(MyTestClass.class);
+ * }
+ * 
+ *

+ * @see org.junit.runner.JUnitCore + */ +public class RunListener { + + /** + * Called before any tests have been run. + * @param description describes the tests to be run + */ + public void testRunStarted(Description description) throws Exception { + } + + /** + * Called when all tests have finished + * @param result the summary of the test run, including all the tests that failed + */ + public void testRunFinished(Result result) throws Exception { + } + + /** + * Called when an atomic test is about to be started. + * @param description the description of the test that is about to be run + * (generally a class and method name) + */ + public void testStarted(Description description) throws Exception { + } + + /** + * Called when an atomic test has finished, whether the test succeeds or fails. + * @param description the description of the test that just ran + */ + public void testFinished(Description description) throws Exception { + } + + /** + * Called when an atomic test fails. + * @param failure describes the test that failed and the exception that was thrown + */ + public void testFailure(Failure failure) throws Exception { + } + + /** + * Called when an atomic test flags that it assumes a condition that is + * false + * + * @param failure + * describes the test that failed and the + * {@link AssumptionViolatedException} that was thrown + */ + public void testAssumptionFailure(Failure failure) { + } + + /** + * Called when a test will not be run, generally because a test method is annotated + * with {@link org.junit.Ignore}. + * + * @param description describes the test that will not be run + */ + public void testIgnored(Description description) throws Exception { + } +} + + diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/notification/RunNotifier.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/notification/RunNotifier.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,162 @@ +package org.junit.runner.notification; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.junit.internal.AssumptionViolatedException; +import org.junit.runner.Description; +import org.junit.runner.Result; + +/** + * If you write custom runners, you may need to notify JUnit of your progress running tests. + * Do this by invoking the RunNotifier passed to your implementation of + * {@link org.junit.runner.Runner#run(RunNotifier)}. Future evolution of this class is likely to + * move {@link #fireTestRunStarted(Description)} and {@link #fireTestRunFinished(Result)} + * to a separate class since they should only be called once per run. + */ +public class RunNotifier { + private final List fListeners= new ArrayList(); + private boolean fPleaseStop= false; + + /** Internal use only + */ + public void addListener(RunListener listener) { + fListeners.add(listener); + } + + /** Internal use only + */ + public void removeListener(RunListener listener) { + fListeners.remove(listener); + } + + private abstract class SafeNotifier { + void run() { + for (Iterator all= fListeners.iterator(); all.hasNext();) + try { + notifyListener(all.next()); + } catch (Exception e) { + all.remove(); // Remove the offending listener first to avoid an infinite loop + fireTestFailure(new Failure(Description.TEST_MECHANISM, e)); + } + } + + abstract protected void notifyListener(RunListener each) throws Exception; + } + + /** + * Do not invoke. + */ + public void fireTestRunStarted(final Description description) { + new SafeNotifier() { + @Override + protected void notifyListener(RunListener each) throws Exception { + each.testRunStarted(description); + }; + }.run(); + } + + /** + * Do not invoke. + */ + public void fireTestRunFinished(final Result result) { + new SafeNotifier() { + @Override + protected void notifyListener(RunListener each) throws Exception { + each.testRunFinished(result); + }; + }.run(); + } + + /** + * Invoke to tell listeners that an atomic test is about to start. + * @param description the description of the atomic test (generally a class and method name) + * @throws StoppedByUserException thrown if a user has requested that the test run stop + */ + public void fireTestStarted(final Description description) throws StoppedByUserException { + if (fPleaseStop) + throw new StoppedByUserException(); + new SafeNotifier() { + @Override + protected void notifyListener(RunListener each) throws Exception { + each.testStarted(description); + }; + }.run(); + } + + /** + * Invoke to tell listeners that an atomic test failed. + * @param failure the description of the test that failed and the exception thrown + */ + public void fireTestFailure(final Failure failure) { + new SafeNotifier() { + @Override + protected void notifyListener(RunListener each) throws Exception { + each.testFailure(failure); + }; + }.run(); + } + + /** + * Invoke to tell listeners that an atomic test flagged that it assumed + * something false. + * + * @param failure + * the description of the test that failed and the + * {@link AssumptionViolatedException} thrown + */ + public void fireTestAssumptionFailed(final Failure failure) { + new SafeNotifier() { + @Override + protected void notifyListener(RunListener each) throws Exception { + each.testAssumptionFailure(failure); + }; + }.run(); + } + + /** + * Invoke to tell listeners that an atomic test was ignored. + * @param description the description of the ignored test + */ + public void fireTestIgnored(final Description description) { + new SafeNotifier() { + @Override + protected void notifyListener(RunListener each) throws Exception { + each.testIgnored(description); + } + }.run(); + } + + /** + * Invoke to tell listeners that an atomic test finished. Always invoke + * {@link #fireTestFinished(Description)} if you invoke {@link #fireTestStarted(Description)} + * as listeners are likely to expect them to come in pairs. + * @param description the description of the test that finished + */ + public void fireTestFinished(final Description description) { + new SafeNotifier() { + @Override + protected void notifyListener(RunListener each) throws Exception { + each.testFinished(description); + }; + }.run(); + } + + /** + * Ask that the tests run stop before starting the next test. Phrased politely because + * the test currently running will not be interrupted. It seems a little odd to put this + * functionality here, but the RunNotifier is the only object guaranteed + * to be shared amongst the many runners involved. + */ + public void pleaseStop() { + fPleaseStop= true; + } + + /** + * Internal use only. The Result's listener must be first. + */ + public void addFirstListener(RunListener listener) { + fListeners.add(0, listener); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/notification/StoppedByUserException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/notification/StoppedByUserException.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,11 @@ +package org.junit.runner.notification; + +/** + * Thrown when a user has requested that the test run stop. Writers of + * test running GUIs should be prepared to catch a StoppedByUserException. + * + * @see org.junit.runner.notification.RunNotifier + */ +public class StoppedByUserException extends RuntimeException { + private static final long serialVersionUID= 1L; +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/notification/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/notification/package-info.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,6 @@ +/** + * Provides information about a test run. + * + * @since 4.0 + */ +package org.junit.runner.notification; \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runner/package-info.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,6 @@ +/** + * Provides classes used to describe, collect, run and analyze multiple tests. + * + * @since 4.0 + */ +package org.junit.runner; \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/AllTests.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/AllTests.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,24 @@ +package org.junit.runners; + +import org.junit.internal.runners.SuiteMethod; + +/** Runner for use with JUnit 3.8.x-style AllTests classes + * (those that only implement a static suite() + * method). For example: + *
+ * @RunWith(AllTests.class)
+ * public class ProductTests {
+ *    public static junit.framework.Test suite() {
+ *       ...
+ *    }
+ * }
+ * 
+ */ +public class AllTests extends SuiteMethod { + /** + * Only called reflectively. Do not use programmatically. + */ + public AllTests(Class klass) throws Throwable { + super(klass); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/BlockJUnit4ClassRunner.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/BlockJUnit4ClassRunner.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,314 @@ +package org.junit.runners; + +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.Test.None; +import org.junit.internal.AssumptionViolatedException; +import org.junit.internal.runners.model.EachTestNotifier; +import org.junit.internal.runners.model.MultipleFailureException; +import org.junit.internal.runners.model.ReflectiveCallable; +import org.junit.internal.runners.statements.ExpectException; +import org.junit.internal.runners.statements.Fail; +import org.junit.internal.runners.statements.FailOnTimeout; +import org.junit.internal.runners.statements.InvokeMethod; +import org.junit.internal.runners.statements.RunAfters; +import org.junit.internal.runners.statements.RunBefores; +import org.junit.runner.Description; +import org.junit.runner.manipulation.Filterable; +import org.junit.runner.manipulation.Sortable; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.Statement; + +/** + * Implements the JUnit 4 standard test case class model, as defined by the + * annotations in the org.junit package. Many users will never notice this + * class: it is now the default test class runner, but it should have exactly + * the same behavior as the old test class runner ({@code JUnit4ClassRunner}). + * + * BlockJUnit4ClassRunner has advantages for writers of custom JUnit runners + * that are slight changes to the default behavior, however: + * + *
    + *
  • It has a much simpler implementation based on {@link Statement}s, + * allowing new operations to be inserted into the appropriate point in the + * execution flow. + * + *
  • It is published, and extension and reuse are encouraged, whereas {@code + * JUnit4ClassRunner} was in an internal package, and is now deprecated. + *
+ */ +public class BlockJUnit4ClassRunner extends ParentRunner + implements Filterable, Sortable { + + /** + * Creates a BlockJUnit4ClassRunner to run {@code klass} + * + * @throws InitializationError + * if the test class is malformed. + */ + public BlockJUnit4ClassRunner(Class klass) throws InitializationError { + super(klass); + } + + // + // Implementation of ParentRunner + // + + @Override + protected void runChild(FrameworkMethod method, RunNotifier notifier) { + EachTestNotifier eachNotifier= makeNotifier(method, notifier); + if (method.getAnnotation(Ignore.class) != null) { + eachNotifier.fireTestIgnored(); + return; + } + + eachNotifier.fireTestStarted(); + try { + methodBlock(method).evaluate(); + } catch (AssumptionViolatedException e) { + eachNotifier.addFailedAssumption(e); + } catch (Throwable e) { + eachNotifier.addFailure(e); + } finally { + eachNotifier.fireTestFinished(); + } + } + + @Override + protected Description describeChild(FrameworkMethod method) { + return Description.createTestDescription(getTestClass().getJavaClass(), + testName(method), method.getAnnotations()); + } + + @Override + protected List getChildren() { + return computeTestMethods(); + } + + // + // Override in subclasses + // + + /** + * Returns the methods that run tests. Default implementation + * returns all methods annotated with {@code @Test} on this + * class and superclasses that are not overridden. + */ + protected List computeTestMethods() { + return getTestClass().getAnnotatedMethods(Test.class); + } + + @Override + protected void collectInitializationErrors(List errors) { + super.collectInitializationErrors(errors); + + validateConstructor(errors); + validateInstanceMethods(errors); + } + + private void validateConstructor(List errors) { + validateOnlyOneConstructor(errors); + validateZeroArgConstructor(errors); + } + + private void validateOnlyOneConstructor(List errors) { + if (!hasOneConstructor()) { + String gripe= "Test class should have exactly one public constructor"; + errors.add(new Exception(gripe)); + } + } + + /** + * Adds to {@code errors} if the test class's single constructor + * takes parameters + */ + protected void validateZeroArgConstructor(List errors) { + if (hasOneConstructor() + && !(getTestClass().getOnlyConstructor().getParameterTypes().length == 0)) { + String gripe= "Test class should have exactly one public zero-argument constructor"; + errors.add(new Exception(gripe)); + } + } + + private boolean hasOneConstructor() { + return getTestClass().getJavaClass().getConstructors().length == 1; + } + + /** + * Adds to {@code errors} for each method annotated with {@code @Test}, + * {@code @Before}, or {@code @After} that is not a public, void instance + * method with no arguments. + */ + protected void validateInstanceMethods(List errors) { + validatePublicVoidNoArgMethods(After.class, false, errors); + validatePublicVoidNoArgMethods(Before.class, false, errors); + validateTestMethods(errors); + + if (computeTestMethods().size() == 0) + errors.add(new Exception("No runnable methods")); + } + + /** + * Adds to {@code errors} for each method annotated with {@code @Test}that + * is not a public, void instance method with no arguments. + */ + protected void validateTestMethods(List errors) { + validatePublicVoidNoArgMethods(Test.class, false, errors); + } + + /** + * Returns a new fixture for running a test. Default implementation executes + * the test class's no-argument constructor (validation should have ensured + * one exists). + */ + protected Object createTest() throws Exception { + return getTestClass().getOnlyConstructor().newInstance(); + } + + /** + * Returns the name that describes {@code method} for {@link Description}s. + * Default implementation is the method's name + */ + protected String testName(FrameworkMethod method) { + return method.getName(); + } + + /** + * Returns a Statement that, when executed, either returns normally if + * {@code method} passes, or throws an exception if {@code method} fails. + * + * Here is an outline of the default implementation: + * + *
    + *
  • Invoke {@code method} on the result of {@code createTest()}, and + * throw any exceptions thrown by either operation. + *
  • HOWEVER, if {@code method}'s {@code @Test} annotation has the {@code + * expecting} attribute, return normally only if the previous step threw an + * exception of the correct type, and throw an exception otherwise. + *
  • HOWEVER, if {@code method}'s {@code @Test} annotation has the {@code + * timeout} attribute, throw an exception if the previous step takes more + * than the specified number of milliseconds. + *
  • ALWAYS run all non-overridden {@code @Before} methods on this class + * and superclasses before any of the previous steps; if any throws an + * Exception, stop execution and pass the exception on. + *
  • ALWAYS run all non-overridden {@code @After} methods on this class + * and superclasses before any of the previous steps; all After methods are + * always executed: exceptions thrown by previous steps are combined, if + * necessary, with exceptions from After methods into a + * {@link MultipleFailureException}. + *
+ * + * This can be overridden in subclasses, either by overriding this method, + * or the implementations creating each sub-statement. + */ + protected Statement methodBlock(FrameworkMethod method) { + Object test; + try { + test= new ReflectiveCallable() { + @Override + protected Object runReflectiveCall() throws Throwable { + return createTest(); + } + }.run(); + } catch (Throwable e) { + return new Fail(e); + } + + Statement statement= methodInvoker(method, test); + statement= possiblyExpectingExceptions(method, test, statement); + statement= withPotentialTimeout(method, test, statement); + statement= withBefores(method, test, statement); + statement= withAfters(method, test, statement); + return statement; + } + + // + // Statement builders + // + + /** + * Returns a {@link Statement} that invokes {@code method} on {@code test} + */ + protected Statement methodInvoker(FrameworkMethod method, Object test) { + return new InvokeMethod(method, test); + } + + /** + * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation + * has the {@code expecting} attribute, return normally only if {@code next} + * throws an exception of the correct type, and throw an exception + * otherwise. + */ + protected Statement possiblyExpectingExceptions(FrameworkMethod method, + Object test, Statement next) { + Test annotation= method.getAnnotation(Test.class); + return expectsException(annotation) ? new ExpectException(next, + getExpectedException(annotation)) : next; + } + + /** + * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation + * has the {@code timeout} attribute, throw an exception if {@code next} + * takes more than the specified number of milliseconds. + */ + protected Statement withPotentialTimeout(FrameworkMethod method, + Object test, Statement next) { + long timeout= getTimeout(method.getAnnotation(Test.class)); + return timeout > 0 ? new FailOnTimeout(next, timeout) : next; + } + + /** + * Returns a {@link Statement}: run all non-overridden {@code @Before} + * methods on this class and superclasses before running {@code next}; if + * any throws an Exception, stop execution and pass the exception on. + */ + protected Statement withBefores(FrameworkMethod method, Object target, + Statement statement) { + List befores= getTestClass().getAnnotatedMethods( + Before.class); + return new RunBefores(statement, befores, target); + } + + /** + * Returns a {@link Statement}: run all non-overridden {@code @After} + * methods on this class and superclasses before running {@code next}; all + * After methods are always executed: exceptions thrown by previous steps + * are combined, if necessary, with exceptions from After methods into a + * {@link MultipleFailureException}. + */ + protected Statement withAfters(FrameworkMethod method, Object target, + Statement statement) { + List afters= getTestClass().getAnnotatedMethods( + After.class); + return new RunAfters(statement, afters, target); + } + + private EachTestNotifier makeNotifier(FrameworkMethod method, + RunNotifier notifier) { + Description description= describeChild(method); + return new EachTestNotifier(notifier, description); + } + + private Class getExpectedException(Test annotation) { + if (annotation == null || annotation.expected() == None.class) + return null; + else + return annotation.expected(); + } + + private boolean expectsException(Test annotation) { + return getExpectedException(annotation) != null; + } + + private long getTimeout(Test annotation) { + if (annotation == null) + return 0; + return annotation.timeout(); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/JUnit4.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/JUnit4.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,22 @@ +package org.junit.runners; + +import org.junit.runners.model.InitializationError; + +/** + * Aliases the current default JUnit 4 class runner, for future-proofing. If + * future versions of JUnit change the default Runner class, they will also + * change the definition of this class. Developers wanting to explicitly tag a + * class as a JUnit 4 class should use {@code @RunWith(JUnit4.class)}, not, + * for example in JUnit 4.5, {@code @RunWith(BlockJUnit4ClassRunner.class)}. + * This is the only way this class should be used--any extension that + * depends on the implementation details of this class is likely to break + * in future versions. + */ +public final class JUnit4 extends BlockJUnit4ClassRunner { + /** + * Constructs a new instance of the default runner + */ + public JUnit4(Class klass) throws InitializationError { + super(klass); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/Parameterized.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/Parameterized.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,166 @@ +package org.junit.runners; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.junit.runner.Runner; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.Statement; +import org.junit.runners.model.TestClass; + +/** + *

+ * The custom runner Parameterized implements parameterized tests. + * When running a parameterized test class, instances are created for the + * cross-product of the test methods and the test data elements. + *

+ * + * For example, to test a Fibonacci function, write: + * + *
+ * @RunWith(Parameterized.class)
+ * public class FibonacciTest {
+ * 	@Parameters
+ * 	public static Collection<Object[]> data() {
+ * 		return Arrays.asList(new Object[][] {
+ * 				Fibonacci,
+ * 				{ { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, { 4, 3 }, { 5, 5 },
+ * 						{ 6, 8 } } });
+ * 	}
+ * 
+ * 	private int fInput;
+ * 
+ * 	private int fExpected;
+ * 
+ * 	public FibonacciTest(int input, int expected) {
+ * 		fInput= input;
+ * 		fExpected= expected;
+ * 	}
+ * 
+ * 	@Test
+ * 	public void test(@HeresHowYouGetValue Type value) {
+ * 		assertAnswerKey(new Object[][] {
+ * 				Fibonacci,
+ * 				{ { 0, 0 }, { 1, 1 }, { 2, 1 }, { 3, 2 }, { 4, 3 }, { 5, 5 },
+ * 						{ 6, 8 } } });
+ * 		assertEquals(fExpected, Fibonacci.compute(fInput));
+ * 	}
+ * }
+ * 
+ * + *

+ * Each instance of FibonacciTest will be constructed using the + * two-argument constructor and the data values in the + * @Parameters method. + *

+ */ +public class Parameterized extends Suite { + /** + * Annotation for a method which provides parameters to be injected into the + * test class constructor by Parameterized + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public static @interface Parameters { + } + + private class TestClassRunnerForParameters extends + BlockJUnit4ClassRunner { + private final int fParameterSetNumber; + + private final List fParameterList; + + TestClassRunnerForParameters(Class type, + List parameterList, int i) throws InitializationError { + super(type); + fParameterList= parameterList; + fParameterSetNumber= i; + } + + @Override + public Object createTest() throws Exception { + return getTestClass().getOnlyConstructor().newInstance( + computeParams()); + } + + private Object[] computeParams() throws Exception { + try { + return fParameterList.get(fParameterSetNumber); + } catch (ClassCastException e) { + throw new Exception(String.format( + "%s.%s() must return a Collection of arrays.", + getTestClass().getName(), getParametersMethod( + getTestClass()).getName())); + } + } + + @Override + protected String getName() { + return String.format("[%s]", fParameterSetNumber); + } + + @Override + protected String testName(final FrameworkMethod method) { + return String.format("%s[%s]", method.getName(), + fParameterSetNumber); + } + + @Override + protected void validateZeroArgConstructor(List errors) { + // constructor can, nay, should have args. + } + + @Override + protected Statement classBlock(RunNotifier notifier) { + return childrenInvoker(notifier); + } + } + + private final ArrayList runners= new ArrayList(); + + /** + * Only called reflectively. Do not use programmatically. + */ + public Parameterized(Class klass) throws Throwable { + super(klass, Collections.emptyList()); + List parametersList= getParametersList(getTestClass()); + for (int i= 0; i < parametersList.size(); i++) + runners.add(new TestClassRunnerForParameters(getTestClass().getJavaClass(), + parametersList, i)); + } + + @Override + protected List getChildren() { + return runners; + } + + @SuppressWarnings("unchecked") + private List getParametersList(TestClass klass) + throws Throwable { + return (List) getParametersMethod(klass).invokeExplosively( + null); + } + + private FrameworkMethod getParametersMethod(TestClass testClass) + throws Exception { + List methods= testClass + .getAnnotatedMethods(Parameters.class); + for (FrameworkMethod each : methods) { + int modifiers= each.getMethod().getModifiers(); + if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers)) + return each; + } + + throw new Exception("No public static parameters method on class " + + testClass.getName()); + } + +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/ParentRunner.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/ParentRunner.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,293 @@ +package org.junit.runners; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.internal.AssumptionViolatedException; +import org.junit.internal.runners.model.EachTestNotifier; +import org.junit.internal.runners.model.MultipleFailureException; +import org.junit.internal.runners.statements.RunAfters; +import org.junit.internal.runners.statements.RunBefores; +import org.junit.runner.Description; +import org.junit.runner.Runner; +import org.junit.runner.manipulation.Filter; +import org.junit.runner.manipulation.Filterable; +import org.junit.runner.manipulation.NoTestsRemainException; +import org.junit.runner.manipulation.Sortable; +import org.junit.runner.manipulation.Sorter; +import org.junit.runner.notification.RunNotifier; +import org.junit.runner.notification.StoppedByUserException; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.Statement; +import org.junit.runners.model.TestClass; + +/** + * Provides most of the functionality specific to a Runner that implements a + * "parent node" in the test tree, with children defined by objects of some data + * type {@code T}. (For {@link BlockJUnit4ClassRunner}, {@code T} is + * {@link Method} . For {@link Suite}, {@code T} is {@link Class}.) Subclasses + * must implement finding the children of the node, describing each child, and + * running each child. ParentRunner will filter and sort children, handle + * {@code @BeforeClass} and {@code @AfterClass} methods, create a composite + * {@link Description}, and run children sequentially. + */ +public abstract class ParentRunner extends Runner implements Filterable, + Sortable { + private final TestClass fTestClass; + + private Filter fFilter= null; + + private Sorter fSorter= Sorter.NULL; + + /** + * Constructs a new {@code ParentRunner} that will run {@code @TestClass} + * @throws InitializationError + */ + protected ParentRunner(Class testClass) throws InitializationError { + fTestClass= new TestClass(testClass); + validate(); + } + + // + // Must be overridden + // + + /** + * Returns a list of objects that define the children of this Runner. + */ + protected abstract List getChildren(); + + /** + * Returns a {@link Description} for {@code child}, which can be assumed to + * be an element of the list returned by {@link ParentRunner#getChildren()} + */ + protected abstract Description describeChild(T child); + + /** + * Runs the test corresponding to {@code child}, which can be assumed to be + * an element of the list returned by {@link ParentRunner#getChildren()}. + * Subclasses are responsible for making sure that relevant test events are + * reported through {@code notifier} + */ + protected abstract void runChild(T child, RunNotifier notifier); + + // + // May be overridden + // + + /** + * Adds to {@code errors} a throwable for each problem noted with the test class (available from {@link #getTestClass()}). + * Default implementation adds an error for each method annotated with + * {@code @BeforeClass} or {@code @AfterClass} that is not + * {@code public static void} with no arguments. + */ + protected void collectInitializationErrors(List errors) { + validatePublicVoidNoArgMethods(BeforeClass.class, true, errors); + validatePublicVoidNoArgMethods(AfterClass.class, true, errors); + } + + /** + * Adds to {@code errors} if any method in this class is annotated with + * {@code annotation}, but: + *
    + *
  • is not public, or + *
  • takes parameters, or + *
  • returns something other than void, or + *
  • is static (given {@code isStatic is false}), or + *
  • is not static (given {@code isStatic is true}). + */ + protected void validatePublicVoidNoArgMethods(Class annotation, + boolean isStatic, List errors) { + List methods= getTestClass().getAnnotatedMethods(annotation); + + for (FrameworkMethod eachTestMethod : methods) + eachTestMethod.validatePublicVoidNoArg(isStatic, errors); + } + + /** + * Constructs a {@code Statement} to run all of the tests in the test class. Override to add pre-/post-processing. + * Here is an outline of the implementation: + *
      + *
    • Call {@link #runChild(Object, RunNotifier)} on each object returned by {@link #getChildren()} (subject to any imposed filter and sort).
    • + *
    • ALWAYS run all non-overridden {@code @BeforeClass} methods on this class + * and superclasses before the previous step; if any throws an + * Exception, stop execution and pass the exception on. + *
    • ALWAYS run all non-overridden {@code @AfterClass} methods on this class + * and superclasses before any of the previous steps; all AfterClass methods are + * always executed: exceptions thrown by previous steps are combined, if + * necessary, with exceptions from AfterClass methods into a + * {@link MultipleFailureException}. + *
    + * @param notifier + * @return {@code Statement} + */ + protected Statement classBlock(final RunNotifier notifier) { + Statement statement= childrenInvoker(notifier); + statement= withBeforeClasses(statement); + statement= withAfterClasses(statement); + return statement; + } + + /** + * Returns a {@link Statement}: run all non-overridden {@code @BeforeClass} methods on this class + * and superclasses before executing {@code statement}; if any throws an + * Exception, stop execution and pass the exception on. + */ + protected Statement withBeforeClasses(Statement statement) { + List befores= fTestClass + .getAnnotatedMethods(BeforeClass.class); + statement= new RunBefores(statement, befores, null); + return statement; + } + + /** + * Returns a {@link Statement}: run all non-overridden {@code @AfterClass} methods on this class + * and superclasses before executing {@code statement}; all AfterClass methods are + * always executed: exceptions thrown by previous steps are combined, if + * necessary, with exceptions from AfterClass methods into a + * {@link MultipleFailureException}. + */ + protected Statement withAfterClasses(Statement statement) { + List afters= fTestClass + .getAnnotatedMethods(AfterClass.class); + statement= new RunAfters(statement, afters, null); + return statement; + } + + /** + * Returns a {@link Statement}: Call {@link #runChild(Object, RunNotifier)} + * on each object returned by {@link #getChildren()} (subject to any imposed + * filter and sort) + */ + protected Statement childrenInvoker(final RunNotifier notifier) { + return new Statement() { + @Override + public void evaluate() { + runChildren(notifier); + } + }; + } + + private void runChildren(final RunNotifier notifier) { + for (T each : getFilteredChildren()) + runChild(each, notifier); + } + + /** + * Returns a name used to describe this Runner + */ + protected String getName() { + return fTestClass.getName(); + } + + // + // Available for subclasses + // + + /** + * Returns a {@link TestClass} object wrapping the class to be executed. + */ + protected final TestClass getTestClass() { + return fTestClass; + } + + // + // Implementation of Runner + // + + @Override + public Description getDescription() { + Description description= Description.createSuiteDescription(getName(), + fTestClass.getAnnotations()); + for (T child : getFilteredChildren()) + description.addChild(describeChild(child)); + return description; + } + + @Override + public void run(final RunNotifier notifier) { + EachTestNotifier testNotifier= new EachTestNotifier(notifier, + getDescription()); + try { + Statement statement= classBlock(notifier); + statement.evaluate(); + } catch (AssumptionViolatedException e) { + testNotifier.fireTestIgnored(); + } catch (StoppedByUserException e) { + throw e; + } catch (Throwable e) { + testNotifier.addFailure(e); + } + } + + // + // Implementation of Filterable and Sortable + // + + public void filter(Filter filter) throws NoTestsRemainException { + fFilter= filter; + + for (T each : getChildren()) + if (shouldRun(each)) + return; + throw new NoTestsRemainException(); + } + + public void sort(Sorter sorter) { + fSorter= sorter; + } + + // + // Private implementation + // + + private void validate() throws InitializationError { + List errors= new ArrayList(); + collectInitializationErrors(errors); + if (!errors.isEmpty()) + throw new InitializationError(errors); + } + + private List getFilteredChildren() { + ArrayList filtered= new ArrayList(); + for (T each : getChildren()) + if (shouldRun(each)) + try { + filterChild(each); + sortChild(each); + filtered.add(each); + } catch (NoTestsRemainException e) { + // don't add it + } + Collections.sort(filtered, comparator()); + return filtered; + } + + private void sortChild(T child) { + fSorter.apply(child); + } + + private void filterChild(T child) throws NoTestsRemainException { + if (fFilter != null) + fFilter.apply(child); + } + + private boolean shouldRun(T each) { + return fFilter == null || fFilter.shouldRun(describeChild(each)); + } + + private Comparator comparator() { + return new Comparator() { + public int compare(T o1, T o2) { + return fSorter.compare(describeChild(o1), describeChild(o2)); + } + }; + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/Suite.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/Suite.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,117 @@ +package org.junit.runners; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.List; + +import org.junit.internal.builders.AllDefaultPossibilitiesBuilder; +import org.junit.runner.Description; +import org.junit.runner.Runner; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.RunnerBuilder; + +/** + * Using Suite as a runner allows you to manually + * build a suite containing tests from many classes. It is the JUnit 4 equivalent of the JUnit 3.8.x + * static {@link junit.framework.Test} suite() method. To use it, annotate a class + * with @RunWith(Suite.class) and @SuiteClasses(TestClass1.class, ...). + * When you run this class, it will run all the tests in all the suite classes. + */ +public class Suite extends ParentRunner { + /** + * The SuiteClasses annotation specifies the classes to be run when a class + * annotated with @RunWith(Suite.class) is run. + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + public @interface SuiteClasses { + /** + * @return the classes to be run + */ + public Class[] value(); + } + + private static Class[] getAnnotatedClasses(Class klass) throws InitializationError { + SuiteClasses annotation= klass.getAnnotation(SuiteClasses.class); + if (annotation == null) + throw new InitializationError(String.format("class '%s' must have a SuiteClasses annotation", klass.getName())); + return annotation.value(); + } + + private final List fRunners; + + /** + * Called reflectively on classes annotated with @RunWith(Suite.class) + * + * @param klass the root class + * @param builder builds runners for classes in the suite + * @throws InitializationError + */ + public Suite(Class klass, RunnerBuilder builder) throws InitializationError { + this(builder, klass, getAnnotatedClasses(klass)); + } + + /** + * Call this when there is no single root class (for example, multiple class names + * passed on the command line to {@link org.junit.runner.JUnitCore} + * + * @param builder builds runners for classes in the suite + * @param classes the classes in the suite + * @throws InitializationError + */ + public Suite(RunnerBuilder builder, Class[] classes) throws InitializationError { + this(null, builder.runners(null, classes)); + } + + /** + * Call this when the default builder is good enough. Left in for compatibility with JUnit 4.4. + * @param klass the root of the suite + * @param suiteClasses the classes in the suite + * @throws InitializationError + */ + protected Suite(Class klass, Class[] suiteClasses) throws InitializationError { + this(new AllDefaultPossibilitiesBuilder(true), klass, suiteClasses); + } + + /** + * Called by this class and subclasses once the classes making up the suite have been determined + * + * @param builder builds runners for classes in the suite + * @param klass the root of the suite + * @param suiteClasses the classes in the suite + * @throws InitializationError + */ + protected Suite(RunnerBuilder builder, Class klass, Class[] suiteClasses) throws InitializationError { + this(klass, builder.runners(klass, suiteClasses)); + } + + /** + * Called by this class and subclasses once the runners making up the suite have been determined + * + * @param klass root of the suite + * @param runners for each class in the suite, a {@link Runner} + * @throws InitializationError + */ + protected Suite(Class klass, List runners) throws InitializationError { + super(klass); + fRunners = runners; + } + + @Override + protected List getChildren() { + return fRunners; + } + + @Override + protected Description describeChild(Runner child) { + return child.getDescription(); + } + + @Override + protected void runChild(Runner runner, final RunNotifier notifier) { + runner.run(notifier); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/model/FrameworkMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/model/FrameworkMethod.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,150 @@ +package org.junit.runners.model; + +import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.List; + +import org.junit.internal.runners.model.ReflectiveCallable; + +/** + * Represents a method on a test class to be invoked at the appropriate point in + * test execution. These methods are usually marked with an annotation (such as + * {@code @Test}, {@code @Before}, {@code @After}, {@code @BeforeClass}, {@code + * @AfterClass}, etc.) + */ +public class FrameworkMethod { + private final Method fMethod; + + /** + * Returns a new {@code FrameworkMethod} for {@code method} + */ + public FrameworkMethod(Method method) { + fMethod= method; + } + + /** + * Returns the underlying Java method + */ + public Method getMethod() { + return fMethod; + } + + /** + * Returns the result of invoking this method on {@code target} with + * parameters {@code params}. {@link InvocationTargetException}s thrown are + * unwrapped, and their causes rethrown. + */ + public Object invokeExplosively(final Object target, final Object... params) + throws Throwable { + return new ReflectiveCallable() { + @Override + protected Object runReflectiveCall() throws Throwable { + return fMethod.invoke(target, params); + } + }.run(); + } + + /** + * Returns the method's name + */ + public String getName() { + return fMethod.getName(); + } + + /** + * Adds to {@code errors} if this method: + *
      + *
    • is not public, or + *
    • takes parameters, or + *
    • returns something other than void, or + *
    • is static (given {@code isStatic is false}), or + *
    • is not static (given {@code isStatic is true}). + */ + public void validatePublicVoidNoArg(boolean isStatic, List errors) { + validatePublicVoid(isStatic, errors); + if (fMethod.getParameterTypes().length != 0) + errors.add(new Exception("Method " + fMethod.getName() + " should have no parameters")); + } + + + /** + * Adds to {@code errors} if this method: + *
        + *
      • is not public, or + *
      • returns something other than void, or + *
      • is static (given {@code isStatic is false}), or + *
      • is not static (given {@code isStatic is true}). + */ + public void validatePublicVoid(boolean isStatic, List errors) { + if (Modifier.isStatic(fMethod.getModifiers()) != isStatic) { + String state= isStatic ? "should" : "should not"; + errors.add(new Exception("Method " + fMethod.getName() + "() " + state + " be static")); + } + if (!Modifier.isPublic(fMethod.getDeclaringClass().getModifiers())) + errors.add(new Exception("Class " + fMethod.getDeclaringClass().getName() + " should be public")); + if (!Modifier.isPublic(fMethod.getModifiers())) + errors.add(new Exception("Method " + fMethod.getName() + "() should be public")); + if (fMethod.getReturnType() != Void.TYPE) + errors.add(new Exception("Method " + fMethod.getName() + "() should be void")); + } + + boolean isShadowedBy(List results) { + for (FrameworkMethod each : results) + if (isShadowedBy(each)) + return true; + return false; + } + + private boolean isShadowedBy(FrameworkMethod each) { + if (!each.getName().equals(getName())) + return false; + if (each.getParameterTypes().length != getParameterTypes().length) + return false; + for (int i= 0; i < each.getParameterTypes().length; i++) + if (!each.getParameterTypes()[i].equals(getParameterTypes()[i])) + return false; + return true; + } + + @Override + public boolean equals(Object obj) { + if (!FrameworkMethod.class.isInstance(obj)) + return false; + return ((FrameworkMethod) obj).fMethod.equals(fMethod); + } + + @Override + public int hashCode() { + return fMethod.hashCode(); + } + + /** + * Returns true iff this is a no-arg method that returns a value assignable + * to {@code type} + */ + public boolean producesType(Class type) { + return getParameterTypes().length == 0 + && type.isAssignableFrom(fMethod.getReturnType()); + } + + private Class[] getParameterTypes() { + return fMethod.getParameterTypes(); + } + + /** + * Returns the annotations on this method + */ + public Annotation[] getAnnotations() { + return fMethod.getAnnotations(); + } + + /** + * Returns the annotation of type {@code annotationType} on this method, if + * one exists. + */ + public T getAnnotation(Class annotationType) { + return fMethod.getAnnotation(annotationType); + } +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/model/InitializationError.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/model/InitializationError.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,35 @@ +package org.junit.runners.model; + +import java.util.Arrays; +import java.util.List; + +/** + * Represents one or more problems encountered while initializing a Runner + */ +public class InitializationError extends Exception { + private static final long serialVersionUID= 1L; + private final List fErrors; + + /** + * Construct a new {@code InitializationError} with one or more + * errors {@code errors} as causes + */ + public InitializationError(List errors) { + fErrors= errors; + } + + /** + * Construct a new {@code InitializationError} with one cause + * with message {@code string} + */ + public InitializationError(String string) { + this(Arrays.asList(new Exception(string))); + } + + /** + * Returns one or more Throwables that led to this initialization error. + */ + public List getCauses() { + return fErrors; + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/model/RunnerBuilder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/model/RunnerBuilder.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,99 @@ +package org.junit.runners.model; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.internal.runners.ErrorReportingRunner; +import org.junit.runner.Runner; + +/** + * A RunnerBuilder is a strategy for constructing runners for classes. + * + * Only writers of custom runners should use RunnerBuilders. A custom runner class with a constructor taking + * a RunnerBuilder parameter will be passed the instance of RunnerBuilder used to build that runner itself. + * For example, + * imagine a custom runner that builds suites based on a list of classes in a text file: + * + *
        + * \@RunWith(TextFileSuite.class)
        + * \@SuiteSpecFile("mysuite.txt")
        + * class MySuite {}
        + * 
        + * + * The implementation of TextFileSuite might include: + * + *
        + * public TextFileSuite(Class testClass, RunnerBuilder builder) {
        + *   // ...
        + *   for (String className : readClassNames())
        + *     addRunner(builder.runnerForClass(Class.forName(className)));
        + *   // ...
        + * }
        + * 
        + * + * @see org.junit.runners.Suite + */ +public abstract class RunnerBuilder { + private final Set> parents= new HashSet>(); + + /** + * Override to calculate the correct runner for a test class at runtime. + * + * @param testClass class to be run + * @return a Runner + * @throws Throwable if a runner cannot be constructed + */ + public abstract Runner runnerForClass(Class testClass) throws Throwable; + + /** + * Always returns a runner, even if it is just one that prints an error instead of running tests. + * @param testClass class to be run + * @return a Runner + */ + public Runner safeRunnerForClass(Class testClass) { + try { + return runnerForClass(testClass); + } catch (Throwable e) { + return new ErrorReportingRunner(testClass, e); + } + } + + Class addParent(Class parent) throws InitializationError { + if (!parents.add(parent)) + throw new InitializationError(String.format("class '%s' (possibly indirectly) contains itself as a SuiteClass", parent.getName())); + return parent; + } + + void removeParent(Class klass) { + parents.remove(klass); + } + + /** + * Constructs and returns a list of Runners, one for each child class in + * {@code children}. Care is taken to avoid infinite recursion: + * this builder will throw an exception if it is requested for another + * runner for {@code parent} before this call completes. + */ + public List runners(Class parent, Class[] children) + throws InitializationError { + addParent(parent); + + try { + return runners(children); + } finally { + removeParent(parent); + } + } + + private List runners(Class[] children) { + ArrayList runners= new ArrayList(); + for (Class each : children) { + Runner childRunner= safeRunnerForClass(each); + if (childRunner != null) + runners.add(childRunner); + } + return runners; + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/model/Statement.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/model/Statement.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,16 @@ +/** + * + */ +package org.junit.runners.model; + + +/** + * Represents one or more actions to be taken at runtime in the course + * of running a JUnit test suite. + */ +public abstract class Statement { + /** + * Run the action, throwing a {@code Throwable} if anything goes wrong. + */ + public abstract void evaluate() throws Throwable; +} \ No newline at end of file diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/model/TestClass.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/model/TestClass.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,129 @@ +package org.junit.runners.model; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; + +/** + * Wraps a class to be run, providing method validation and annotation searching + */ +public class TestClass { + private final Class fClass; + + private Map, List> fMethodsForAnnotations= new HashMap, List>(); + + /** + * Creates a {@code TestClass} wrapping {@code klass}. Each time this + * constructor executes, the class is scanned for annotations, which can be + * an expensive process (we hope in future JDK's it will not be.) Therefore, + * try to share instances of {@code TestClass} where possible. + */ + public TestClass(Class klass) { + fClass= klass; + if (klass != null && klass.getConstructors().length > 1) + throw new IllegalArgumentException( + "Test class can only have one constructor"); + + for (Class eachClass : getSuperClasses(fClass)) + for (Method eachMethod : eachClass.getDeclaredMethods()) + addToAnnotationLists(new FrameworkMethod(eachMethod)); + } + + private void addToAnnotationLists(FrameworkMethod testMethod) { + for (Annotation each : computeAnnotations(testMethod)) + addToAnnotationList(each.annotationType(), testMethod); + } + + /** + * Returns all of the annotations on {@code testMethod} + */ + protected Annotation[] computeAnnotations(FrameworkMethod testMethod) { + return testMethod.getAnnotations(); + } + + private void addToAnnotationList(Class annotation, + FrameworkMethod testMethod) { + List methods= getAnnotatedMethods(annotation); + if (testMethod.isShadowedBy(methods)) + return; + if (runsTopToBottom(annotation)) + methods.add(0, testMethod); + else + methods.add(testMethod); + } + + private void ensureKey(Class annotation) { + if (!fMethodsForAnnotations.containsKey(annotation)) + fMethodsForAnnotations.put(annotation, + new ArrayList()); + } + + /** + * Returns, efficiently, all the non-overridden methods in this class and + * its superclasses that are annotated with {@code annotationClass}. + */ + public List getAnnotatedMethods( + Class annotationClass) { + ensureKey(annotationClass); + return fMethodsForAnnotations.get(annotationClass); + } + + private boolean runsTopToBottom(Class annotation) { + return annotation.equals(Before.class) + || annotation.equals(BeforeClass.class); + } + + private List> getSuperClasses(Class testClass) { + ArrayList> results= new ArrayList>(); + Class current= testClass; + while (current != null) { + results.add(current); + current= current.getSuperclass(); + } + return results; + } + + /** + * Returns the underlying Java class. + */ + public Class getJavaClass() { + return fClass; + } + + /** + * Returns the class's name. + */ + public String getName() { + if (fClass == null) + return "null"; + return fClass.getName(); + } + + /** + * Returns the only public constructor in the class, or throws an {@code + * AssertionError} if there are more or less than one. + */ + + public Constructor getOnlyConstructor() { + Constructor[] constructors= fClass.getConstructors(); + Assert.assertEquals(1, constructors.length); + return constructors[0]; + } + + /** + * Returns the annotations on this class + */ + public Annotation[] getAnnotations() { + if (fClass == null) + return new Annotation[0]; + return fClass.getAnnotations(); + } +} diff -r 8d56403172bc -r 3ef299ba838f carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/carbidecpp22devenv/plugins/org.eclipse.test.source_3.5.0.r20080925/src/org.junit4_4.5.0.v20090423/junitsrc/org/junit/runners/package-info.java Fri Dec 04 11:49:54 2009 -0600 @@ -0,0 +1,8 @@ +/** + * Provides standard {@link org.junit.runner.Runner Runner} implementations. + * + * @since 4.0 + * @see org.junit.runner.Runner + * @see org.junit.runners.BlockJUnit4ClassRunner + */ +package org.junit.runners; \ No newline at end of file