Search in sources :

Example 1 with GwtTestWithMockito

use of com.googlecode.gwt.test.GwtTestWithMockito in project gwt-test-utils by gwt-test-utils.

the class GwtMockitoAnnotations method processInjectMocks.

private static void processInjectMocks(GwtTestWithMockito testInstance) {
    GwtMockitoUtils.getMockFields(testInstance.getClass(), InjectMocks.class).forEach(injectMocksField -> {
        try {
            GwtReflectionUtils.makeAccessible(injectMocksField);
            Object injectMocks = injectMocksField.get(testInstance);
            testInstance.getAllMocksByType().forEach((key, value) -> GwtReflectionUtils.getFields(injectMocks.getClass()).stream().filter(field -> field.getType().isAssignableFrom(key)).forEach(field -> {
                try {
                    GwtReflectionUtils.makeAccessible(field);
                    Object mock = field.get(injectMocks);
                    if (mock == null) {
                        field.set(injectMocks, value);
                    }
                } catch (IllegalAccessException e) {
                    // should never append
                    throw new GwtTestException("", e);
                }
            }));
        } catch (IllegalAccessException e) {
            // should never append
            throw new GwtTestException("", e);
        }
    });
}
Also used : InjectMocks(org.mockito.InjectMocks) MockitoAnnotations(org.mockito.MockitoAnnotations) GwtTestException(com.googlecode.gwt.test.exceptions.GwtTestException) Annotation(java.lang.annotation.Annotation) Set(java.util.Set) GwtReflectionUtils(com.googlecode.gwt.test.utils.GwtReflectionUtils) Field(java.lang.reflect.Field) GwtTestWithMockito(com.googlecode.gwt.test.GwtTestWithMockito) GwtTestException(com.googlecode.gwt.test.exceptions.GwtTestException) InjectMocks(org.mockito.InjectMocks)

Aggregations

GwtTestWithMockito (com.googlecode.gwt.test.GwtTestWithMockito)1 GwtTestException (com.googlecode.gwt.test.exceptions.GwtTestException)1 GwtReflectionUtils (com.googlecode.gwt.test.utils.GwtReflectionUtils)1 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 Set (java.util.Set)1 InjectMocks (org.mockito.InjectMocks)1 MockitoAnnotations (org.mockito.MockitoAnnotations)1