本文整理汇总了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;
}
示例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;
}
}
示例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);
}
}
示例5: VerifierStatement
import org.junit.internal.runners.statements.ExpectException; //导入依赖的package包/类
private VerifierStatement(Statement base) {
this.base = base;
this.expectsException = ExpectException.class.isAssignableFrom(base.getClass());
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}