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


Java WhiteboxImpl.getConstructor方法代码示例

本文整理汇总了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;
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:22,代码来源:MockitoNewInvocationControl.java

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

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

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

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

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


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