test/java/module/modinit/RunMTest.java

Print this page

        

@@ -59,12 +59,12 @@
         Map<String,String> m = (Map<String,String>)(Map)p;
         defaultProperties = new HashMap<String,String>(m);
         defaultProperties.put("header", WARNING_HEADER);
     }
 
-    private final File file;
-    private final File outputDirectory;
+    protected final File file;
+    protected final File outputDirectory;
     private final List<ModuleDescription> modules;
     private final List<TestDescription> tests;
 
     private RunMTest(File file, String baseDirectory) throws IOException {
         this.file = file;

@@ -75,21 +75,21 @@
         if (k == -1) {
             subdir = file.getName();
         } else {
             subdir = cPath.substring(k + mString.length());
         }
-        System.out.println(">>> Test " + subdir);
+        System.out.println(">>>Test " + subdir);
         outputDirectory = new File(baseDirectory, subdir);
         if (outputDirectory.exists()) {
             recursiveDelete(outputDirectory);
         }
         modules = new ArrayList<ModuleDescription>();
         tests = new ArrayList<TestDescription>();
         parse();
     }
 
-    private String getName() {
+    protected String getName() {
         return file.getName();
     }
 
     private static String template;
 

@@ -308,20 +308,53 @@
         for (TestDescription t : tests) {
             t.runTest(this);
         }
     }
 
-    private static class TestDescription {
 
-        private final String name;
-        private String result;
+    // Abstracting the creation of TestDescription instances to a factory
+    // allows other tests to override TestDescription.runTest.
+    //
+    public static class TestDescriptionFactory {
+        private static TestDescriptionFactory instance;
 
-        private TestDescription(String name) {
+        static TestDescription create(String name) {
+            return getInstance().doCreate(name);
+        }
+
+        private static TestDescriptionFactory getInstance() {
+            if (instance == null) {
+                String factName = System.getProperty("TestDescriptionFactory.classname");
+                if (factName != null) {
+                    try {
+                        Class<?> clazz = Class.forName(factName);
+                        instance = (TestDescriptionFactory) clazz.newInstance();
+                    } catch (Throwable t) {
+                        throw new RuntimeException(t);
+                    }
+                } else {
+                    instance = new TestDescriptionFactory();
+                }
+            }
+            return instance;
+        }
+
+        protected TestDescription doCreate(String name) {
+            return new TestDescription(name);
+        }
+    }                
+        
+    public static class TestDescription {
+
+        protected final String name;
+        protected String result;
+
+        TestDescription(String name) {
             this.name = name;
         }
 
-        private void runTest(RunMTest mTest) throws Exception {
+        protected void runTest(RunMTest mTest) throws Exception {
             System.out.println("> Running test " + name + "...");
             Repository parent = sun.module.repository.RepositoryConfig.getSystemRepository();
             Repository repository = Modules.newLocalRepository(parent, mTest.getName(), mTest.outputDirectory);
             ModuleDefinition md = repository.find(name);
             try {

@@ -358,11 +391,11 @@
     }
 
     private TestDescription parseTest(String header, BufferedReader reader) throws IOException {
         String[] s = header.split(" ");
         String name = s[s.length - 1];
-        TestDescription test = new TestDescription(name);
+        TestDescription test = TestDescriptionFactory.create(name);
         while (true) {
             String line = getLine(reader);
             if (line == null) {
                 throw new EOFException();
             }