Search in sources :

Example 1 with DefaultInjectionEngine

use of org.mockito.internal.configuration.DefaultInjectionEngine in project gwt-test-utils by gwt-test-utils.

the class GwtInjectingAnnotationEngine method injectMocks.

/**
     * Initializes mock/spies dependencies for objects annotated with @InjectMocks for given
     * testClassInstance.
     * <p>
     * See examples in javadoc for {@link MockitoAnnotations} class.
     *
     * @param testClassInstance Test class, usually <code>this</code>
     */
public void injectMocks(final Object testClassInstance) {
    Class<?> clazz = testClassInstance.getClass();
    Set<Field> mockDependentFields = new HashSet<Field>();
    Set<Object> mocks = newMockSafeHashSet();
    while (clazz != Object.class) {
        new InjectMocksScanner(clazz).addTo(mockDependentFields);
        new GwtMockScanner(testClassInstance, clazz).addPreparedMocks(mocks);
        clazz = clazz.getSuperclass();
    }
    new DefaultInjectionEngine().injectMocksOnFields(mockDependentFields, mocks, testClassInstance);
}
Also used : Field(java.lang.reflect.Field) InjectMocksScanner(org.mockito.internal.configuration.injection.scanner.InjectMocksScanner) DefaultInjectionEngine(org.mockito.internal.configuration.DefaultInjectionEngine) HashSet(java.util.HashSet) Sets.newMockSafeHashSet(org.mockito.internal.util.collections.Sets.newMockSafeHashSet)

Aggregations

Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 DefaultInjectionEngine (org.mockito.internal.configuration.DefaultInjectionEngine)1 InjectMocksScanner (org.mockito.internal.configuration.injection.scanner.InjectMocksScanner)1 Sets.newMockSafeHashSet (org.mockito.internal.util.collections.Sets.newMockSafeHashSet)1