Java 类org.junit.internal.runners.statements.ExpectException 实例源码

项目:sosiefier    文件:BlockJUnit4ClassRunner.java   
/**
 * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code expecting} attribute, return normally only if {@code next}
 * throws an exception of the correct type, and throw an exception
 * otherwise.
 */
protected Statement possiblyExpectingExceptions(FrameworkMethod method,
        Object test, Statement next) {
    Test annotation = method.getAnnotation(Test.class);
    return expectsException(annotation) ? new ExpectException(next,
            getExpectedException(annotation)) : next;
}
项目:tomee    文件:JUnit4Runner.java   
protected Statement possiblyExpectingAccessException(final Statement next, final boolean failWithAccessException) {
    if (failWithAccessException) {
        return new ExpectException(next, EJBAccessException.class);
    } else {
        return next;
    }
}
项目:junit-hierarchicalcontextrunner    文件:ExpectExceptionStatementBuilderTest.java   
@Test
public void whenTestAnnotationDoesSpecifyAnException_returnExpectExceptionStatement() throws Exception {
    TestClass testClass = TestClassPool.forClass(SingleTestWithExpectedAnnotation.class);
    FrameworkMethod method = testClass.getAnnotatedMethods(Test.class).get(0);

    Statement actual = builder.createStatement(testClass, method, target, next, description, notifier);
    assertThat(actual, is(instanceOf(ExpectException.class)));
}
项目:ef-orm    文件:JefJUnit4DatabaseTestRunner.java   
@Override
protected Statement methodInvoker(FrameworkMethod method, Object test) {
    boolean isNew = false;
    boolean inject = false;
    if (method instanceof DbFrameworkMethod) {
        DbFrameworkMethod dbCase = (DbFrameworkMethod) method;
        String dbType = dbCase.getDbType();
        Object obj = connections.get(dbType);
        if (obj == null) {
            throw new IllegalArgumentException("Database " + dbType + " is unknown.");
        }
        DbConnectionHolder holder;
        if (obj instanceof DataSource) {
            holder = createDbClient((DataSource) obj);// CreateDbClient
            isNew = true;
        } else {
            holder = (DbConnectionHolder) obj;
            if (holder.db == null) {
                holder = createDbClient(holder.datasource);// CreateDbClient
            }
        }
        inject(test, holder.db, holder.datasource.field());
        inject=true;
    } else if (isRouting) {
        if (routingDbClient == null) {
            MapDataSourceLookup lookup = new MapDataSourceLookup();
            for (Entry<String, Object> entry : connections.entrySet()) {
                if (entry.getValue() instanceof DataSource) {
                    DataSource ds = (DataSource) entry.getValue();
                    lookup.put(ds.name(), new SimpleDataSource(ds.url(),ds.user(),ds.password()));
                }
            }
            RoutingDataSource rds = new RoutingDataSource(lookup);
            routingDbClient = new DbClient(rds);
            isNew = true;
        }
        inject(test, routingDbClient, "");
        inject=true;
    }
    if (isNew) {
        List<FrameworkMethod> methods = getTestClass().getAnnotatedMethods(DatabaseInit.class);
        try {
            for (FrameworkMethod m : methods) {
                printMethod(m, method);
                m.getMethod().invoke(test);
            }
        } catch (Exception e) {
            throw DbUtils.toRuntimeException(e);
        }
    }
    printMethod(method, null);
    if(inject){
        return super.methodInvoker(method, test);
    }else{
        System.err.println("数据库未配置,跳过测试:"+super.describeChild(method).getDisplayName());
        return new ExpectException(null, NullPointerException.class);
    }
}
项目:smartassert    文件:SoftAssertVerifier.java   
private VerifierStatement(Statement base) {
    this.base = base;
    this.expectsException = ExpectException.class.isAssignableFrom(base.getClass());
}
项目:junit-hierarchicalcontextrunner    文件:ExpectExceptionStatementBuilder.java   
public Statement createStatement(final TestClass testClass, final FrameworkMethod method, final Object target,
                                 final Statement next, final Description description, final RunNotifier notifier) {
    final Test annotation = method.getAnnotation(Test.class);
    return annotation.expected() == Test.None.class ? next : new ExpectException(next, annotation.expected());
}
项目:kc-rice    文件:LoadTimeWeavableTestRunner.java   
/**
 * Returns a {@link org.junit.runners.model.Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code expecting} attribute, return normally only if {@code next}
 * throws an exception of the correct type, and throw an exception
 * otherwise.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement possiblyExpectingExceptions(FrameworkMethod method,
        Object test, Statement next) {
    Test annotation = method.getAnnotation(Test.class);
    return expectsException(annotation) ? new ExpectException(next,
            getExpectedException(annotation)) : next;
}
项目:lcm    文件:BlockJUnit4ClassRunner.java   
/**
 * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code expecting} attribute, return normally only if {@code next}
 * throws an exception of the correct type, and throw an exception
 * otherwise.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement possiblyExpectingExceptions(FrameworkMethod method,
        Object test, Statement next) {
    Test annotation = method.getAnnotation(Test.class);
    return expectsException(annotation) ? new ExpectException(next,
            getExpectedException(annotation)) : next;
}
项目:rice    文件:LoadTimeWeavableTestRunner.java   
/**
 * Returns a {@link org.junit.runners.model.Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code expecting} attribute, return normally only if {@code next}
 * throws an exception of the correct type, and throw an exception
 * otherwise.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement possiblyExpectingExceptions(FrameworkMethod method,
        Object test, Statement next) {
    Test annotation = method.getAnnotation(Test.class);
    return expectsException(annotation) ? new ExpectException(next,
            getExpectedException(annotation)) : next;
}
项目:junit    文件:BlockJUnit4ClassRunner.java   
/**
 * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code expecting} attribute, return normally only if {@code next}
 * throws an exception of the correct type, and throw an exception
 * otherwise.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement possiblyExpectingExceptions(FrameworkMethod method,
        Object test, Statement next) {
    Test annotation = method.getAnnotation(Test.class);
    return expectsException(annotation) ? new ExpectException(next,
            getExpectedException(annotation)) : next;
}
项目:org.openntf.domino    文件:BlockJUnit4ClassRunner.java   
/**
 * Returns a {@link Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code expecting} attribute, return normally only if {@code next}
 * throws an exception of the correct type, and throw an exception
 * otherwise.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement possiblyExpectingExceptions(FrameworkMethod method,
        Object test, Statement next) {
    Test annotation = method.getAnnotation(Test.class);
    return expectsException(annotation) ? new ExpectException(next,
            getExpectedException(annotation)) : next;
}
项目:spring4-understanding    文件:SpringJUnit4ClassRunner.java   
/**
 * Perform the same logic as
 * {@link BlockJUnit4ClassRunner#possiblyExpectingExceptions(FrameworkMethod, Object, Statement)}
 * except that the <em>expected exception</em> is retrieved using
 * {@link #getExpectedException(FrameworkMethod)}.
 */
@Override
protected Statement possiblyExpectingExceptions(FrameworkMethod frameworkMethod, Object testInstance, Statement next) {
    Class<? extends Throwable> expectedException = getExpectedException(frameworkMethod);
    return (expectedException != null ? new ExpectException(next, expectedException) : next);
}
项目:class-guard    文件:SpringJUnit4ClassRunner.java   
/**
 * Performs the same logic as
 * {@link BlockJUnit4ClassRunner#possiblyExpectingExceptions(FrameworkMethod, Object, Statement)}
 * except that the <em>expected exception</em> is retrieved using
 * {@link #getExpectedException(FrameworkMethod)}.
 */
@Override
protected Statement possiblyExpectingExceptions(FrameworkMethod frameworkMethod, Object testInstance, Statement next) {
    Class<? extends Throwable> expectedException = getExpectedException(frameworkMethod);
    return expectedException != null ? new ExpectException(next, expectedException) : next;
}