本文整理了Java中org.powermock.reflect.internal.WhiteboxImpl.findUniqueConstructorOrThrowException()
方法的一些代码示例,展示了WhiteboxImpl.findUniqueConstructorOrThrowException()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WhiteboxImpl.findUniqueConstructorOrThrowException()
方法的具体详情如下:
包路径:org.powermock.reflect.internal.WhiteboxImpl
类名称:WhiteboxImpl
方法名:findUniqueConstructorOrThrowException
[英]Finds and returns a certain constructor. If the constructor couldn't be found this method delegates to
[中]查找并返回某个构造函数。如果找不到构造函数,此方法将委托给
代码示例来源:origin: org.powermock/powermock-api-support
/**
* Returns a constructor specified in declaringClass.
*
* @param declaringClass
* The declaringClass of the class where the constructor is
* located.
* @param parameterTypes
* All parameter types of the constructor (may be
* {@code null}).
* @return A {@code java.lang.reflect.Constructor}.
* @throws ConstructorNotFoundException
* if the constructor cannot be found.
*/
@SuppressWarnings("unchecked")
public static <T> Constructor<T> constructor(Class<T> declaringClass, Class<?>... parameterTypes) {
return (Constructor<T>) WhiteboxImpl.findUniqueConstructorOrThrowException(declaringClass,
(Object[]) parameterTypes);
}
代码示例来源:origin: org.powermock.api/powermock-api-support
/**
* Returns a constructor specified in declaringClass.
*
* @param declaringClass
* The declaringClass 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.
*/
@SuppressWarnings("unchecked")
public static <T> Constructor<T> constructor(Class<T> declaringClass, Class<?>... parameterTypes) {
return (Constructor<T>) WhiteboxImpl.findUniqueConstructorOrThrowException(declaringClass,
(Object[]) parameterTypes);
}
代码示例来源:origin: org.powermock/powermock-api-mockito2
@SuppressWarnings({"unchecked", "rawtypes"})
private 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.getOriginalUnmockedType(type);
if (parameterTypes == null) {
WhiteboxImpl.findUniqueConstructorOrThrowException(type, arguments);
} else {
WhiteboxImpl.getConstructor(unmockedType, parameterTypes);
}
NewInvocationControl<OngoingStubbing<T>> newInvocationControl = createNewInvocationControl(type, unmockedType);
return newInvocationControl.expectSubstitutionLogic(arguments);
}
代码示例来源:origin: org.powermock.api/powermock-api-easymock
/**
* Creates a nice mock object that supports mocking of final and native
* methods and invokes a specific constructor based on the supplied argument
* values.
*
* @param <T>
* the type of the mock object
* @param type
* the type of the mock object
* @param constructorArguments
* The constructor arguments that will be used to invoke a
* certain constructor.
* @return the mock object.
*/
public static <T> T createNiceMock(Class<T> type, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMock(type, false, new NiceMockStrategy(), constructorArgs, (Method[]) null);
}
代码示例来源:origin: org.powermock.api/powermock-api-easymock
/**
* Creates a mock object that supports mocking of final and native methods
* and invokes a specific constructor based on the supplied argument values.
*
* @param <T>
* the type of the mock object
* @param type
* the type of the mock object
* @param constructorArguments
* The constructor arguments that will be used to invoke a
* certain constructor.
* @return the mock object.
*/
public static <T> T createMock(Class<T> type, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMock(type, false, new DefaultMockStrategy(), constructorArgs, (Method[]) null);
}
代码示例来源:origin: org.powermock.api/powermock-api-easymock
/**
* Creates a strict mock object that supports mocking of final and native
* methods and invokes a specific constructor based on the supplied argument
* values.
*
* @param <T>
* the type of the mock object
* @param type
* the type of the mock object
* @param constructorArguments
* The constructor arguments that will be used to invoke a
* certain constructor.
* @return the mock object.
*/
public static <T> T createStrictMock(Class<T> type, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMock(type, false, new StrictMockStrategy(), constructorArgs, (Method[]) null);
}
代码示例来源:origin: org.powermock.api/powermock-api-easymock
/**
* A utility method that may be used to strictly mock several methods in an
* easy way (by just passing in the method names of the method you wish to
* mock). Use this to handle overloaded methods. The mock object created
* will support mocking of final and native methods and invokes a specific
* constructor based on the supplied argument values.
*
* @param <T>
* the type of the mock object
* @param type
* the type of the mock object
* @param methodName
* The names of the methods that should be mocked. If
* <code>null</code>, then this method will have the same effect
* as just calling {@link #createMock(Class, Method...)} with the
* second parameter as <code>new Method[0]</code> (i.e. all
* methods in that class will be mocked).
* @param methodParameterTypes
* Parameter types that defines the method. Note that this is
* only needed to separate overloaded methods.
* @param constructorArguments
* The constructor arguments that will be used to invoke a
* certain constructor. (optional)
* @return the mock object.
*/
public static <T> T createStrictPartialMock(Class<T> type, String methodName, Class<?>[] methodParameterTypes, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMockSpecific(type, new StrictMockStrategy(), new String[] { methodName }, constructorArgs, methodParameterTypes);
}
代码示例来源:origin: org.powermock.api/powermock-api-easymock
/**
* A utility method that may be used to mock several methods in an easy way
* (by just passing in the method names of the method you wish to mock). Use
* this to handle overloaded methods. The mock object created will support
* mocking of final and native methods and invokes a specific constructor
* based on the supplied argument values.
*
* @param <T>
* the type of the mock object
* @param type
* the type of the mock object
* @param methodName
* The names of the methods that should be mocked. If
* <code>null</code>, then this method will have the same effect
* as just calling {@link #createMock(Class, Method...)} with the
* second parameter as <code>new Method[0]</code> (i.e. all
* methods in that class will be mocked).
* @param methodParameterTypes
* Parameter types that defines the method. Note that this is
* only needed to separate overloaded methods.
* @param constructorArguments
* The constructor arguments that will be used to invoke a
* certain constructor. (optional)
* @return the mock object.
*/
public static <T> T createPartialMock(Class<T> type, String methodName, Class<?>[] methodParameterTypes, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMockSpecific(type, new DefaultMockStrategy(), new String[] { methodName }, constructorArgs, methodParameterTypes);
}
代码示例来源:origin: org.powermock.api/powermock-api-easymock
/**
* A utility method that may be used to nicely mock several methods in an
* easy way (by just passing in the method names of the method you wish to
* mock). Use this to handle overloaded methods. The mock object created
* will support mocking of final and native methods and invokes a specific
* constructor based on the supplied argument values.
*
* @param <T>
* the type of the mock object
* @param type
* the type of the mock object
* @param methodName
* The names of the methods that should be mocked. If
* <code>null</code>, then this method will have the same effect
* as just calling {@link #createMock(Class, Method...)} with the
* second parameter as <code>new Method[0]</code> (i.e. all
* methods in that class will be mocked).
* @param methodParameterTypes
* Parameter types that defines the method. Note that this is
* only needed to separate overloaded methods.
* @param constructorArguments
* The constructor arguments that will be used to invoke a
* certain constructor. (optional)
* @return the mock object.
*/
public static <T> T createNicePartialMock(Class<T> type, String methodName, Class<?>[] methodParameterTypes, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMockSpecific(type, new NiceMockStrategy(), new String[] { methodName }, constructorArgs, methodParameterTypes);
}
代码示例来源:origin: org.powermock.api/powermock-api-easymock
/**
* * A utility method that may be used to strictly mock several methods in
* an easy way (by just passing in the method names of the method you wish
* to mock). The mock object created will support mocking of final and
* native methods and invokes a specific constructor based on the supplied
* argument values.
*
* @param <T>
* the type of the mock object
* @param type
* the type of the mock object
* @param methodNames
* The names of the methods that should be mocked. If
* <code>null</code>, then this method will have the same effect
* as just calling {@link #createMock(Class, Method...)} with the
* second parameter as <code>new Method[0]</code> (i.e. all
* methods in that class will be mocked).
* @param constructorArguments
* The constructor arguments that will be used to invoke a
* certain constructor. (optional)
* @return the mock object.
*/
public static <T> T createStrictPartialMock(Class<T> type, String[] methodNames, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMock(type, false, new StrictMockStrategy(), constructorArgs, Whitebox.getMethods(type, methodNames));
}
代码示例来源:origin: org.powermock.api/powermock-api-easymock
/**
* * A utility method that may be used to nicely mock several methods in an
* easy way (by just passing in the method names of the method you wish to
* mock). The mock object created will support mocking of final and native
* methods and invokes a specific constructor based on the supplied argument
* values.
*
* @param <T>
* the type of the mock object
* @param type
* the type of the mock object
* @param methodNames
* The names of the methods that should be mocked. If
* <code>null</code>, then this method will have the same effect
* as just calling {@link #createMock(Class, Method...)} with the
* second parameter as <code>new Method[0]</code> (i.e. all
* methods in that class will be mocked).
* @param constructorArguments
* The constructor arguments that will be used to invoke a
* certain constructor. (optional)
* @return the mock object.
*/
public static <T> T createNicePartialMock(Class<T> type, String[] methodNames, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMock(type, false, new NiceMockStrategy(), constructorArgs, Whitebox.getMethods(type, methodNames));
}
代码示例来源:origin: org.powermock.api/powermock-api-easymock
/**
* A utility method that may be used to mock several methods in an easy way
* (by just passing in the method names of the method you wish to mock). The
* mock object created will support mocking of final and native methods and
* invokes a specific constructor based on the supplied argument values.
*
* @param <T>
* the type of the mock object
* @param type
* the type of the mock object
* @param methodNames
* The names of the methods that should be mocked. If
* <code>null</code>, then this method will have the same effect
* as just calling {@link #createMock(Class, Method...)} with the
* second parameter as <code>new Method[0]</code> (i.e. all
* methods in that class will be mocked).
* @param constructorArguments
* The constructor arguments that will be used to invoke a
* certain constructor. (optional)
* @return the mock object.
*/
public static <T> T createPartialMock(Class<T> type, String[] methodNames, Object... constructorArguments) {
Constructor<?> constructor = WhiteboxImpl.findUniqueConstructorOrThrowException(type, constructorArguments);
ConstructorArgs constructorArgs = new ConstructorArgs(constructor, constructorArguments);
return doMock(type, false, new DefaultMockStrategy(), constructorArgs, Whitebox.getMethods(type, methodNames));
}
代码示例来源:origin: org.powermock.api/powermock-api-easymock
if (!isNiceMock) {
if (parameterTypes == null) {
WhiteboxImpl.findUniqueConstructorOrThrowException(type, arguments);
} else {
WhiteboxImpl.getConstructor(unmockedType, parameterTypes);
代码示例来源:origin: org.powermock/powermock-api-mockito-common
@SuppressWarnings({"unchecked", "rawtypes"})
private <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.getOriginalUnmockedType(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 = getMockCreator().createMock(InvocationSubstitute.class, false, false, null, null, (Method[]) null);
newInvocationControl = createNewInvocationControl(mock);
MockRepository.putNewInstanceControl(type, newInvocationControl);
MockRepository.addObjectsToAutomaticallyReplayAndVerify(WhiteboxImpl.getOriginalUnmockedType(type));
}
return newInvocationControl.expectSubstitutionLogic(arguments);
}
内容来源于网络,如有侵权,请联系作者删除!