All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.mockito.internal.junit.JUnitRule Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fitbur.mockito.internal.junit;

import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import com.fitbur.mockito.Mockito;
import com.fitbur.mockito.MockitoAnnotations;
import com.fitbur.mockito.internal.debugging.WarningsCollector;
import com.fitbur.mockito.internal.util.MockitoLogger;
import com.fitbur.mockito.junit.MockitoRule;

/**
 * Internal implementation.
 */
public class JUnitRule implements MockitoRule {
	
	private final MockitoLogger logger;

	public JUnitRule(MockitoLogger logger) {
		this.logger = logger;
	}
	@Override
	public Statement apply(final Statement base, FrameworkMethod method, final Object target) {
		return new Statement() {
            @Override
            public void evaluate() throws Throwable {
                WarningsCollector c = new WarningsCollector();
                MockitoAnnotations.initMocks(target);
                try {
                    base.evaluate();
                } catch(Throwable t) {
                    logger.log(c.getWarnings());
                    throw t;
                }
                Mockito.validateMockitoUsage();
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy