Search in sources :

Example 1 with InjectMock

use of io.quarkus.test.junit.mockito.InjectMock in project quarkus by quarkusio.

the class CreateMockitoMocksCallback method afterConstruct.

@Override
public void afterConstruct(Object testInstance) {
    Class<?> current = testInstance.getClass();
    while (current.getSuperclass() != null) {
        for (Field field : current.getDeclaredFields()) {
            InjectMock injectMockAnnotation = field.getAnnotation(InjectMock.class);
            if (injectMockAnnotation != null) {
                boolean returnsDeepMocks = injectMockAnnotation.returnsDeepMocks();
                Object beanInstance = getBeanInstance(testInstance, field, InjectMock.class);
                Optional<Object> result = createMockAndSetTestField(testInstance, field, beanInstance, new MockConfiguration(returnsDeepMocks));
                if (result.isPresent()) {
                    MockitoMocksTracker.track(testInstance, result.get(), beanInstance);
                }
            }
        }
        current = current.getSuperclass();
    }
}
Also used : Field(java.lang.reflect.Field) InjectMock(io.quarkus.test.junit.mockito.InjectMock)

Aggregations

InjectMock (io.quarkus.test.junit.mockito.InjectMock)1 Field (java.lang.reflect.Field)1