Scan and prepare mocks for the given <code>testClassInstance</code> and <code>clazz</code> in the type hierarchy.

@return A prepared set of mock
181146
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;
    }
1342280
public static Object loadInstance(Class clazz) throws ClassException {
	try {
	    return clazz.newInstance();
	}
	catch (InstantiationException e) {
	    throw new ClassException("the specified class object [" + clazz.getName() + "()] cannot be instantiated");
	}
	catch (IllegalAccessException e) {
	    throw new ClassException("can't load class because the currently executing method does not have access to the definition of the specified class");
	}
    }
758008
public static ConstructorParameterPair getConstructorParameterPairIgnoreCase(Class clazz, Object[] parameters) throws NoSuchMethodException {
	// set all values
	// Class objectClass=object.getClass();
	if (parameters == null) parameters = new Object[0];

	// set parameter classes
	Class[] parameterClasses = new Class[parameters.length];
	for (int i = 0; i < parameters.length; i++) {
	    parameterClasses[i] = parameters[i].getClass();
	}

	// search right method
	Constructor[] constructor = clazz.getConstructors();
	for (int mode = 0; mode < 2; mode++) {
	    outer: for (int i = 0; i < constructor.length; i++) {
		Constructor c = constructor[i];

		Class[] paramTrg = c.getParameterTypes();
		// Same Parameter count
		if (parameterClasses.length == paramTrg.length) {
		    for (int y = 0; y < parameterClasses.length; y++) {
			if (mode == 0 && parameterClasses[y] != primitiveToWrapperType(paramTrg[y])) {
			    continue outer;
			}
			else if (mode == 1) {
			    Object o = compareClasses(parameters[y], paramTrg[y]);
			    if (o == null) continue outer;

			    parameters[y] = o;
			    parameterClasses[y] = o.getClass();

			}
		    }
		    return new ConstructorParameterPair(c, parameters);
		}

	    }
	}

	// Exeception
	String parameter = "";
	for (int i = 0; i < parameterClasses.length; i++) {
	    if (i != 0) parameter += ", ";
	    parameter += parameterClasses[i].getName();
	}
	throw new NoSuchMethodException("class constructor " + clazz.getName() + "(" + parameter + ") doesn't exist");
    }
80550
@SuppressWarnings("rawtypes")
    public static Class inferParameterClass(Class clazz, String methodName) {
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            if (method.getName().equals(methodName) && !method.isBridge()) {
                Type[] types = method.getGenericParameterTypes();
                for (Type type : types) {
                    if (type instanceof Class && !((Class) type).isInterface()) {
                        return ((Class) type);
                    }
                }
            }
        }
        return null;
    }
471316
public static Class<?>[] getAllInterfaces(Class<?> clz) {
    HashSet<Class<?>> set = new HashSet<>();
    getAllInterfaces(clz, set);
    return set.toArray(new Class<?>[set.size()]);
  }
640292
public Map<String, Class<?>> scan(String classNamePattern) throws IOException {
        final Map<String, Class<?>> scannedClasses = new LinkedHashMap<>();
        scan(classNamePattern, scannedClasses);
        return scannedClasses;
    }
668261
public static ClassLoader getClassLoader(Class<?> clazz) {
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        if (loader != null) {
            return loader;
        }
        if (clazz != null) {
            loader = clazz.getClassLoader();
            if (loader != null) {
                return loader;
            }
        }
        return ClassLoader.getSystemClassLoader();
    }
738255
@Override
    public <T> T createSpyComponent(final T instance) {
        checkArgument(instance != null, "instance must not be null!");
        if (isFinalOrPrimitive(instance.getClass())) {
            LOG.warn("Skipping creation of a spy : {} as it is final or primitive type.", instance.getClass()
                    .getSimpleName());
            return null;
        }
        return Mockito.spy(instance);
    }
894663
public static <T> T newInstance(final Class<T> clazz) {
        Constructor<?>[] constructors = getAllConstructorsOfClass(clazz, true);
        if (constructors == null || constructors.length == 0) {
            return null;
        }
        Object[] initParameters = getInitParameters(constructors[0].getParameterTypes());
        try {
            @SuppressWarnings("unchecked")
            T instance = (T) constructors[0].newInstance(initParameters);
            return instance;
        } catch (Exception e) {
            log.error("newInstance", e);
            return null;
        }
    }
