1 /* 2 * Copyright (c) 2016 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockito.plugins; 6 7 import org.mockito.Incubating; 8 9 /** 10 * Allows switching off the plugins that are discovered on classpath. 11 * 12 * <p> 13 * Mockito will invoke this interface in order to select whether a plugin is enabled or not. 14 * </p> 15 * 16 * <p> 17 * When a particular plugin is switched off, the default Mockito behavior is used. 18 * For example, if Android's dexmaker MockMaker is switched off, 19 * Mockito default MockMaker implementation is used {@link org.mockito.plugins.MockMaker} 20 * </p> 21 * 22 * <h3>Using the extension point</h3> 23 * 24 * <p> 25 * The plugin mechanism of mockito works in a similar way as the {@link java.util.ServiceLoader}, however instead of 26 * looking in the <code>META-INF</code> directory, Mockito will look in <code>mockito-extensions</code> directory. 27 * <em>The reason for that is that Android SDK strips jar from the <code>META-INF</code> directory when creating an APK.</em> 28 * </p> 29 * 30 * <ol style="list-style-type: lower-alpha"> 31 * <li>The implementation itself, for example <code>org.awesome.mockito.AwesomeMockMaker</code> that extends the <code>MockMaker</code>.</li> 32 * <li>A file "<code>mockito-extensions/org.mockito.plugins.MockMaker</code>". The content of this file is 33 * exactly a <strong>one</strong> line with the qualified name: <code>org.awesome.mockito.AwesomeMockMaker</code>.</li> 34 * </ol></p> 35 * 36 * <p>Note that if several <code>mockito-extensions/org.mockito.plugins.MockMaker</code> files exists in the classpath 37 * Mockito will only use the first returned by the standard {@link ClassLoader#getResource} mechanism. 38 * <p> 39 * So just create a custom implementation of {@link PluginSwitch} and place the qualified name in the following file 40 * <code>mockito-extensions/org.mockito.plugins.PluginSwitch</code>. 41 * </p> 42 * 43 * @since 1.10.15 44 */ 45 @Incubating 46 public interface PluginSwitch { 47 48 /** 49 * Mockito invokes this method for every plugin found in the classpath 50 * (except from the {@code PluginSwitch} implementation itself). 51 * If no custom plugins are discovered this method is not invoked. 52 * 53 * @since 1.10.15 54 */ isEnabled(String pluginClassName)55 boolean isEnabled(String pluginClassName); 56 } 57