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


Java Statement类代码示例

本文整理汇总了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();
        }
    };
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:18,代码来源:Sample.java

示例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();
      }
    }
  };
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:17,代码来源:RunUsingLooper.java

示例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;
            }
        }
    };
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:RedirectStdOutAndErr.java

示例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();
        }
    };
}
 
开发者ID:ebridfighter,项目名称:GongXianSheng,代码行数:20,代码来源:RxSchedulersOverrideRule.java

示例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) {
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:MockWebServerTest.java

示例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();
      }
    }
  };
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:19,代码来源:DataResetRule.java

示例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
}
 
开发者ID:xemantic,项目名称:github-users,代码行数:18,代码来源:ExpectedUncaughtExceptionTest.java

示例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();
                }
            }
        }
    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:RunWithRemoteService.java

示例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);
            }
        }
    };
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:20,代码来源:GrpcContextRule.java

示例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();
            }
        }
    };
}
 
开发者ID:Zeyad-37,项目名称:RxRedux,代码行数:18,代码来源:ImmediateSchedulersRule.java

示例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()));
            }
        }
    };
}
 
开发者ID:tyro,项目名称:pact-spring-mvc,代码行数:21,代码来源:PactTestRunner.java

示例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();
            }
        }
    };
}
 
开发者ID:OlegDokuka,项目名称:reactive-playing,代码行数:20,代码来源:WordServiceWithRuleTest.java

示例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();
      }
    }
  };
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:22,代码来源:InjectMembersRule.java

示例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;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:26,代码来源:IgnoreUntilRule.java

示例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
}
 
开发者ID:xemantic,项目名称:github-users,代码行数:22,代码来源:ExpectedUncaughtExceptionTest.java


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