當前位置: 首頁>>代碼示例>>Java>>正文


Java Assert類代碼示例

本文整理匯總了Java中org.junit.Assert的典型用法代碼示例。如果您正苦於以下問題:Java Assert類的具體用法?Java Assert怎麽用?Java Assert使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Assert類屬於org.junit包,在下文中一共展示了Assert類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testPessimisticProvidePostResolveFailure

import org.junit.Assert; //導入依賴的package包/類
/**
 * Test the completion and callback invocation of {@link RedFutureHub}
 * pessimistic union of provided futures that later were failed
 */
@Test
public void testPessimisticProvidePostResolveFailure() throws Throwable {
    AtomicBoolean reachedSuccessBlock = new AtomicBoolean(false);
    AtomicBoolean reachedFailureBlock = new AtomicBoolean(false);
    AtomicBoolean reachedFinallyBlock = new AtomicBoolean(false);
    RedFutureHub hub = RedFuture.hub();
    OpenRedFuture future1 = hub.provideFuture();
    OpenRedFuture future2 = hub.provideFuture();
    OpenRedFutureOf<Object> futureOf = hub.provideFutureOf();
    RedFuture union = hub.unitePessimistically();
    union.addSuccessCallback(() -> reachedSuccessBlock.set(true));
    union.addFailureCallback(throwable -> reachedFailureBlock.set(true));
    union.addFinallyCallback(() -> reachedFinallyBlock.set(true));
    Assert.assertFalse(reachedFinallyBlock.get());
    Assert.assertFalse(reachedSuccessBlock.get());
    Assert.assertFalse(reachedFailureBlock.get());
    future1.resolve();
    future2.fail(new TestException());
    futureOf.resolve(new Object());
    Assert.assertTrue(reachedFinallyBlock.get());
    Assert.assertTrue(reachedSuccessBlock.get());
    Assert.assertFalse(reachedFailureBlock.get());
}
 
開發者ID:avivcarmis,項目名稱:java-red,代碼行數:28,代碼來源:TestRedFuture.java

示例2: testDeleteAllWithError

import org.junit.Assert; //導入依賴的package包/類
@Test
public void testDeleteAllWithError(){
    testStore.shouldThrowError(true);
    models.clear();

    List<TestModel> list = new ArrayList<>();
    list.add(new TestModel(1));
    list.add(new TestModel(2));
    list.add(new TestModel(3));
    memoryStore.insertOrUpdate(list);

    TestSubscriber<Integer> observer = new TestSubscriber<>();
    disposables.add(testStore.deleteAll()
            .subscribeOn(Schedulers.io())
            .subscribeWith(observer));

    observer.awaitTerminalEvent(5, SECONDS);
    observer.assertError(Throwable.class);
    observer.assertErrorMessage("deleteAll.error");

    testStore.shouldThrowError(false); // disable error
    Assert.assertEquals(3, models.size());
}
 
開發者ID:playmoweb,項目名稱:store2store,代碼行數:24,代碼來源:StoreServiceUnitTest.java

示例3: xmlDeveSerGeradoCorretamente

import org.junit.Assert; //導入依賴的package包/類
@Test
public void xmlDeveSerGeradoCorretamente() throws IOException{
  String xmlTest = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("loteRpsConsultaSituacao.xml"));
  LoteRpsConsultaSituacao consultaSituacaoLote = new LoteRpsConsultaSituacao("AP1057893n16X103sfhF4RPm", FabricaDeObjetosFake.getRpsPrestador());
  String xml = consultaSituacaoLote.converterParaXml();
  
  Assert.assertEquals(xml, xmlTest);
}
 
開發者ID:pablopdomingos,項目名稱:nfse,代碼行數:9,代碼來源:LoteRpsConsultaSituacaoTest.java

示例4: testNullSeen

