1 package org.codehaus.mojo.javascript;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.Iterator;
20
21 import junit.framework.AssertionFailedError;
22 import junit.framework.Test;
23 import junit.framework.TestResult;
24 import junit.framework.TestSuite;
25 import net.jsunit.JsUnitServer;
26 import net.jsunit.StandaloneTest;
27 import net.jsunit.TestCaseResult;
28 import net.jsunit.TestSuiteResult;
29
30
31
32
33
34
35
36 public class JsUnitTestCase
37 extends StandaloneTest
38 {
39
40
41
42 public JsUnitTestCase( String name )
43 {
44 super( name );
45 }
46
47 private static JsUnitServer sharedServer;
48
49
50
51
52 public static void setSharedServer( JsUnitServer server )
53 {
54 JsUnitTestCase.sharedServer = server;
55 }
56
57
58
59
60
61
62 public void setUp()
63 throws Exception
64 {
65 setServer( sharedServer );
66 super.setUp();
67 }
68
69
70
71
72
73
74
75
76 public void run( TestResult result )
77 {
78 super.run( new TestResult() );
79 TestSuiteResult suiteResult = JsUnitTestCase.sharedServer.lastResult();
80 if (suiteResult == null )
81 {
82 return;
83 }
84 for ( Iterator it = suiteResult.getTestCaseResults().iterator(); it.hasNext(); )
85 {
86 final TestCaseResult testCaseResult = (TestCaseResult) it.next();
87 Test fake = new Test()
88 {
89
90 public void run( TestResult result )
91 {
92 }
93
94 public int countTestCases()
95 {
96 return 1;
97 }
98
99 public String toString()
100 {
101 return testCaseResult.getName();
102 }
103 };
104 result.startTest( fake );
105 if ( testCaseResult.hadError() )
106 {
107 result.addError( fake, new Exception( testCaseResult.getError() ) );
108 }
109 if ( testCaseResult.hadFailure() )
110 {
111 result.addFailure( fake, new AssertionFailedError( testCaseResult.getFailure() ) );
112 }
113 result.endTest( fake );
114 }
115 }
116
117 private static TestSuite suite;
118
119 public static Test suite()
120 {
121 return suite;
122 }
123
124
125
126
127 public static void setSuite( TestSuite suite )
128 {
129 JsUnitTestCase.suite = suite;
130 }
131
132 }