• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java MockPolicy类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.powermock.core.classloader.annotations.MockPolicy的典型用法代码示例。如果您正苦于以下问题:Java MockPolicy类的具体用法?Java MockPolicy怎么用?Java MockPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

MockPolicy类属于org.powermock.core.classloader.annotations包,在下文中一共展示了MockPolicy类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: handleException

点赞 2

import org.powermock.core.classloader.annotations.MockPolicy; //导入依赖的package包/类
protected void handleException(final TestMethod testMethod, Throwable actualFailure) {
    try {
        final String throwableName = actualFailure.getClass().getName();
        if (throwableName.equals("org.junit.internal.AssumptionViolatedException") || throwableName.startsWith("org.junit.Assume$AssumptionViolatedException")) {
            return;
        } else if (!(Boolean) Whitebox.invokeMethod(testMethod, "expectsException")) {
            final String className = actualFailure.getStackTrace()[0].getClassName();
            final Class<?> testClassAsJavaClass = testClass.getJavaClass();
            if (actualFailure instanceof NullPointerException
                    && !testClassAsJavaClass.getName().equals(className)
                    && !className.startsWith("java.lang")
                    && !className.startsWith("org.powermock")
                    && !className.startsWith("org.junit")
                    && !new PrepareForTestExtractorImpl().isPrepared(testClassAsJavaClass, className)
                    && !testClassAsJavaClass.isAnnotationPresent(PrepareEverythingForTest.class)
                    && !new MockPolicyInitializerImpl(testClassAsJavaClass.isAnnotationPresent(MockPolicy.class) ? testClassAsJavaClass
                    .getAnnotation(MockPolicy.class).value() : null).isPrepared(className)) {
                Whitebox.setInternalState(actualFailure, "detailMessage", "Perhaps the class " + className + " must be prepared for test?",
                        Throwable.class);
            }
            addFailure(actualFailure);
        } else if ((Boolean) Whitebox.invokeMethod(testMethod, "isUnexpected", actualFailure)) {
            String message = "Unexpected exception, expected<" + getExpectedExceptionName(testMethod) + "> but was<"
                    + actualFailure.getClass().getName() + ">";
            addFailure(new Exception(message, actualFailure));
        }

    } catch (Exception e) {
        throw new RuntimeException("PowerMock internal error: Should never throw exception at this level", e);
    }
}
 

开发者ID:awenblue,
项目名称:powermock,
代码行数:32,
代码来源:PowerMockJUnit44RunnerDelegateImpl.java

示例2: getMockPolicies

点赞 2

import org.powermock.core.classloader.annotations.MockPolicy; //导入依赖的package包/类
/**
 * Get the mock policies from a test-class.
 */
@SuppressWarnings("unchecked")
private static Class<? extends PowerMockPolicy>[] getMockPolicies(Class<?> testClass) {
    Class<? extends PowerMockPolicy>[] powerMockPolicies = new Class[0];
    if (testClass.isAnnotationPresent(MockPolicy.class)) {
        MockPolicy annotation = testClass.getAnnotation(MockPolicy.class);
        powerMockPolicies = annotation.value();
    }
    return powerMockPolicies;
}
 

开发者ID:awenblue,
项目名称:powermock,
代码行数:13,
代码来源:MockPolicyInitializerImpl.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)