當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。