For IntelliJ IDEA,
Android Studio or Eclipse



} else { boolean inVerificationMode = isInVerificationMode(); if (WhiteboxImpl.isClass(obj) && inVerificationMode) { handleStaticVerification((Class<?>) obj);
@SuppressWarnings("unchecked") private static <T> IExpectationSetters<T> doExpectPrivate(Object instance, Method methodToExpect, Object... arguments) throws Exception { WhiteboxImpl.performMethodInvocation(instance, methodToExpect, arguments); return (IExpectationSetters<T>) org.easymock.EasyMock.expectLastCall(); }
@SuppressWarnings("UnusedDeclaration") public static Object constructorCall(Class<?> type, Object[] args, Class<?>[] sig) throws Throwable { final Constructor<?> constructor = WhiteboxImpl.getConstructor(type, sig); if (MockRepository.shouldSuppressConstructor(constructor)) { return null; } return PROCEED; }
private void init() { if (object instanceof Class<?>) { objectType = (Class<?>) object; methodInvocationControl = MockRepository.getStaticMethodInvocationControl(objectType); } else { final Class<?> type = object.getClass(); UnproxiedType unproxiedType = WhiteboxImpl.getUnproxiedType(type); objectType = unproxiedType.getOriginalType(); methodInvocationControl = MockRepository.getInstanceMethodInvocationControl(object); } method = findMethodToInvoke(methodName, sig, objectType); }
/** * 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); }
/** * 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); }
/** * 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)); }
private static void removeFinalModifierIfPresent(Field fieldToRemoveFinalFrom) throws IllegalAccessException { int fieldModifiersMask = fieldToRemoveFinalFrom.getModifiers(); boolean isFinalModifierPresent = (fieldModifiersMask & Modifier.FINAL) == Modifier.FINAL; if (isFinalModifierPresent) { checkIfCanSetNewValue(fieldToRemoveFinalFrom); int fieldModifiersMaskWithoutFinal = fieldModifiersMask & ~Modifier.FINAL; sedModifiersToField(fieldToRemoveFinalFrom, fieldModifiersMaskWithoutFinal); } }
/** * Invoke a private or inner class method. This might be useful to test * private methods. */ public static synchronized <T> T invokeMethod(Object instance, String methodToExecute, Object... arguments) throws Exception { return WhiteboxImpl.invokeMethod(instance, methodToExecute, arguments); }
ConstructorFinder(Class<?> type, Object... arguments) { if (type == null) { throw new IllegalArgumentException("Class type cannot be null."); } this.type = type; this.arguments = arguments; this.unmockedType = WhiteboxImpl.getOriginalUnmockedType(type); if (isNestedClass() && arguments != null) { addArgumentForNestedClass(); } }
/** * Set the value of a field using reflection at at specific place in the * class hierarchy (<tt>where</tt>). This first field assignable to * <tt>object</tt> will then be set to <tt>value</tt>. * * @param object the object to modify * @param value the new value of the field * @param where the class in the hierarchy where the field is defined */ public static void setInternalState(Object object, Object value, Class<?> where) { setField(object, value, findField(object, new AssignableFromFieldTypeMatcherStrategy(getType(value)), where)); }
/** * 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); }
/** * 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); }
private static void restoreModifiersToFieldIfChanged(int initialFieldModifiersMask, Field fieldToRestoreModifiersTo) throws IllegalAccessException { int newFieldModifiersMask = fieldToRestoreModifiersTo.getModifiers(); if(initialFieldModifiersMask != newFieldModifiersMask){ sedModifiersToField(fieldToRestoreModifiersTo, initialFieldModifiersMask); } }