Package org.mockito.internal.util.reflection

Examples of org.mockito.internal.util.reflection.FieldReader


    private static Set<Field> scanForInjection(Object testClass, Class<?> clazz) {
        Set<Field> testedFields = new HashSet<Field>();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (null != field.getAnnotation(InjectMocks.class)) {
                if(new FieldReader(testClass, field).isNull()) {
                    new Reporter().injectMockAnnotationFieldIsNull(field.getName());
                }
                testedFields.add(field);
            }
        }
View Full Code Here


     */
    private Set<Object> scan() {
        Set<Object> mocks = newMockSafeHashSet();
        for (Field field : clazz.getDeclaredFields()) {
            // mock or spies only
            FieldReader fieldReader = new FieldReader(instance, field);

            Object mockInstance = preparedMock(fieldReader.read(), field);
            if (mockInstance != null) {
                mocks.add(mockInstance);
            }
        }
        return mocks;
View Full Code Here

*/
public class SpyOnInjectedFieldsHandler extends MockInjectionStrategy {

    @Override
    protected boolean processInjection(Field field, Object fieldOwner, Set<Object> mockCandidates) {
        FieldReader fieldReader = new FieldReader(fieldOwner, field);

        // TODO refoctor : code duplicated in SpyAnnotationEngine
        if(!fieldReader.isNull() && field.isAnnotationPresent(Spy.class)) {
            try {
                Object instance = fieldReader.read();
                if (new MockUtil().isMock(instance)) {
                    // A. instance has been spied earlier
                    // B. protect against multiple use of MockitoAnnotations.initMocks()
                    Mockito.reset(instance);
                } else {
View Full Code Here

     */
    private Set<Object> scan() {
        Set<Object> mocks = newMockSafeHashSet();
        for (Field field : clazz.getDeclaredFields()) {
            // mock or spies only
            FieldReader fieldReader = new FieldReader(instance, field);

            Object mockInstance = preparedMock(fieldReader.read(), field);
            if (mockInstance != null) {
                mocks.add(mockInstance);
            }
        }
        return mocks;
View Full Code Here

    private static Set<Field> scanForInjection(Object testClass, Class<?> clazz) {
        Set<Field> testedFields = new HashSet<Field>();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (null != field.getAnnotation(InjectMocks.class)) {
                if(new FieldReader(testClass, field).isNull()) {
                    new Reporter().injectMockAnnotationFieldIsNull(field.getName());
                }
                testedFields.add(field);
            }
        }
View Full Code Here

    */
   private Set<Object> scan() {
      Set<Object> mocks = newMockSafeHashSet();
      for (Field field : clazz.getDeclaredFields()) {
         // mock or spies only
         FieldReader fieldReader = new FieldReader(instance, field);

         Object mockInstance = preparedMock(fieldReader.read(), field);
         if (mockInstance != null) {
            mocks.add(mockInstance);
         }
      }
      return mocks;
View Full Code Here

TOP

Related Classes of org.mockito.internal.util.reflection.FieldReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.