本文整理汇总了Java中org.junit.runners.model.Statement类的典型用法代码示例。如果您正苦于以下问题:Java Statement类的具体用法?Java Statement怎么用?Java Statement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Statement类属于org.junit.runners.model包,在下文中一共展示了Statement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.junit.runners.model.Statement; //导入依赖的package包/类
public Statement apply(final Statement base, FrameworkMethod method, Object target) {
sampleName = getSampleName(method);
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (sampleName != null) {
String hintForMissingSample = String.format("If '%s' is a new sample, try running 'gradle intTestImage'.", sampleName);
TestFile srcDir = new IntegrationTestBuildContext().getSamplesDir().file(sampleName).assertIsDir(hintForMissingSample);
logger.debug("Copying sample '{}' to test directory.", sampleName);
srcDir.copyTo(getDir());
} else {
logger.debug("No sample specified for this test, skipping.");
}
base.evaluate();
}
};
}
示例2: apply
import org.junit.runners.model.Statement; //导入依赖的package包/类
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
if(Looper.myLooper()==null) {
Looper.prepare();
}
base.evaluate();
} finally {
Looper.myLooper().quit();
}
}
};
}
示例3: apply
import org.junit.runners.model.Statement; //导入依赖的package包/类
public Statement apply(final Statement base, FrameworkMethod method, Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
originalStdOut = System.out;
originalStdErr = System.err;
stdOutRouter.setOut(originalStdOut);
stdErrRouter.setOut(originalStdErr);
try {
System.setOut(stdOutPrintStream);
System.setErr(stdErrPrintStream);
base.evaluate();
} finally {
System.setOut(originalStdOut);
System.setErr(originalStdErr);
stdOutRouter = null;
stdErrRouter = null;
stdOutPrintStream = null;
stdErrPrintStream = null;
stdoutContent = null;
stderrContent = null;
}
}
};
}
示例4: apply
import org.junit.runners.model.Statement; //导入依赖的package包/类
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
RxAndroidPlugins.getInstance().reset();
RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
RxJavaHooks.reset();
RxJavaHooks.setOnIOScheduler(mRxJavaImmediateScheduler);
RxJavaHooks.setOnNewThreadScheduler(mRxJavaImmediateScheduler);
base.evaluate();
RxAndroidPlugins.getInstance().reset();
RxJavaHooks.reset();
}
};
}
示例5: statementStartsAndStops
import org.junit.runners.model.Statement; //导入依赖的package包/类
@Test public void statementStartsAndStops() throws Throwable {
final AtomicBoolean called = new AtomicBoolean();
Statement statement = server.apply(new Statement() {
@Override public void evaluate() throws Throwable {
called.set(true);
server.url("/").url().openConnection().connect();
}
}, Description.EMPTY);
statement.evaluate();
assertTrue(called.get());
try {
server.url("/").url().openConnection().connect();
fail();
} catch (ConnectException expected) {
}
}
示例6: apply
import org.junit.runners.model.Statement; //导入依赖的package包/类
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
base.evaluate();
} finally {
SQLiteDatabase database = snooperDbHelper.getWritableDatabase();
List<String> tableToDelete = Arrays.asList(HEADER_VALUE_TABLE_NAME, HEADER_TABLE_NAME, HTTP_CALL_RECORD_TABLE_NAME);
for (String table : tableToDelete) {
database.delete(table, null, null);
}
database.close();
}
}
};
}
示例7: expectExceptionAndMessage_noExceptionThrown_shouldFail
import org.junit.runners.model.Statement; //导入依赖的package包/类
@Test
public void expectExceptionAndMessage_noExceptionThrown_shouldFail() throws Throwable {
// given
Statement originalStatement = mock(Statement.class);
ExpectedUncaughtException uncaughtThrown = ExpectedUncaughtException.none();
Statement statement = uncaughtThrown.apply(originalStatement, description);
thrown.expect(AssertionError.class);
thrown.expectMessage("No uncaught exception occurred:\n" +
"Expected: <java.lang.Exception>");
// when
uncaughtThrown.expect(Exception.class);
uncaughtThrown.expectMessage("foo");
statement.evaluate();
// then should fail
}
示例8: apply
import org.junit.runners.model.Statement; //导入依赖的package包/类
@Override
public Statement apply(final Statement base, Description description) {
final RunTestWithRemoteService annotation = description.getAnnotation(RunTestWithRemoteService.class);
if (annotation == null) {
return base;
}
return new Statement() {
@Override
public void evaluate() throws Throwable {
before(annotation.remoteService());
try {
base.evaluate();
} finally {
if (!annotation.onLooperThread()) {
after();
}
}
}
};
}
示例9: apply
import org.junit.runners.model.Statement; //导入依赖的package包/类
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
// Reset the gRPC context between test executions
Context prev = Context.ROOT.attach();
try {
base.evaluate();
if (Context.current() != Context.ROOT) {
Assert.fail("Test is leaking context state between tests! Ensure proper " +
"attach()/detach() pairing.");
}
} finally {
Context.ROOT.detach(prev);
}
}
};
}
示例10: apply
import org.junit.runners.model.Statement; //导入依赖的package包/类
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline());
RxJavaPlugins.setComputationSchedulerHandler(scheduler -> Schedulers.trampoline());
RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> Schedulers.trampoline());
RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline());
try {
base.evaluate();
} finally {
RxJavaPlugins.reset();
}
}
};
}
示例11: methodInvoker
import org.junit.runners.model.Statement; //导入依赖的package包/类
@Override
protected Statement methodInvoker(final FrameworkMethod method, final Object test) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
PactFrameworkMethod pactFrameworkMethod = (PactFrameworkMethod) method;
if (pactFrameworkMethod.shouldExclude()) {
LOG.warn("Test has been excluded. Test will show as passed but was *NOT* run.");
return;
}
if (pactFrameworkMethod.getWorkflow() != null) {
setUpProviderState(test, pactFrameworkMethod.getWorkflow());
pactFrameworkMethod.invokeExplosively(test, pactFrameworkMethod.getWorkflow().getInteractions());
} else {
setUpProviderState(test, pactFrameworkMethod.getInteraction());
pactFrameworkMethod.invokeExplosively(test, Collections.singletonList(pactFrameworkMethod.getInteraction()));
}
}
};
}
示例12: apply
import org.junit.runners.model.Statement; //导入依赖的package包/类
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
RxJavaPlugins.setIoSchedulerHandler(scheduler ->
Schedulers.trampoline());
RxJavaPlugins.setComputationSchedulerHandler(scheduler ->
Schedulers.trampoline());
RxJavaPlugins.setNewThreadSchedulerHandler(scheduler ->
Schedulers.trampoline());
try {
base.evaluate();
} finally {
RxJavaPlugins.reset();
}
}
};
}
示例13: apply
import org.junit.runners.model.Statement; //导入依赖的package包/类
/**
* @see org.junit.rules.MethodRule#apply(org.junit.runners.model.Statement, org.junit.runners.model.FrameworkMethod, java.lang.Object)
*/
@Override
public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final List<Module> moduleWithTarget = new ArrayList<>(Arrays.asList(modules));
if (target instanceof Module) {
moduleWithTarget.add((Module) target);
}
Guice.createInjector(moduleWithTarget).injectMembers(target);
try {
base.evaluate();
} finally {
new ThreadSafeMockingProgress().reset();
}
}
};
}
示例14: throwOnIgnoreTest
import org.junit.runners.model.Statement; //导入依赖的package包/类
protected Statement throwOnIgnoreTest(Statement statement, Description description) {
if (isTest(description)) {
boolean ignoreTest = false;
String message = "";
IgnoreUntil testCaseAnnotation = description.getAnnotation(IgnoreUntil.class);
if (testCaseAnnotation != null) {
ignoreTest = evaluate(testCaseAnnotation, description);
message = testCaseAnnotation.value();
} else if (description.getTestClass().isAnnotationPresent(IgnoreUntil.class)) {
IgnoreUntil testClassAnnotation =
description.getTestClass().getAnnotation(IgnoreUntil.class);
ignoreTest = evaluate(testClassAnnotation, description);
message = testClassAnnotation.value();
}
if (ignoreTest) {
throw new AssumptionViolatedException(format(message, description));
}
}
return statement;
}
示例15: noneExpected_butUncaughtErrorOccurred_shouldFail
import org.junit.runners.model.Statement; //导入依赖的package包/类
@Test
public void noneExpected_butUncaughtErrorOccurred_shouldFail() throws Throwable {
// given
Statement originalStatement = new Statement() {
@Override
public void evaluate() throws Throwable {
Single.just("bar")
.map(s -> { throw new Exception("foo"); })
.subscribe();
}
};
ExpectedUncaughtException uncaughtThrown = ExpectedUncaughtException.none();
Statement statement = uncaughtThrown.apply(originalStatement, description);
thrown.expect(AssertionError.class);
thrown.expectMessage("Unexpected uncaught exception");
// when
statement.evaluate();
// then should fail
}