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


Java ExpectException类代码示例

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


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

示例1: possiblyExpectingExceptions

import org.junit.internal.runners.statements.ExpectException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:13,代码来源:BlockJUnit4ClassRunner.java

示例2: possiblyExpectingAccessException

import org.junit.internal.runners.statements.ExpectException; //导入依赖的package包/类
protected Statement possiblyExpectingAccessException(final Statement next, final boolean failWithAccessException) {
    if (failWithAccessException) {
        return new ExpectException(next, EJBAccessException.class);
    } else {
        return next;
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:8,代码来源:JUnit4Runner.java

示例3: whenTestAnnotationDoesSpecifyAnException_returnExpectExceptionStatement

import org.junit.internal.runners.statements.ExpectException; //导入依赖的package包/类
@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)));
}
 
开发者ID:bechte,项目名称:junit-hierarchicalcontextrunner,代码行数:9,代码来源:ExpectExceptionStatementBuilderTest.java

示例4: methodInvoker

import org.junit.internal.runners.statements.ExpectException; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:59,代码来源:JefJUnit4DatabaseTestRunner.java

示例5: VerifierStatement

import org.junit.internal.runners.statements.ExpectException; //导入依赖的package包/类
private VerifierStatement(Statement base) {
    this.base = base;
    this.expectsException = ExpectException.class.isAssignableFrom(base.getClass());
}
 
开发者ID:smarttested,项目名称:smartassert,代码行数:5,代码来源:SoftAssertVerifier.java

示例6: createStatement

import org.junit.internal.runners.statements.ExpectException; //导入依赖的package包/类
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());
}
 
开发者ID:bechte,项目名称:junit-hierarchicalcontextrunner,代码行数:6,代码来源:ExpectExceptionStatementBuilder.java

示例7: possiblyExpectingExceptions

import org.junit.internal.runners.statements.ExpectException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:16,代码来源:LoadTimeWeavableTestRunner.java

示例8: possiblyExpectingExceptions

import org.junit.internal.runners.statements.ExpectException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:lcm-proj,项目名称:lcm,代码行数:16,代码来源:BlockJUnit4ClassRunner.java

示例9: possiblyExpectingExceptions

import org.junit.internal.runners.statements.ExpectException; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:SpringJUnit4ClassRunner.java

示例10: possiblyExpectingExceptions

import org.junit.internal.runners.statements.ExpectException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:12,代码来源:SpringJUnit4ClassRunner.java


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