use of org.mockito.exceptions.Reporter in project gwt-test-utils by gwt-test-utils.
the class GwtSpyAnnotationEngine method process.
@Override
@SuppressWarnings("deprecation")
public // for MockitoAnnotations.Mock
void process(Class<?> context, Object testInstance) {
Field[] fields = context.getDeclaredFields();
for (Field field : fields) {
if (field.isAnnotationPresent(Spy.class) && !field.isAnnotationPresent(InjectMocks.class)) {
assertNoIncompatibleAnnotations(Spy.class, field, com.googlecode.gwt.test.Mock.class, Mock.class, org.mockito.MockitoAnnotations.Mock.class, Captor.class);
Object instance = null;
try {
FieldInitializationReport report = new FieldInitializer(testInstance, field).initialize();
instance = report.fieldInstance();
} catch (MockitoException e) {
new Reporter().cannotInitializeForSpyAnnotation(field.getName(), e);
}
try {
if (new MockUtil().isMock(instance)) {
// instance has been spied earlier
// for example happens when MockitoAnnotations.initMocks is called two times.
Mockito.reset(instance);
} else {
field.setAccessible(true);
field.set(testInstance, Mockito.mock(instance.getClass(), withSettings().spiedInstance(instance).defaultAnswer(Mockito.CALLS_REAL_METHODS).name(field.getName())));
}
} catch (IllegalAccessException e) {
throw new MockitoException("Problems initiating spied field " + field.getName(), e);
}
}
}
}
use of org.mockito.exceptions.Reporter in project powermock by powermock.
the class PowerMockMatchersBinder method validateMatchers.
private void validateMatchers(Invocation invocation, List<LocalizedMatcher> lastMatchers) {
if (!lastMatchers.isEmpty()) {
int recordedMatchersSize = lastMatchers.size();
int expectedMatchersSize = invocation.getArguments().length;
if (expectedMatchersSize != recordedMatchersSize) {
new Reporter().invalidUseOfMatchers(expectedMatchersSize, lastMatchers);
}
}
}
Aggregations