}
@Override
public void prepareTestInstance(TestContext context) {
List<Field> mocks = context.introspector().selectFields(fieldsAnnotatedBy(Mock.class));
Mockery mockery = findProvidedMockery(context);
if (mockery == null) {
mockery = new Mockery();
for (Field mock : mocks) {
if (!mock.getType().isInterface()) {
mockery.setImposteriser(ClassImposteriser.INSTANCE);
break;
}
}
}
context.attributes().set(MOCKERY, mockery);
for (Field field : context.introspector().selectFields(and(fieldsAccepting(Mockery.class), fieldsAnnotatedBy(MockContext.class)))) {
context.introspector().set(field, mockery);
}
for (Field field : mocks) {
context.introspector().set(field, mockery.mock(field.getType(), field.getDeclaringClass().getName() + "." + field.getName()));
}
}