} else { boolean inVerificationMode = isInVerificationMode(); if (WhiteboxImpl.isClass(obj) && inVerificationMode) { handleStaticVerification((Class<?>) obj);
public java.lang.reflect.Constructor findConstructor() { lookupPotentialConstructor(); throwExceptionIfConstructorWasNotFound(); return potentialConstructor.getJavaConstructor(); }
public MockGetawayCall(final Class mockGetawayClass) { getawayMethod = WhiteboxImpl.getMethod( mockGetawayClass, "suppressConstructorCall", Class.class, Object[].class, Class[].class ); }
/** * Find field in hierarchy. * * @param object the object * @param strategy the strategy * @return the field */ private static Field findFieldInHierarchy(Object object, FieldMatcherStrategy strategy) { assertObjectInGetInternalStateIsNotNull(object); return findSingleFieldUsingStrategy(strategy, object, true, getType(object)); }
@SuppressWarnings("UnusedDeclaration") public static Object fieldCall(Object instanceOrClassContainingTheField, Class<?> classDefiningField, String fieldName, Class<?> fieldType) { if (MockRepository.shouldSuppressField(WhiteboxImpl.getField(classDefiningField, fieldName))) { return TypeUtils.getDefaultValue(fieldType); } return PROCEED; }
/** * Get all fields in a class hierarchy. * * @param clazz * The class that should contain the fields. * @return An array of Field's. May be of length 0 but not {@code null} * */ public static Field[] fields(Class<?> clazz) { return WhiteboxImpl.getAllFields(clazz); }
private void lookupPotentialConstructor() {Set<Constructor> constructors = getDeclaredConstructorsWithoutPowerMockConstructor(); for (Constructor constructor : constructors) { if (constructor.canBeInvokeWith(arguments)) { setPotentialConstructor(constructor); } // if a constructor is found and it has varargs parameters then the constructor will be used even if // other constructor is matcher the given arguments. It is done, because when Argument Matchers are used // arguments passed to the method are null value and it's imposable to determinate whether parameters // match to arguments or not. if (isVarArgConstructorFound()){ return; } } }
/** * Invoke a private or inner class method in that is located in a subclass * of the instance. This might be useful to test private methods. * * @throws Exception * Exception that may occur when invoking this method. */ public static synchronized <T> T invokeMethod(Object instance, Class<?> declaringClass, String methodToExecute, Object... arguments) throws Exception { return WhiteboxImpl.<T> invokeMethod(instance, declaringClass, methodToExecute, arguments); }
/** * Get the first parent constructor defined in a super class of * <code>klass</code>. * * @param klass * The class where the constructor is located. <code>null</code> * ). * @return A <code>java.lang.reflect.Constructor</code>. */ public static Constructor<?> getFirstParentConstructor(Class<?> klass) { return WhiteboxImpl.getFirstParentConstructor(klass); }
/** * Set the value of a field using reflection. This method will traverse the * super class hierarchy until a field with name <tt>fieldName</tt> is * found. * * @param object the object to modify * @param fieldName the name of the field * @param value the new value of the field */ public static void setInternalState(Object object, String fieldName, Object[] value) { setInternalState(object, fieldName, (Object) value); }
/** * Get all static fields for a particular type. * * @param type * The class whose static fields to get. * @return All static fields in {@code type}. All fields are set to * accessible. */ public static Set<Field> getAllStaticFields(Class<?> type) { return WhiteboxImpl.getAllStaticFields(type); }
public boolean match() { if ((arguments != null && (parameterTypes.length == arguments.length))) { if (parameterTypes.length == 0) { return true; } return checkArgumentTypesMatchParameterTypes(isVarArgs, parameterTypes, arguments); } else if (doesParameterTypesMatchForVarArgsInvocation(arguments)) { return true; } else { return false; } }
/** * Find field. * * @param object the object * @param strategy the strategy * @param where the where * @return the field */ private static Field findField(Object object, FieldMatcherStrategy strategy, Class<?> where) { return findSingleFieldUsingStrategy(strategy, object, false, where); }
/** * Gets the type. * * @param object the object * @return The type of the of an object. */ public static Class<?> getUnproxyType(Object object) { return WhiteboxImpl.getUnproxyType(object); }
/** * Invoke a private or inner class static method without the need to specify * the method name. This is thus a more refactor friendly version of the * {@link #invokeMethod(Class, String, Object...)} method and is recommend * over this method for that reason. This method might be useful to test * private methods. * */ public static synchronized <T> T invokeMethod(Class<?> klass, Object... arguments) throws Exception { return WhiteboxImpl.<T> invokeMethod(klass, arguments); }
/** * Register a proxy framework. * * @param proxyFramework * The proxy framework to register. */ public static void registerProxyFramework(ProxyFramework proxyFramework) { WhiteboxImpl.setInternalState(WhiteboxImpl.class, proxyFramework); } }
/** * Get all static fields for a particular type. * * @param type * The class whose static fields to get. * @return All static fields in <code>type</code>. All fields are set to * accessible. */ public static Set<Field> getAllStaticFields(Class<?> type) { return WhiteboxImpl.getAllStaticFields(type); }
/** * Invoke a private or inner class method in that is located in a subclass * of the instance. This might be useful to test private methods. * * @throws Exception * Exception that may occur when invoking this method. */ public static synchronized <T> T invokeMethod(Object instance, Class<?> declaringClass, String methodToExecute, Object... arguments) throws Exception { return WhiteboxImpl.invokeMethod(instance, declaringClass, methodToExecute, arguments); }
/** * Invoke a static private or inner class method. This may be useful to test * private methods. * */ public static synchronized <T> T invokeMethod(Class<?> clazz, String methodToExecute, Object... arguments) throws Exception { return WhiteboxImpl.invokeMethod(clazz, methodToExecute, arguments); }