本文整理汇总了Java中org.powermock.reflect.internal.WhiteboxImpl.getConstructor方法的典型用法代码示例。如果您正苦于以下问题:Java WhiteboxImpl.getConstructor方法的具体用法?Java WhiteboxImpl.getConstructor怎么用?Java WhiteboxImpl.getConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.powermock.reflect.internal.WhiteboxImpl
的用法示例。
在下文中一共展示了WhiteboxImpl.getConstructor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
public Object invoke(Class<?> type, Object[] args, Class<?>[] sig) throws Exception {
Constructor<?> constructor = WhiteboxImpl.getConstructor(type, sig);
if (constructor.isVarArgs()) {
Object varArgs = args[args.length - 1];
final int varArgsLength = Array.getLength(varArgs);
Object[] oldArgs = args;
args = new Object[args.length + varArgsLength - 1];
System.arraycopy(oldArgs, 0, args, 0, oldArgs.length - 1);
for (int i = oldArgs.length - 1, j=0; i < args.length; i++, j++) {
args[i] = Array.get(varArgs, j);
}
}
try {
return substitute.performSubstitutionLogic(args);
} catch (MockitoAssertionError e) {
InvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(e, type);
}
// Won't happen
return null;
}
示例2: createNewSubstituteMock
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private static <T> OngoingStubbing<T> createNewSubstituteMock(Class<T> type, Class<?>[] parameterTypes, Object... arguments) throws Exception {
if (type == null) {
throw new IllegalArgumentException("type cannot be null");
}
final Class<T> unmockedType = (Class<T>) WhiteboxImpl.getUnmockedType(type);
if (parameterTypes == null) {
WhiteboxImpl.findUniqueConstructorOrThrowException(type, arguments);
} else {
WhiteboxImpl.getConstructor(unmockedType, parameterTypes);
}
/*
* Check if this type has been mocked before
*/
NewInvocationControl<OngoingStubbing<T>> newInvocationControl = (NewInvocationControl<OngoingStubbing<T>>) MockRepository
.getNewInstanceControl(unmockedType);
if (newInvocationControl == null) {
InvocationSubstitute<T> mock = MockCreator.mock(InvocationSubstitute.class, false, false, null, null, (Method[]) null);
newInvocationControl = new MockitoNewInvocationControl(mock);
MockRepository.putNewInstanceControl(type, newInvocationControl);
MockRepository.addObjectsToAutomaticallyReplayAndVerify(WhiteboxImpl.getUnmockedType(type));
}
return newInvocationControl.expectSubstitutionLogic(arguments);
}
示例3: invoke
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
public Object invoke(Class<?> type, Object[] args, Class<?>[] sig) throws Exception {
Constructor<?> constructor = WhiteboxImpl.getConstructor(type, sig);
if (constructor.isVarArgs()) {
/*
* Get the last argument because this contains the actual varargs
* arguments.
*/
int length = constructor.getParameterTypes().length;
args = (Object[]) args[length-1];
}
try {
final MocksControl.MockType mockType = ((EasyMockMethodInvocationControl<?>) MockRepository.getInstanceMethodInvocationControl(substitute))
.getMockType();
Object result = substitute.performSubstitutionLogic(args);
if (result == null) {
if (mockType == MocksControl.MockType.NICE) {
result = EasyMock.createNiceMock(subsitutionType);
} else {
throw new IllegalStateException("Must replay class " + type.getName() + " to get configured expectation.");
}
}
return result;
} catch (AssertionError e) {
NewInvocationControlAssertionError.throwAssertionErrorForNewSubstitutionFailure(e, type);
}
// Won't happen
return null;
}
示例4: doExpectNew
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> IExpectationSetters<T> doExpectNew(Class<T> type, MockStrategy mockStrategy,
Class<?>[] parameterTypes, Object... arguments) throws Exception {
if (type == null) {
throw new IllegalArgumentException("type cannot be null");
} else if (mockStrategy == null) {
throw new IllegalArgumentException("Internal error: Mock strategy cannot be null");
}
final boolean isNiceMock = mockStrategy instanceof NiceMockStrategy;
final Class<T> unmockedType = (Class<T>) WhiteboxImpl.getUnmockedType(type);
if (!isNiceMock) {
if (parameterTypes == null) {
WhiteboxImpl.findUniqueConstructorOrThrowException(type, arguments);
} else {
WhiteboxImpl.getConstructor(unmockedType, parameterTypes);
}
}
/*
* Check if this type has been mocked before
*/
NewInvocationControl<IExpectationSetters<T>> newInvocationControl = (NewInvocationControl<IExpectationSetters<T>>) MockRepository
.getNewInstanceControl(unmockedType);
if (newInvocationControl == null) {
InvocationSubstitute<T> mock = doMock(InvocationSubstitute.class, false, mockStrategy, null,
(Method[]) null);
newInvocationControl = new NewInvocationControlImpl<T>(mock, type);
MockRepository.putNewInstanceControl(type, newInvocationControl);
MockRepository.addObjectsToAutomaticallyReplayAndVerify(WhiteboxImpl.getUnmockedType(type));
}
if (isNiceMock && (arguments == null || arguments.length == 0)) {
return null;
}
return newInvocationControl.expectSubstitutionLogic(arguments);
}
示例5: constructorCall
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
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;
}
示例6: getConstructor
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
/**
* Convenience method to get a (declared) constructor from a class type
* without having to catch the checked exceptions otherwise required. These
* exceptions are wrapped as runtime exceptions. The constructor is also set
* to accessible.
*
* @param type
* The type of the class where the constructor is located.
* @param parameterTypes
* All parameter types of the constructor (may be
* <code>null</code>).
* @return A <code>java.lang.reflect.Constructor</code>.
* @throws ConstructorNotFoundException
* if the constructor cannot be found.
*/
public static <T> Constructor<T> getConstructor(Class<?> type, Class<?>... parameterTypes) {
return (Constructor<T>) WhiteboxImpl.getConstructor(type, parameterTypes);
}