Home | History | Annotate | Download | only in runners
      1 /*
      2  * Copyright (c) 2007 Mockito contributors
      3  * This program is made available under the terms of the MIT License.
      4  */
      5 
      6 package org.mockito.internal.runners;
      7 
      8 import org.junit.internal.runners.InitializationError;
      9 import org.junit.internal.runners.JUnit4ClassRunner;
     10 import org.junit.runner.Description;
     11 import org.junit.runner.manipulation.Filter;
     12 import org.junit.runner.manipulation.NoTestsRemainException;
     13 import org.junit.runner.notification.RunNotifier;
     14 import org.mockito.MockitoAnnotations;
     15 import org.mockito.internal.runners.util.FrameworkUsageValidator;
     16 
     17 @SuppressWarnings("deprecation")
     18 public class JUnit44RunnerImpl implements RunnerImpl {
     19 
     20 	JUnit4ClassRunner runner;
     21 
     22     public JUnit44RunnerImpl(Class<?> klass) throws InitializationError {
     23         this.runner = new JUnit4ClassRunner(klass) {
     24             @Override
     25             protected Object createTest() throws Exception {
     26                 Object test = super.createTest();
     27                 MockitoAnnotations.initMocks(test);
     28                 return test;
     29             }
     30         };
     31     }
     32 
     33     public void run(RunNotifier notifier) {
     34         // add listener that validates framework usage at the end of each test
     35         notifier.addListener(new FrameworkUsageValidator(notifier));
     36 
     37         runner.run(notifier);
     38     }
     39 
     40     public Description getDescription() {
     41         return runner.getDescription();
     42     }
     43 
     44 	public void filter(Filter filter) throws NoTestsRemainException {
     45 		runner.filter(filter);
     46 	}
     47 }