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

org.mockito.internal.configuration.ConfigurationLoader Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package org.mockito.internal.configuration;

import org.mockito.configuration.IMockitoConfiguration;
import org.mockito.plugins.MockMaker;

import java.util.Optional;
import java.util.ServiceLoader;


/**
 * Loads configuration or extension points available in the classpath.
 *
 * 

*

    *
  • * Can load the mockito configuration. The user who want to provide his own mockito configuration * should write the class org.mockito.configuration.MockitoConfiguration that implements * {@link IMockitoConfiguration}. For example : *
    
     * package org.mockito.configuration;
     *
     * //...
     *
     * public class MockitoConfiguration implements IMockitoConfiguration {
     *     boolean enableClassCache() { return false; }
     *
     *     // ...
     * }
     *     
    *
  • *
  • * Can load available mockito extensions. Currently Mockito only have one extension point the * {@link MockMaker}. This extension point allows a user to provide his own bytecode engine to build mocks. *
    Suppose you wrote an extension to create mocks with some Awesome library, in order to tell * Mockito to use it you need to put in your classpath *
      *
    1. The implementation itself, for example org.awesome.mockito.AwesomeMockMaker.
    2. *
    3. A file named org.mockito.plugins.MockMaker in a folder named * mockito-extensions, the content of this file need to have one line with * the qualified name org.awesome.mockito.AwesomeMockMaker.
    4. *
    *
  • *
*

*/ public class ConfigurationLoader { /** * @return configuration loaded from classpath or null */ @SuppressWarnings({"unchecked"}) public IMockitoConfiguration loadConfiguration() { ServiceLoader serviceLoader = ServiceLoader.load(IMockitoConfiguration.class); Optional configClass = serviceLoader.findFirst(); return configClass.orElse(null); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy