Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.junit.extensions.dynamicsuite.suite;
  
 
 import java.io.File;
 import java.util.List;
Copyright 2011 Christof Schoell

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

 
 public class DynamicSuite extends ParentRunner<Runner> {
 
     public static final Logger log = Logger.getLogger(DynamicSuite.class.getName());
     private List<RunnerfRunners;
 
     private Class<?> testedClass;
 
     private List<Class<?>> filteredClasses = new ArrayList<Class<?>>();
 
     private TestClassFilter filter;
 
     private File basePath;

    
Constructs a new ParentRunner that will run @TestClass

 
     protected DynamicSuite(Class<?> testClassthrows InitializationError {
         super(testClass);
     }
 
     public DynamicSuite(Class<?> klassRunnerBuilder builderthrows InitializationError {
         this(klass);
          = klass;
 
         loadTestClasses();
 
          = builder.runners(klass.toArray(new Class<?>[.size()]));
     }
 
     private void loadTestClasses() throws InitializationError {
         ClassScanner scanner = null;
         try {
             scanner = ScannerFactory.getInstance().createScanner();
 
             List<StringclassNames = scanner.listClassNames();
             for (String name : classNames) {
                 TestClassFilter testFilter = getFilter();
                 if (testFilter.include(name)) {
                     filterByClass(name);
                 }
             }
         } catch (Exception e) {
             throw new InitializationError(e);
         }
 
     }
 
 
     private void filterByClass(String className) {
         try {
             final Class<?> newTestClass = ClassLoader.getSystemClassLoader().loadClass(className);
             if (.include(newTestClass)) {
                 .add(newTestClass);
             }
         } catch (ClassNotFoundException e) {
             .info(e.getMessage());
         }
     }
 
 
     private Class<? extends TestClassFiltergetAnnotatedFilterClass() throws InitializationError {
         Filter annotation = .getAnnotation(Filter.class);
         if (annotation == null) {
            String string = String.format("class '%s' must have a Filter annotation".getName());
            ..println(string);
            throw new InitializationError(string);
        }
        return annotation.value();
    }
    private TestClassFilter getFilter() throws InitializationError {
        if ( == null) {
            try {
                 = getAnnotatedFilterClass().newInstance();
            } catch (InitializationError e) {
                throw e;
            }catch (Exception e) {
                throw new InitializationError(e);
            }
        }
        return ;
    }
    @Override
    protected List<RunnergetChildren() {
        return ;
    }
    @Override
    protected Description describeChild(Runner child) {
        return child.getDescription();
    }
    @Override
    protected void runChild(Runner runnerfinal RunNotifier notifier) {
        runner.run(notifier);
    }
New to GrepCode? Check out our FAQ X