private void injectCaptor(Object testInstance) throws Exception { Set<Field> fieldsAnnotatedWithCaptor = Whitebox.getFieldsAnnotatedWith(testInstance, Captor.class); for (Field field : fieldsAnnotatedWithCaptor) { final Object captor = processAnnotationOn(field.getAnnotation(Captor.class), field); field.set(testInstance, captor); } }
private void standardInject(Object testInstance) throws IllegalAccessException { Set<Field> fields = Whitebox.getFieldsAnnotatedWith(testInstance, getMockAnnotations()); for (Field field : fields) { if (field.get(testInstance) != null) {
private void clearMockFields(Object target, Object annotationEnabler) throws Exception { if (annotationEnabler != null) { Class<? extends Annotation>[] mockAnnotations = Whitebox.invokeMethod(annotationEnabler, "getMockAnnotations"); Set<Field> mockFields = Whitebox.getFieldsAnnotatedWith(target, mockAnnotations); for (Field field : mockFields) { field.set(target, null); } } }
private void clearMockFields() throws Exception { if (annotationEnabler != null) { final Class<? extends Annotation>[] mockAnnotations = Whitebox.invokeMethod(annotationEnabler, "getMockAnnotations"); Set<Field> mockFields = Whitebox.getFieldsAnnotatedWith(this, mockAnnotations); for (Field field : mockFields) { field.set(this, null); } } }
private void clearMockFields() throws Exception, IllegalAccessException { if (annotationEnabler != null) { Set<Field> mockFields = Whitebox.getFieldsAnnotatedWith(this, Whitebox .<Class<? extends Annotation>[]> invokeMethod(annotationEnabler, "getMockAnnotations")); for (Field field : mockFields) { field.set(this, null); } } }
private void injectCaptor(Object testInstance) throws Exception { Set<Field> fieldsAnnotatedWithCaptor = Whitebox.getFieldsAnnotatedWith(testInstance, Captor.class); for (Field field : fieldsAnnotatedWithCaptor) { final Object captor = processAnnotationOn(field.getAnnotation(Captor.class), field); field.set(testInstance, captor); } }
public void inject(Object testInstance, Class<? extends Annotation> annotation) throws Exception { Set<Field> fields = Whitebox.getFieldsAnnotatedWith(testInstance, annotation); for (Field field : fields) { if (field.get(testInstance) != null) { continue; } final Class<?> type = field.getType(); Annotation annotationInstance = field.getAnnotation(annotation); final String[] value = (String[]) Whitebox.invokeMethod(annotationInstance, "value"); Method[] methods = null; if (value.length != 1 || !"".equals(value[0])) { methods = Whitebox.getMethods(type, value); } final Object createMock = createMockInstance(type, methods); field.set(testInstance, createMock); } }
private void standardInject(Object testInstance) throws IllegalAccessException { Set<Field> fields = Whitebox.getFieldsAnnotatedWith(testInstance, getMockAnnotations()); for (Field field : fields) { if (field.get(testInstance) != null) { continue; } final Class<?> type = field.getType(); if (field.isAnnotationPresent(org.mockito.Mock.class)) { org.mockito.Mock mockAnnotation = field.getAnnotation(org.mockito.Mock.class); MockSettings mockSettings = withSettings(); Answers answers = mockAnnotation.answer(); if (answers != null) { mockSettings.defaultAnswer(answers.get()); } Class<?>[] extraInterfaces = mockAnnotation.extraInterfaces(); if (extraInterfaces != null && extraInterfaces.length > 0) { mockSettings.extraInterfaces(extraInterfaces); } String name = mockAnnotation.name(); if (name != null && name.length() > 0) { mockSettings.name(name); } field.set(testInstance, mock(type, mockSettings)); } else { field.set(testInstance, mock(type)); } } }