WhiteboxImpl
Code IndexAdd Codota to your IDE (free)

Best code snippets using org.powermock.reflect.internal.WhiteboxImpl(Showing top 15 results out of 315)

origin: org.powermock/powermock-api-mockito

} else {
  boolean inVerificationMode = isInVerificationMode();
  if (WhiteboxImpl.isClass(obj) && inVerificationMode) {
    handleStaticVerification((Class<?>) obj);
origin: org.powermock/powermock-api-easymock

@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();
}
origin: org.powermock/powermock-core

@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;
}
origin: org.powermock/powermock-core

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);
}

origin: org.powermock/powermock-reflect

/**
 * 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);
}
origin: org.powermock/powermock-reflect

/**
 * 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);
}
origin: org.powermock/powermock-reflect

/**
 * 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));
}
origin: org.powermock/powermock-reflect

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);
  }
}
origin: org.powermock/powermock-reflect

/**
 * 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);
}
origin: org.powermock/powermock-reflect

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();
  }
}
origin: org.powermock/powermock-reflect

/**
 * 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));
}
origin: org.powermock/powermock-api-support

/**
 * 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);
}
origin: org.powermock/powermock-reflect

/**
 * 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);
}
origin: org.powermock/powermock-reflect

public static void setInternalStateFromContext(Object object, Object context, FieldMatchingStrategy strategy) {
  if (isClass(context)) {
    copyState(object, getType(context), strategy);
  } else {
    copyState(object, context, strategy);
  }
}
origin: org.powermock/powermock-reflect

private static void restoreModifiersToFieldIfChanged(int initialFieldModifiersMask, Field fieldToRestoreModifiersTo) throws IllegalAccessException {
  int newFieldModifiersMask = fieldToRestoreModifiersTo.getModifiers();
  if(initialFieldModifiersMask != newFieldModifiersMask){
    sedModifiersToField(fieldToRestoreModifiersTo, initialFieldModifiersMask);
  }
}
org.powermock.reflect.internalWhiteboxImpl

Javadoc

Various utilities for accessing internals of a class. Basically a simplified reflection utility intended for tests.

Most used methods

  • getConstructor
    Convenience method to get a (declared) constructor from a class type without having to catch the che
  • findMethodOrThrowException
    Finds and returns a certain method. If the method couldn't be found this method delegates to
  • findUniqueConstructorOrThrowException
    Finds and returns a certain constructor. If the constructor couldn't be found this method delegates
  • isClass
    Checks if is class.
  • throwExceptionIfMethodWasNotFound
    Throw exception if method was not found.
  • getInternalState
    Get the value of a field using reflection. Use this method when you need to specify in which class t
  • performMethodInvocation
    Perform method invocation.
  • areAllMethodsStatic
    Are all methods static.
  • checkIfParameterTypesAreSame
    Check if parameter types are same.
  • findMethod
    Finds and returns a method based on the input parameters. If no parameterTypes are present the metho
  • getAllFields
    Get all fields in a class hierarchy! Both declared an non-declared (no duplicates).
  • getAllMethodExcept
    Gets the all method except.
  • getAllFields,
  • getAllMethodExcept,
  • getAllMethods,
  • getBestMethodCandidate,
  • getField,
  • getFieldsOfType,
  • getFirstParentConstructor,
  • getMethod,
  • getOriginalUnmockedType,
  • getUnmockedType

Popular classes and methods

  • putExtra (Intent)
  • getExternalFilesDir (Context)
  • getApplicationContext (Context)
  • Kernel (java.awt.image)
  • File (java.io)
    LocalStorage based File implementation for GWT. Should probably have used Harmony as a starting poin
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • Connection (java.sql)
    A connection (session) with a specific database. SQL statements are executed and results are returne
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support

For IntelliJ IDEA,
Android Studio or Eclipse

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)