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

org.mockito.configuration.MockitoConfiguration Maven / Gradle / Ivy

Go to download

Contains a MockitoConfiguration that has to be loaded parent-first to work in continuous testing. It is separated from junit5-mockito to minimize the blast radius.

There is a newer version: 3.17.5
Show newest version
package org.mockito.configuration;

import java.lang.reflect.InvocationTargetException;

import org.mockito.stubbing.Answer;

public class MockitoConfiguration extends DefaultMockitoConfiguration {

    @SuppressWarnings("unchecked")
    @Override
    public Answer getDefaultAnswer() {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        try {
            // we need to load it from the TCCL (QuarkusClassLoader) instead of our class loader (JUnit CL)
            Class mutinyAnswer = cl.loadClass("io.quarkus.test.junit.mockito.internal.MutinyAnswer");
            return (Answer) mutinyAnswer.getDeclaredConstructor().newInstance();
        } catch (ClassNotFoundException | SecurityException | IllegalArgumentException | IllegalAccessException
                | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
            throw new RuntimeException("Failed to load MutinyAnswer from the TCCL", e);
        }
    }
}