当前位置: 首页>>代码示例>>Java>>正文


Java WhiteboxImpl.findUniqueConstructorOrThrowException方法代码示例

本文整理汇总了Java中org.powermock.reflect.internal.WhiteboxImpl.findUniqueConstructorOrThrowException方法的典型用法代码示例。如果您正苦于以下问题:Java WhiteboxImpl.findUniqueConstructorOrThrowException方法的具体用法?Java WhiteboxImpl.findUniqueConstructorOrThrowException怎么用?Java WhiteboxImpl.findUniqueConstructorOrThrowException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.powermock.reflect.internal.WhiteboxImpl的用法示例。


在下文中一共展示了WhiteboxImpl.findUniqueConstructorOrThrowException方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:28,代码来源:DefaultConstructorExpectationSetup.java

示例2: 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);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:39,代码来源:PowerMock.java

示例3: findUniqueConstructorOrThrowExceptionFiltersPowerMockConstructors

import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void findUniqueConstructorOrThrowExceptionFiltersPowerMockConstructors() throws Exception {
	Constructor<?> actualConstructor = WhiteboxImpl.findUniqueConstructorOrThrowException(ClassWithPowerMockGeneratedConstructor.class,
			(Object) null);
	assertEquals(ClassWithPowerMockGeneratedConstructor.class.getConstructor(String.class), actualConstructor);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:7,代码来源:PowerMockConstructorFiltrationTest.java

示例4: createPartialMock

import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:33,代码来源:PowerMock.java

示例5: createStrictPartialMock

import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:33,代码来源:PowerMock.java

示例6: createNicePartialMock

import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:33,代码来源:PowerMock.java

示例7: constructor

import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:19,代码来源:MemberMatcher.java

示例8: createMock

import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:19,代码来源:PowerMock.java

示例9: createStrictMock

import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:20,代码来源:PowerMock.java

示例10: createNiceMock

import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:20,代码来源:PowerMock.java


注:本文中的org.powermock.reflect.internal.WhiteboxImpl.findUniqueConstructorOrThrowException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。