Home | History | Annotate | Download | only in plugins
      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.internal.configuration.plugins;
      6 
      7 import org.mockito.plugins.AnnotationEngine;
      8 import org.mockito.plugins.InstantiatorProvider;
      9 import org.mockito.plugins.MockMaker;
     10 import org.mockito.plugins.PluginSwitch;
     11 import org.mockito.plugins.StackTraceCleanerProvider;
     12 
     13 class PluginRegistry {
     14 
     15     private final PluginSwitch pluginSwitch = new PluginLoader(new DefaultPluginSwitch())
     16             .loadPlugin(PluginSwitch.class, DefaultPluginSwitch.class.getName());
     17 
     18     private final MockMaker mockMaker = new PluginLoader(pluginSwitch)
     19             .withAlias("mock-maker-inline", "org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker")
     20             .loadPlugin(MockMaker.class, "org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker");
     21 
     22     private final StackTraceCleanerProvider stackTraceCleanerProvider = new PluginLoader(pluginSwitch)
     23             .loadPlugin(StackTraceCleanerProvider.class, "org.mockito.internal.exceptions.stacktrace.DefaultStackTraceCleanerProvider");
     24 
     25     private final InstantiatorProvider instantiatorProvider = new PluginLoader(pluginSwitch)
     26             .loadPlugin(InstantiatorProvider.class, "org.mockito.internal.creation.instance.DefaultInstantiatorProvider");
     27 
     28     private AnnotationEngine annotationEngine = new PluginLoader(pluginSwitch)
     29             .loadPlugin(AnnotationEngine.class, "org.mockito.internal.configuration.InjectingAnnotationEngine");
     30 
     31     /**
     32      * The implementation of the stack trace cleaner
     33      */
     34     StackTraceCleanerProvider getStackTraceCleanerProvider() {
     35         //TODO we should throw some sensible exception if this is null.
     36         return stackTraceCleanerProvider;
     37     }
     38 
     39     /**
     40      * Returns the implementation of the mock maker available for the current runtime.
     41      *
     42      * <p>Returns {@link org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker} if no
     43      * {@link org.mockito.plugins.MockMaker} extension exists or is visible in the current classpath.</p>
     44      */
     45     MockMaker getMockMaker() {
     46         return mockMaker;
     47     }
     48 
     49     /**
     50      * Returns the instantiator provider available for the current runtime.
     51      *
     52      * <p>Returns {@link org.mockito.internal.creation.instance.DefaultInstantiatorProvider} if no
     53      * {@link org.mockito.plugins.InstantiatorProvider} extension exists or is visible in the current classpath.</p>
     54      */
     55     InstantiatorProvider getInstantiatorProvider() {
     56       return instantiatorProvider;
     57     }
     58 
     59     /**
     60      * Returns the annotation engine available for the current runtime.
     61      *
     62      * <p>Returns {@link org.mockito.internal.configuration.InjectingAnnotationEngine} if no
     63      * {@link org.mockito.plugins.AnnotationEngine} extension exists or is visible in the current classpath.</p>
     64      */
     65     AnnotationEngine getAnnotationEngine() {
     66         return annotationEngine;
     67     }
     68 }
     69