84131
private static Set<QMethod> buildMethodSet(JavaClass cls) {
        Set<QMethod> methods = new HashSet<>();

        boolean isInterface = cls.isInterface();

        for (Method m : cls.getMethods()) {
            boolean isDefaultInterfaceMethod = isInterface && !m.isAbstract();

            boolean isSyntheticForParentCall;

            if (m.isSynthetic()) {
                BitSet bytecodeSet = ClassContext.getBytecodeSet(cls, m);
                isSyntheticForParentCall = (bytecodeSet != null) && bytecodeSet.get(Const.INVOKESPECIAL);
            } else {
                isSyntheticForParentCall = false;
            }

            if (!isSyntheticForParentCall && !isDefaultInterfaceMethod) {
                String methodName = m.getName();
                QMethod methodInfo = new QMethod(methodName, m.getSignature());

                if (!OBJECT_METHODS.contains(methodInfo)) {
                    if (!Values.CONSTRUCTOR.equals(methodName) && !Values.STATIC_INITIALIZER.equals(methodName)) {
                        methods.add(methodInfo);
                    }
                }
            }
        }

        return methods;
    }
994617
private Map<String, Class<?>> createPropertyMap(Class<?> clz) throws Exception
   {
      Map<String, Class<?>> result = new HashMap<>();

      for (Method m : clz.getMethods())
      {
         if (m.getName().startsWith("set"))
         {
            if (m.getReturnType().equals(Void.TYPE) &&
                m.getParameterCount() == 1 &&
                isSupported(m.getParameterTypes()[0]))
               result.put(m.getName().substring(3), m.getParameterTypes()[0]);
         }
      }
      
      return result;
   }
363018
@Override
    public void beforeEach(final ExtensionContext context) {
        Set<Object> testInstances = new LinkedHashSet<>();
        testInstances.add(context.getRequiredTestInstance());

        this.collectParentTestInstances(context, testInstances);

        Strictness actualStrictness = this.retrieveAnnotationFromTestClasses(context)
            .map(MockitoSettings::strictness)
            .orElse(strictness);

        MockitoSession session = Mockito.mockitoSession()
            .initMocks(testInstances.toArray())
            .strictness(actualStrictness)
            .logger(new MockitoSessionLoggerAdapter(Plugins.getMockitoLogger()))
            .startMocking();

        context.getStore(MOCKITO).put(SESSION, session);
    }
1297573
public static Builder forClass(Class clazz) {
        if (clazz == null) {
            throw new IllegalArgumentException("class can not be null");
        }
        return new Builder(Collections.singletonList(clazz));
    }
1291985
public Collection<T> getDescriptors(TestClass testClass) {
        final List<T> descriptors = new ArrayList<T>();
        for (Method testMethod : testClass.getMethods(resourceAnnotation)) {
            descriptors.addAll(getDescriptorsDefinedFor(testMethod));
        }
        descriptors.addAll(obtainClassLevelDescriptor(testClass.getAnnotation(resourceAnnotation)));
        return descriptors;
    }
1239709
public static <T> T getInstance(Class<T> clazz, Class<?>[] paramTypes, Object[] params) {
        Assert.isTrue(CollectionUtil.safeSizeOf(paramTypes) == CollectionUtil.safeSizeOf(params));
        try {
            Constructor<T> constructor = clazz.getConstructor(paramTypes);
            ReflectUtil.allowAccess(constructor);
            return constructor.newInstance(params);
        } catch (Exception e) {
            throw new ReflectException("获取类实例异常，可能是没有默认无参构造器", e);
        }
    }
936433
public static Class[] getSuperTypes(Class from) {
        ArrayList<Class> superclasses = new ArrayList<Class>();

        collectInterfaces( from, superclasses );
        while ( !from.equals( Object.class ) && !from.isInterface() ) {
            superclasses.add( from.getSuperclass() );
            from = from.getSuperclass();
            collectInterfaces( from, superclasses );
        }

        final Class[] classes = new Class[superclasses.size()];
        superclasses.toArray(classes);
        return classes;
    }
749418
public static ConstructorInstance getConstructorInstance(Class clazz, Object[] args) throws NoSuchMethodException {
	ConstructorInstance ci = getConstructorInstance(clazz, args, null);
	if (ci != null) return ci;
	throw new NoSuchMethodException("No matching Constructor for " + clazz.getName() + "(" + getDspMethods(getClasses(args)) + ") found");
    }