01: /**
02: *
03: * Copyright 2004 James Strachan
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: **/package org.codehaus.groovy.runtime;
18:
19: import junit.framework.Test;
20: import junit.framework.TestResult;
21:
22: /**
23: * An adapter to make any Groovy Script class an instance of a JUnit Test
24: *
25: * @version $Revision: 1292 $
26: */
27: public class ScriptTestAdapter implements Test {
28: private Class scriptClass;
29: private String[] arguments;
30:
31: public ScriptTestAdapter(Class scriptClass, String[] arguments) {
32: this .scriptClass = scriptClass;
33: this .arguments = arguments;
34: }
35:
36: public int countTestCases() {
37: return 1;
38: }
39:
40: public void run(TestResult result) {
41: try {
42: result.startTest(this );
43:
44: // lets run the script
45: InvokerHelper.runScript(scriptClass, arguments);
46: result.endTest(this );
47: } catch (Exception e) {
48: result.addError(this , e);
49: }
50: }
51:
52: public String toString() {
53: return "TestCase for script: " + scriptClass.getName();
54: }
55: }
|