Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 the original author or authors.
   *
   * 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.
  */
 
 package org.callbackparams.junit4;
 

Author(s):
Henrik Kaipe
 
 class Junit3RunWrapper extends RunWrapper {
 
     /* Initial value might be updated by isCallbackTestCase(...) */
     private boolean isCallbackTestCase = false;
 
     /* Initial value might be updated by isSuiteMethodTest(...) */
     private boolean isSuiteMethodTest = false;
 
     @Override
     void run(CallbackRunListener callbackRunListener) {
         if () {
             {
                 /*
                  * This block is a somewhat ugly workaround to get
                  * callback-context into a proper state */
                 CallbackTestClassReloader classReloader =
                         (CallbackTestClassReloader)
                         .getClassLoader();
                 classReloader.getCallbackContext();
             }
 
             RunNotifier outerNotifier = new RunNotifier();
             outerNotifier.addListener(callbackRunListener);
             createRunner().run(outerNotifier);
         } else {
             super.run(callbackRunListener);
         }
     }
 
         if () {
             return Version.newJunit38SuiteRunner();
         } else {
             return Version.newJunit38Runner();
         }
     }

    

Returns:
true if the test-class seems to be based on the JUnit-3.x API and therewith makes this run-wrapper initialize properly; false otherwise, ie this run-wrapper can not used and the test-class must be run with a JUnit-4.x run-wrapper.
 
     boolean tryInitTestClass(Class<?> testClassthrows ClassNotFoundException {
         if (isSuiteMethodTest(testClass) || isCallbackTestCase(testClass)
                 || TestCase.class.isAssignableFrom(testClass)) {
             CallbackTestClassReloader classReloader =
                     CallbackTestClassReloader.newInstance(
                     testClass, WrappedRunnnerReloadFilter.getInstance(),
                     new RebyteInfo() {
                 public void putNoargProxyMethod(
                         String proxyMethodNameMethod callbackProxiedMethod) {
                     .put(
                             proxyMethodNamecallbackProxiedMethod.getName());
                 }
                 @Override
                 public boolean isCallbackInjectField(Field f) {
                     if (false == f.isAnnotationPresent(CallbackField.class)) {
                         return false;
                     } else if (f.getType().isInterface()) {
                         return true;
                     } else {
                         throw new RuntimeException("The type of a " +
                                 "@CallbackField-annotated field must be an " +
                                 "interface (" + f + ')');
                    }
                }
            });
            this. =
                    classReloader.loadClass(testClass.getName());
            return true;
        } else {
            return false;
        }
    }
    private boolean isSuiteMethodTest(Class<?> testClass) {
        try {
            Method suiteMethod = testClass.getMethod("suite");
            this. =
                    Test.class.isAssignableFrom(suiteMethod.getReturnType());
            return this.;
        } catch (NoSuchMethodException ex) {
            return false;
        }
    }
    private boolean isCallbackTestCase(Class<?> testClass) {
         = CallbackTestCase.class.isAssignableFrom(testClass);
        return ;
    }
New to GrepCode? Check out our FAQ X