import org.junit.Assert; //導入依賴的package包/類
private void testNullSeen(String snippet) {
    ProfilingInfo info = profile(snippet, 1);
    Assert.assertEquals(TriState.FALSE, info.getNullSeen(1));

    continueProfiling(snippet, "ABC");
    Assert.assertEquals(TriState.FALSE, info.getNullSeen(1));

    continueProfiling(snippet, new Object());
    Assert.assertEquals(TriState.FALSE, info.getNullSeen(1));

    if (TriState.TRUE == info.getNullSeen(1)) {
        // See the javadoc comment for ProfilingInfoTest.
        continueProfiling(snippet, (Object) null);
        Assert.assertEquals(TriState.TRUE, info.getNullSeen(1));

        continueProfiling(snippet, 0.0);
        Assert.assertEquals(TriState.TRUE, info.getNullSeen(1));

        continueProfiling(snippet, new Object());
        Assert.assertEquals(TriState.TRUE, info.getNullSeen(1));
    }

    resetProfile(snippet);
    Assert.assertEquals(TriState.FALSE, info.getNullSeen(1));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:ProfilingInfoTest.java

示例5: restoreState

import org.junit.Assert; //導入依賴的package包/類
@Override
public void restoreState(List<Tuple2<Integer, BitSet>> state) throws Exception {
    if (state.isEmpty()) {
        Assert.fail("Function was restored without state - no checkpoint completed before.");
    }

    if (state.size() > 1) {
        Assert.fail("Function was restored with multiple states. unexpected scale-in");
    }

    Tuple2<Integer, BitSet> s = state.get(0);
    this.numElementsSoFar = s.f0;
    this.duplicateChecker.clear();
    this.duplicateChecker.or(s.f1);

    log.debug("IntSequenceExactlyOnceValidator was restored with {} elements", numElementsSoFar);
}
 
開發者ID:pravega,項目名稱:flink-connectors,代碼行數:18,代碼來源:IntSequenceExactlyOnceValidator.java

示例6: testContains

import org.junit.Assert; //導入依賴的package包/類
@Test
public void testContains() throws InterruptedException {
    RSetCache<TestObject> set = redisson.getSetCache("set");

    set.add(new TestObject("1", "2"));
    set.add(new TestObject("1", "2"));
    set.add(new TestObject("2", "3"), 1, TimeUnit.SECONDS);
    set.add(new TestObject("3", "4"));
    set.add(new TestObject("5", "6"));

    Thread.sleep(1000);

    Assert.assertFalse(set.contains(new TestObject("2", "3")));
    Assert.assertTrue(set.contains(new TestObject("1", "2")));
    Assert.assertFalse(set.contains(new TestObject("1", "9")));
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:17,代碼來源:RedissonSetCacheTest.java

示例7: testItem_0172

import org.junit.Assert; //導入依賴的package包/類
public void testItem_0172()
{
  boolean caught;
  caught = false;
  try {
    rc_BigDecimal = new BigDecimal(new char[]{'8', '\1', '\1', '\uFFFF', '8', '8', '\uFFFF', '\uFFFF', '8', '\uFFFF', '\234', '8', '8', '\234', '8', '\234', '\0', '\uFFFF', '\234', '\1', '\1', '\uFFFF', '\1', '8', '\uFFFF', '\uFFFF', '\1', '\234', '8', '8', '\1', '\1', '\234', '\0', '\1', '\uFFFF', '\0', '\uFFFF', '\0', '\234', '\uFFFF', '\uFFFF', '\234', '\234', '\1', '8', '\234', '\uFFFF', '8', '8', '\234', '\1', '\1', '8', '\0', '8', '\1', '\uFFFF', '\uFFFF', '\234', '\uFFFF', '\234', '\1', '\234', '\1', '\0', '\234', '\1', '\234', '\234', '\1', '\1', '\1', '\1', '8', '\0', '\uFFFF', '\1', '\234', '8', '\234', '\1', '\uFFFF', '\0', '8', '\234', '8', '\1', '\234', '\0', '\uFFFF', '8', '\0', '\0', '\0', '8', '8', '\1', '\234', '8'}, new MathContext("precision=2147483647 roundingMode=HALF_EVEN"));
  }
  catch (java.lang.NumberFormatException e) {
    caught = true;
  }
  Assert.assertEquals("91.94630872483222%", true, caught);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite042.java

示例8: testItem_0251

import org.junit.Assert; //導入依賴的package包/類
public void testItem_0251()
{
  boolean caught;
  caught = false;
  try {
    rc_BigDecimal = (new BigDecimal("-9000000000000.0")).pow(-1, new MathContext("precision=0 roundingMode=HALF_EVEN"));
  }
  catch (java.lang.ArithmeticException e) {
    caught = true;
  }
  Assert.assertEquals("91.94630872483222%", true, caught);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite054.java

示例9: testItem_0432

import org.junit.Assert; //導入依賴的package包/類
public void testItem_0432()
{
  boolean caught;
  caught = false;
  try {
    rc_BigDecimal = (new BigDecimal("0")).setScale(0, 2147483647);
  }
  catch (java.lang.IllegalArgumentException e) {
    caught = true;
  }
  Assert.assertEquals("91.94630872483222%", true, caught);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite037.java

示例10: test122

import org.junit.Assert; //導入依賴的package包/類
@Test
public void test122() throws Throwable {
    if (debug)
        System.out.format("%n%s%n", "RegressionTest0.test122");
    Table table2 = new Table("", ",");
    List<String> list_str3 = table2.getTokenizedLowerCaseTrimmedName();
    DatabaseMetaData databaseMetaData4 = null;
    try {
        table2.getPrimaryKeys(databaseMetaData4, ",", "", ",");
        Assert.fail("Expected exception of type java.lang.NullPointerException");
    } catch (NullPointerException e) {
    }
    Assert.assertNull(list_str3);
}
 
開發者ID:janmotl,項目名稱:linkifier,代碼行數:15,代碼來源:RegressionTest.java

示例11: testItem_0623

import org.junit.Assert; //導入依賴的package包/類
public void testItem_0623()
{
  boolean caught;
  caught = false;
  try {
    rc_BigDecimal = new BigDecimal("@W0Y<7W?8EY16NT;[email protected]@UQH5R?<3?LNRD<EH1OJ=XW:MTM9F5WV34");
  }
  catch (java.lang.NumberFormatException e) {
    caught = true;
  }
  Assert.assertEquals("91.94630872483222%", true, caught);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:13,代碼來源:TestSuite031.java

示例12: test_cast_to_SqlDate_sql_Date

import org.junit.Assert; //導入依賴的package包/類
public void test_cast_to_SqlDate_sql_Date() throws Exception {
    long millis = System.currentTimeMillis();

    JSONObject json = new JSONObject();
    json.put("date", new java.sql.Date(millis));
    Assert.assertEquals(new java.sql.Date(millis), json.getObject("date", java.sql.Date.class));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:TypeUtilsTest.java

示例13: test007

import org.junit.Assert; //導入依賴的package包/類
@Test
public void test007() throws Throwable {
    if (debug)
        System.out.format("%n%s%n", "RegressionTest0.test007");
    Relationship relationship0 = new Relationship();
    Column column1 = relationship0.getPk();
    Chen chen2 = null;
    try {
        relationship0.setMediumFeatures(chen2);
        Assert.fail("Expected exception of type java.lang.NullPointerException");
    } catch (NullPointerException e) {
    }
    Assert.assertNull(column1);
}
 
開發者ID:janmotl,項目名稱:linkifier,代碼行數:15,代碼來源:RegressionTest.java

示例14: testEqual5

import org.junit.Assert; //導入依賴的package包/類
@Test
public void testEqual5() throws Exception {
    ValidationException.ExceptionMessageWithStackTrace exp = new ValidationException.ExceptionMessageWithStackTrace(
            null, "string2");
    ValidationException.ExceptionMessageWithStackTrace exp2 =
            new ValidationException.ExceptionMessageWithStackTrace(
            "string1", "string2");
    Assert.assertNotEquals(exp, exp2);
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:10,代碼來源:ValidationExceptionTest.java

示例15: should_get_job_zip_success

import org.junit.Assert; //導入依賴的package包/類
@Test
public void should_get_job_zip_success() throws Exception {
    stubDemo();
    Node rootForFlow = createRootFlow("flow1", "yml/flow.yaml");
    Job job = jobService.createFromFlowYml(rootForFlow.getPath(), JobCategory.TAG, null, mockUser);

    job.putEnv(GitEnvs.FLOW_GIT_BRANCH, "master");
    job.setStatus(JobStatus.SUCCESS);
    jobDao.update(job);

    List<NodeResult> nodeResultList = nodeResultService.list(job, true);
    for (NodeResult nodeResult : nodeResultList) {
        nodeResult.setCmdId("xxxx");
        nodeResultService.update(nodeResult);
    }

    MvcResult mvcResult = this.mockMvc.perform(
        get(String.format("/jobs/%s/%s/log/download", job.getNodeName(), job.getNumber()))
    ).andExpect(status().isOk()).andReturn();
    String response = mvcResult.getResponse().getContentAsString();
    Assert.assertNotNull(response);

    Path zipLog = Paths
        .get(workspace.toString(), job.getNodeName(), "log", job.getId().toString(),
            job.getId().toString() + ".zip");
    File zipFile = new File(zipLog.toString());
    Assert.assertEquals(true, zipFile.exists());
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:29,代碼來源:JobControllerTest.java


注:本文中的org.junit.Assert類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。