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

com.fitbur.mockito.internal.runners.RunnerFactory Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package com.fitbur.mockito.internal.runners;

import com.fitbur.mockito.exceptions.base.MockitoException;
import com.fitbur.mockito.internal.runners.util.RunnerProvider;
import com.fitbur.mockito.internal.runners.util.TestMethodsFinder;

import java.lang.reflect.InvocationTargetException;

public class RunnerFactory {

    private final RunnerProvider runnerProvider;

    RunnerFactory(RunnerProvider runnerProvider) {
        this.runnerProvider = runnerProvider;
    }

    public RunnerFactory() {
        this(new RunnerProvider());
    }

    public RunnerImpl create(Class klass) throws InvocationTargetException {
        try {
            //TODO invoke with regular exception
            return runnerProvider.newInstance("com.fitbur.mockito.internal.runners.JUnit45AndHigherRunnerImpl", klass);
        } catch (InvocationTargetException e) {
            if (!new TestMethodsFinder().hasTestMethods(klass)) {
                throw new MockitoException(
                    "\n" +
                    "\n" +
                    "No tests found in " + klass.getSimpleName() + "\n" +
                    "Haven't you forgot @Test annotation?\n"
                    , e);
            }
            throw e;
        } catch (Throwable t) {
            throw new MockitoException(
                    "\n" +
                    "\n" +
                    "MockitoRunner can only be used with JUnit 4.5 or higher.\n" +
                    "You can upgrade your JUnit version or write your own Runner (please consider contributing your runner to the Mockito community).\n" +
                    "Bear in mind that you can still enjoy all features of the framework without using runners (they are completely optional).\n" +
                    "If you get this error despite using JUnit 4.5 or higher then please report this error to the mockito mailing list.\n"
                    , t);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy