Skip to content

Commit 0fcd9f7

Browse files
author
jossonsmith
committed
Check in part of the JUnit codes for Java2Script projects
1 parent 6ba4ad1 commit 0fcd9f7

36 files changed

+2596
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

sources/net.sf.j2s.java.junit/.j2s

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Java2Script Configuration
2+
#Wed Jul 26 01:11:27 CST 2006
3+
j2s.resources.list=bin/junit/textui/TestRunner.js,bin/junit/textui/ResultPrinter.js,bin/junit/swingui/TestTreeModel.js,bin/junit/swingui/TestSuitePanel.js,bin/junit/swingui/TestSelector.js,bin/junit/swingui/TestRunner.js,bin/junit/swingui/TestRunView.js,bin/junit/swingui/TestRunContext.js,bin/junit/swingui/TestHierarchyRunView.js,bin/junit/swingui/StatusLine.js,bin/junit/swingui/ProgressBar.js,bin/junit/swingui/FailureRunView.js,bin/junit/swingui/DefaultFailureDetailView.js,bin/junit/swingui/CounterPanel.js,bin/junit/swingui/AboutDialog.js,bin/junit/runner/Version.js,bin/junit/runner/TestSuiteLoader.js,bin/junit/runner/TestRunListener.js,bin/junit/runner/TestCollector.js,bin/junit/runner/TestCaseClassLoader.js,bin/junit/runner/StandardTestSuiteLoader.js,bin/junit/runner/Sorter.js,bin/junit/runner/SimpleTestCollector.js,bin/junit/runner/ReloadingTestSuiteLoader.js,bin/junit/runner/LoadingTestCollector.js,bin/junit/runner/FailureDetailView.js,bin/junit/runner/ClassPathTestCollector.js,bin/junit/runner/BaseTestRunner.js,bin/junit/framework/TestSuite.js,bin/junit/framework/TestResult.js,bin/junit/framework/TestListener.js,bin/junit/framework/TestFailure.js,bin/junit/framework/TestCase.js,bin/junit/framework/Test.js,bin/junit/framework/Protectable.js,bin/junit/framework/ComparisonFailure.js,bin/junit/framework/AssertionFailedError.js,bin/junit/framework/Assert.js,bin/junit/extensions/TestSetup.js,bin/junit/extensions/TestDecorator.js,bin/junit/extensions/RepeatedTest.js,bin/junit/extensions/ExceptionTestCase.js,bin/junit/extensions/ActiveTestSuite.js,bin/junit/awtui/TestRunner.js,bin/junit/awtui/ProgressBar.js,bin/junit/awtui/Logo.js,bin/junit/awtui/AboutDialog.js
4+
j2s.abandoned.resources.list=
5+
j2s.output.path=bin
6+
j2s.compiler.status=enable
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>net.sf.j2s.java.junit</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>net.sf.j2s.core.java2scriptbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
</natures>
22+
</projectDescription>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package junit.extensions;
2+
3+
import junit.framework.*;
4+
5+
/**
6+
* A TestSuite for active Tests. It runs each
7+
* test in a separate thread and waits until all
8+
* threads have terminated.
9+
* -- Aarhus Radisson Scandinavian Center 11th floor
10+
*/
11+
public class ActiveTestSuite extends TestSuite {
12+
private volatile int fActiveTestDeathCount;
13+
14+
public ActiveTestSuite() {
15+
}
16+
17+
public ActiveTestSuite(Class theClass) {
18+
super(theClass);
19+
}
20+
21+
public ActiveTestSuite(String name) {
22+
super (name);
23+
}
24+
25+
public ActiveTestSuite(Class theClass, String name) {
26+
super(theClass, name);
27+
}
28+
29+
public void run(TestResult result) {
30+
fActiveTestDeathCount= 0;
31+
super.run(result);
32+
waitUntilFinished();
33+
}
34+
35+
public void runTest(final Test test, final TestResult result) {
36+
Thread t= new Thread() {
37+
public void run() {
38+
try {
39+
// inlined due to limitation in VA/Java
40+
//ActiveTestSuite.super.runTest(test, result);
41+
test.run(result);
42+
} finally {
43+
ActiveTestSuite.this.runFinished(test);
44+
}
45+
}
46+
};
47+
t.start();
48+
}
49+
50+
synchronized void waitUntilFinished() {
51+
while (fActiveTestDeathCount < testCount()) {
52+
try {
53+
wait();
54+
} catch (InterruptedException e) {
55+
return; // ignore
56+
}
57+
}
58+
}
59+
60+
synchronized public void runFinished(Test test) {
61+
fActiveTestDeathCount++;
62+
notifyAll();
63+
}
64+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package junit.extensions;
2+
3+
import junit.framework.*;
4+
5+
/**
6+
* A TestCase that expects an Exception of class fExpected to be thrown.
7+
* The other way to check that an expected exception is thrown is:
8+
* <pre>
9+
* try {
10+
* shouldThrow();
11+
* }
12+
* catch (SpecialException e) {
13+
* return;
14+
* }
15+
* fail("Expected SpecialException");
16+
* </pre>
17+
*
18+
* To use ExceptionTestCase, create a TestCase like:
19+
* <pre>
20+
* new ExceptionTestCase("testShouldThrow", SpecialException.class);
21+
* </pre>
22+
*/
23+
public class ExceptionTestCase extends TestCase {
24+
Class fExpected;
25+
26+
public ExceptionTestCase(String name, Class exception) {
27+
super(name);
28+
fExpected= exception;
29+
}
30+
/**
31+
* Execute the test method expecting that an Exception of
32+
* class fExpected or one of its subclasses will be thrown
33+
*/
34+
protected void runTest() throws Throwable {
35+
try {
36+
super.runTest();
37+
}
38+
catch (Exception e) {
39+
if (fExpected.isAssignableFrom(e.getClass()))
40+
return;
41+
else
42+
throw e;
43+
}
44+
fail("Expected exception " + fExpected);
45+
}
46+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package junit.extensions;
2+
3+
import junit.framework.*;
4+
5+
/**
6+
* A Decorator that runs a test repeatedly.
7+
*
8+
*/
9+
public class RepeatedTest extends TestDecorator {
10+
private int fTimesRepeat;
11+
12+
public RepeatedTest(Test test, int repeat) {
13+
super(test);
14+
if (repeat < 0)
15+
throw new IllegalArgumentException("Repetition count must be > 0");
16+
fTimesRepeat= repeat;
17+
}
18+
public int countTestCases() {
19+
return super.countTestCases()*fTimesRepeat;
20+
}
21+
public void run(TestResult result) {
22+
for (int i= 0; i < fTimesRepeat; i++) {
23+
if (result.shouldStop())
24+
break;
25+
super.run(result);
26+
}
27+
}
28+
public String toString() {
29+
return super.toString()+"(repeated)";
30+
}
31+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package junit.extensions;
2+
3+
import junit.framework.*;
4+
5+
/**
6+
* A Decorator for Tests. Use TestDecorator as the base class
7+
* for defining new test decorators. Test decorator subclasses
8+
* can be introduced to add behaviour before or after a test
9+
* is run.
10+
*
11+
*/
12+
public class TestDecorator extends Assert implements Test {
13+
protected Test fTest;
14+
15+
public TestDecorator(Test test) {
16+
fTest= test;
17+
}
18+
/**
19+
* The basic run behaviour.
20+
*/
21+
public void basicRun(TestResult result) {
22+
fTest.run(result);
23+
}
24+
public int countTestCases() {
25+
return fTest.countTestCases();
26+
}
27+
public void run(TestResult result) {
28+
basicRun(result);
29+
}
30+
31+
public String toString() {
32+
return fTest.toString();
33+
}
34+
35+
public Test getTest() {
36+
return fTest;
37+
}
38+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package junit.extensions;
2+
3+
import junit.framework.*;
4+
5+
/**
6+
* A Decorator to set up and tear down additional fixture state.
7+
* Subclass TestSetup and insert it into your tests when you want
8+
* to set up additional state once before the tests are run.
9+
*/
10+
public class TestSetup extends TestDecorator {
11+
12+
public TestSetup(Test test) {
13+
super(test);
14+
}
15+
public void run(final TestResult result) {
16+
Protectable p= new Protectable() {
17+
public void protect() throws Exception {
18+
setUp();
19+
basicRun(result);
20+
tearDown();
21+
}
22+
};
23+
result.runProtected(this, p);
24+
}
25+
/**
26+
* Sets up the fixture. Override to set up additional fixture
27+
* state.
28+
*/
29+
protected void setUp() throws Exception {
30+
}
31+
/**
32+
* Tears down the fixture. Override to tear down the additional
33+
* fixture state.
34+
*/
35+
protected void tearDown() throws Exception {
36+
}
37+
}

0 commit comments

Comments
 (0)