< prev index next >

src/com/sun/javatest/junit/JUnitTestSuite.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


  20  * 2 along with this work; if not, write to the Free Software Foundation,
  21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  22  *
  23  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  24  * or visit www.oracle.com if you need additional information or have any
  25  * questions.
  26  */
  27 package com.sun.javatest.junit;
  28 
  29 import com.sun.javatest.TestRunner;
  30 import com.sun.javatest.TestSuite;
  31 import java.io.File;
  32 import java.util.Map;
  33 import java.net.URLClassLoader;
  34 import java.net.URL;
  35 
  36 /**
  37  * Basic implementation of a test suite for JUnit tests.
  38  */
  39 public class JUnitTestSuite extends TestSuite {
  40     public JUnitTestSuite(File root, Map props, ClassLoader loader) throws TestSuite.Fault {
  41         super(root, props, loader);
  42         try {
  43             if (getTestsDir() != null)
  44                 loader = new URLClassLoader(new URL[] {getTestsDir().toURI().toURL()}, loader);
  45             else loader = ClassLoader.getSystemClassLoader();
  46         } catch(Exception e) {
  47         }
  48         cl = loader;
  49     }
  50 
  51     /**
  52      * Implementation here creates a JUnitTestRunner.
  53      * Override if you wish to supply your own test runner.
  54      */
  55     public TestRunner createTestRunner() {
  56         // will need to add options to test suite to be passed to runner
  57         // for ex. - to run setup/teardown, etc...
  58         try {
  59             Class c = loadClass("com.sun.javatest.junit.JUnitTestRunner");
  60             JUnitTestRunner tr = (JUnitTestRunner)(c.newInstance());
  61             tr.setClassLoader(getClassLoader());
  62             return tr;
  63         }
  64         catch (TestSuite.Fault f) {
  65             f.printStackTrace();
  66             // this will probably be ok, should log and error though
  67             return new JUnitTestRunner();
  68         }
  69         catch (InstantiationException e) {
  70             e.printStackTrace();
  71             return new JUnitTestRunner();
  72         }
  73         catch (IllegalAccessException e) {
  74             e.printStackTrace();
  75             return new JUnitTestRunner();
  76         }
  77     }
  78 
  79     private ClassLoader cl;


  20  * 2 along with this work; if not, write to the Free Software Foundation,
  21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  22  *
  23  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  24  * or visit www.oracle.com if you need additional information or have any
  25  * questions.
  26  */
  27 package com.sun.javatest.junit;
  28 
  29 import com.sun.javatest.TestRunner;
  30 import com.sun.javatest.TestSuite;
  31 import java.io.File;
  32 import java.util.Map;
  33 import java.net.URLClassLoader;
  34 import java.net.URL;
  35 
  36 /**
  37  * Basic implementation of a test suite for JUnit tests.
  38  */
  39 public class JUnitTestSuite extends TestSuite {
  40     public JUnitTestSuite(File root, Map<String, String> props, ClassLoader loader) throws TestSuite.Fault {
  41         super(root, props, loader);
  42         try {
  43             if (getTestsDir() != null)
  44                 loader = new URLClassLoader(new URL[] {getTestsDir().toURI().toURL()}, loader);
  45             else loader = ClassLoader.getSystemClassLoader();
  46         } catch(Exception e) {
  47         }
  48         cl = loader;
  49     }
  50 
  51     /**
  52      * Implementation here creates a JUnitTestRunner.
  53      * Override if you wish to supply your own test runner.
  54      */
  55     public TestRunner createTestRunner() {
  56         // will need to add options to test suite to be passed to runner
  57         // for ex. - to run setup/teardown, etc...
  58         try {
  59             Class<?> c = loadClass("com.sun.javatest.junit.JUnitTestRunner");
  60             JUnitTestRunner tr = (JUnitTestRunner)(c.newInstance());
  61             tr.setClassLoader(getClassLoader());
  62             return tr;
  63         }
  64         catch (TestSuite.Fault f) {
  65             f.printStackTrace();
  66             // this will probably be ok, should log and error though
  67             return new JUnitTestRunner();
  68         }
  69         catch (InstantiationException e) {
  70             e.printStackTrace();
  71             return new JUnitTestRunner();
  72         }
  73         catch (IllegalAccessException e) {
  74             e.printStackTrace();
  75             return new JUnitTestRunner();
  76         }
  77     }
  78 
  79     private ClassLoader cl;
< prev index next >