001 /**
002 *
003 * Copyright 2004 James Strachan
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018
019 package org.codehaus.groovy.runtime;
020
021 import junit.framework.Test;
022 import junit.framework.TestResult;
023
024 /**
025 * An adapter to make any Groovy Script class an instance of a JUnit Test
026 *
027 * @version $Revision: 1.1 $
028 */
029 public class ScriptTestAdapter implements Test {
030 private Class scriptClass;
031 private String[] arguments;
032
033 public ScriptTestAdapter(Class scriptClass, String[] arguments) {
034 this.scriptClass = scriptClass;
035 this.arguments = arguments;
036 }
037
038 public int countTestCases() {
039 return 1;
040 }
041
042 public void run(TestResult result) {
043 try {
044 result.startTest(this);
045
046 // lets run the script
047 InvokerHelper.runScript(scriptClass, arguments);
048 result.endTest(this);
049 }
050 catch (Exception e) {
051 result.addError(this, e);
052 }
053 }
054
055 public String toString() {
056 return "TestCase for script: " + scriptClass.getName();
057 }
058 }