// Path: powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/internal/configuration/PowerMockitoInjectingAnnotationEngine.java
// public class PowerMockitoInjectingAnnotationEngine extends InjectingAnnotationEngine {
// 
//     @SuppressWarnings("deprecation")
//     @Override
//     public AutoCloseable process(Class<?> context, Object testClass) {
//         // this will create @Spies:
//         new PowerMockitoSpyAnnotationEngine().process(context, testClass);
//         
//         preLoadPluginLoader();
//         
//         // this injects mocks
//         injectMocks(testClass);
//         return null;
//     }
//     
//     private void preLoadPluginLoader() {
//         final ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
// 
//         Thread.currentThread().setContextClassLoader(DefaultMockCreator.class.getClassLoader());
//         
//         try {
//             MockitoCore mc = new MockitoCore();
//             Plugins.getMockMaker();
//         } finally {
//             Thread.currentThread().setContextClassLoader(originalCL);
//         }
//     }
// }


import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Set;
import static org.mockito.Mockito.withSettings;
import static org.powermock.api.mockito.PowerMockito.mock;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockSettings;
import org.mockito.exceptions.base.MockitoException;
import org.mockito.internal.configuration.InjectingAnnotationEngine;
import org.mockito.internal.util.reflection.GenericMaster;
import org.powermock.api.mockito.internal.configuration.PowerMockitoInjectingAnnotationEngine;
import org.powermock.core.spi.listener.AnnotationEnablerListener;
import org.powermock.core.spi.support.AbstractPowerMockTestListenerBase;
import org.powermock.reflect.Whitebox;
import java.lang.annotation.Annotation;
/*
 *   Copyright 2016 the original author or authors.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */
package org.powermock.api.extension.listener;




/**
 * Before each test method all fields annotated with {@link Mock},
 * {@link org.mockito.Mock} or {@link Mock} have mock objects created for them
 * and injected to the fields. It will also delegate to a special implementation
 * of the {@link InjectingAnnotationEngine} in Mockito which inject's spies,
 * captors etc.
 * <p/>
 * It will only inject to fields that haven't been set before (i.e that are
 * {@code null}).
 */
@SuppressWarnings("deprecation")
public class AnnotationEnabler extends AbstractPowerMockTestListenerBase implements AnnotationEnablerListener {

    @Override
    public void beforeTestMethod(Object testInstance, Method method, Object[] arguments) throws Exception {
        standardInject(testInstance);
        injectSpiesAndInjectToSetters(testInstance);
        injectCaptor(testInstance);
    }

    private void injectSpiesAndInjectToSetters(Object testInstance) {
// Path: powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/mockito/internal/configuration/PowerMockitoInjectingAnnotationEngine.java
// public class PowerMockitoInjectingAnnotationEngine extends InjectingAnnotationEngine {
// 
//     @SuppressWarnings("deprecation")
//     @Override
//     public AutoCloseable process(Class<?> context, Object testClass) {
//         // this will create @Spies:
//         new PowerMockitoSpyAnnotationEngine().process(context, testClass);
//         
//         preLoadPluginLoader();
//         
//         // this injects mocks
//         injectMocks(testClass);
//         return null;
//     }
//     
//     private void preLoadPluginLoader() {
//         final ClassLoader originalCL = Thread.currentThread().getContextClassLoader();
// 
//         Thread.currentThread().setContextClassLoader(DefaultMockCreator.class.getClassLoader());
//         
//         try {
//             MockitoCore mc = new MockitoCore();
//             Plugins.getMockMaker();
//         } finally {
//             Thread.currentThread().setContextClassLoader(originalCL);
//         }
//     }
// }


// Path: powermock-api/powermock-api-mockito2/src/main/java/org/powermock/api/extension/listener/AnnotationEnabler.java
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Set;
import static org.mockito.Mockito.withSettings;
import static org.powermock.api.mockito.PowerMockito.mock;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockSettings;
import org.mockito.exceptions.base.MockitoException;
import org.mockito.internal.configuration.InjectingAnnotationEngine;
import org.mockito.internal.util.reflection.GenericMaster;
import org.powermock.api.mockito.internal.configuration.PowerMockitoInjectingAnnotationEngine;
import org.powermock.core.spi.listener.AnnotationEnablerListener;
import org.powermock.core.spi.support.AbstractPowerMockTestListenerBase;
import org.powermock.reflect.Whitebox;
import java.lang.annotation.Annotation;

/*
 *   Copyright 2016 the original author or authors.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */
package org.powermock.api.extension.listener;




/**
 * Before each test method all fields annotated with {@link Mock},
 * {@link org.mockito.Mock} or {@link Mock} have mock objects created for them
 * and injected to the fields. It will also delegate to a special implementation
 * of the {@link InjectingAnnotationEngine} in Mockito which inject's spies,
 * captors etc.
 * <p/>
 * It will only inject to fields that haven't been set before (i.e that are
 * {@code null}).
 */
@SuppressWarnings("deprecation")
public class AnnotationEnabler extends AbstractPowerMockTestListenerBase implements AnnotationEnablerListener {

    @Override
    public void beforeTestMethod(Object testInstance, Method method, Object[] arguments) throws Exception {
        standardInject(testInstance);
        injectSpiesAndInjectToSetters(testInstance);
        injectCaptor(testInstance);
    }

    private void injectSpiesAndInjectToSetters(Object testInstance) {
        new PowerMockitoInjectingAnnotationEngine().process(testInstance.getClass(), testInstance);