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);
}
});
}
Aggregations