1 /* 2 * Copyright (c) 2017 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockito.junit; 6 7 import org.junit.runners.model.InitializationError; 8 import org.mockito.internal.junit.MismatchReportingTestListener; 9 import org.mockito.internal.junit.MockitoTestListener; 10 import org.mockito.internal.runners.RunnerFactory; 11 import org.mockito.internal.runners.StrictRunner; 12 import org.mockito.internal.util.SimpleMockitoLogger; 13 import org.mockito.internal.util.Supplier; 14 15 import java.lang.reflect.InvocationTargetException; 16 17 public class TestableJUnitRunner extends MockitoJUnitRunner { 18 19 private final static ThreadLocal<SimpleMockitoLogger> LOGGER = new ThreadLocal<SimpleMockitoLogger>() { 20 protected SimpleMockitoLogger initialValue() { 21 return new SimpleMockitoLogger(); 22 } 23 }; 24 TestableJUnitRunner(Class<?> klass)25 public TestableJUnitRunner(Class<?> klass) throws InvocationTargetException, InitializationError { 26 super(new StrictRunner(new RunnerFactory().create(klass, new Supplier<MockitoTestListener>() { 27 public MockitoTestListener get() { 28 return new MismatchReportingTestListener(LOGGER.get()); 29 } 30 }), klass)); 31 } 32 refreshedLogger()33 public static SimpleMockitoLogger refreshedLogger() { 34 return LOGGER.get().clear(); 35 } 36 } 37