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 package org.mockito.runners;
      6 
      7 import java.lang.reflect.InvocationTargetException;
      8 import org.junit.runner.Description;
      9 import org.junit.runner.Runner;
     10 import org.junit.runner.manipulation.Filter;
     11 import org.junit.runner.manipulation.Filterable;
     12 import org.junit.runner.manipulation.NoTestsRemainException;
     13 import org.junit.runner.notification.Failure;
     14 import org.junit.runner.notification.RunListener;
     15 import org.junit.runner.notification.RunNotifier;
     16 import org.mockito.internal.debugging.WarningsCollector;
     17 import org.mockito.internal.junit.util.JUnitFailureHacker;
     18 import org.mockito.internal.runners.RunnerFactory;
     19 import org.mockito.internal.runners.InternalRunner;
     20 
     21 /**
     22  * @deprecated as of 2.1.0. Use the {@link org.mockito.junit.MockitoJUnitRunner} runner instead
     23  * which contains support for detecting unused stubs.
     24  * <p>
     25  * If you still prefer using this runner, tell us why (create ticket in our issue tracker).
     26  */
     27 @Deprecated
     28 public class VerboseMockitoJUnitRunner extends Runner implements Filterable {
     29 
     30     private final InternalRunner runner;
     31 
     32     public VerboseMockitoJUnitRunner(Class<?> klass) throws InvocationTargetException {
     33         this(new RunnerFactory().create(klass));
     34     }
     35 
     36     VerboseMockitoJUnitRunner(InternalRunner runner) {
     37         this.runner = runner;
     38     }
     39 
     40     @Override
     41     public void run(RunNotifier notifier) {
     42 
     43         //a listener that changes the failure's exception in a very hacky way...
     44         RunListener listener = new RunListener() {
     45 
     46             WarningsCollector warningsCollector;
     47 
     48             @Override
     49             public void testStarted(Description description) throws Exception {
     50                 warningsCollector = new WarningsCollector();
     51             }
     52 
     53             @Override
     54             @SuppressWarnings("deprecation")
     55             public void testFailure(final Failure failure) throws Exception {
     56                 String warnings = warningsCollector.getWarnings();
     57                 new JUnitFailureHacker().appendWarnings(failure, warnings);
     58             }
     59         };
     60 
     61         notifier.addFirstListener(listener);
     62 
     63         runner.run(notifier);
     64     }
     65 
     66     @Override
     67     public Description getDescription() {
     68         return runner.getDescription();
     69     }
     70 
     71     public void filter(Filter filter) throws NoTestsRemainException {
     72         //filter is required because without it UnrootedTests show up in Eclipse
     73         runner.filter(filter);
     74     }
     75 }
     76