junit.framework.Assert.assertTrue()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(461)

本文整理了Java中junit.framework.Assert.assertTrue()方法的一些代码示例,展示了Assert.assertTrue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert.assertTrue()方法的具体详情如下:
包路径:junit.framework.Assert
类名称:Assert
方法名:assertTrue

Assert.assertTrue介绍

[英]Asserts that a condition is true. If it isn't it throws an AssertionFailedError with the given message.
[中]断言某个条件为真。如果不是,则会抛出带有给定消息的AssertionFailedError。

代码示例

代码示例来源:origin: google/guava

private void testItems() {
 for (Object item : Iterables.concat(equalityGroups)) {
  assertTrue(item + " must not be Object#equals to null", !item.equals(null));
  assertTrue(
    item + " must not be Object#equals to an arbitrary object of another class",
    !item.equals(NotAnInstance.EQUAL_TO_NOTHING));
  assertEquals(item + " must be Object#equals to itself", item, item);
  assertEquals(
    "the Object#hashCode of " + item + " must be consistent",
    item.hashCode(),
    item.hashCode());
 }
}

代码示例来源:origin: google/guava

@SuppressWarnings({"SelfComparison", "SelfEquals"})
public static <T extends Comparable<? super T>> void testCompareToAndEquals(
  List<T> valuesInExpectedOrder) {
 // This does an O(n^2) test of all pairs of values in both orders
 for (int i = 0; i < valuesInExpectedOrder.size(); i++) {
  T t = valuesInExpectedOrder.get(i);
  for (int j = 0; j < i; j++) {
   T lesser = valuesInExpectedOrder.get(j);
   assertTrue(lesser + ".compareTo(" + t + ')', lesser.compareTo(t) < 0);
   assertFalse(lesser.equals(t));
  }
  assertEquals(t + ".compareTo(" + t + ')', 0, t.compareTo(t));
  assertTrue(t.equals(t));
  for (int j = i + 1; j < valuesInExpectedOrder.size(); j++) {
   T greater = valuesInExpectedOrder.get(j);
   assertTrue(greater + ".compareTo(" + t + ')', greater.compareTo(t) > 0);
   assertFalse(greater.equals(t));
  }
 }
}

代码示例来源:origin: google/guava

Comparator<? super T> comparator, List<T> valuesInExpectedOrder) {
for (int i = 0; i < valuesInExpectedOrder.size(); i++) {
 T t = valuesInExpectedOrder.get(i);
  assertTrue(
    comparator + ".compare(" + lesser + ", " + t + ")", comparator.compare(lesser, t) < 0);
 assertEquals(comparator + ".compare(" + t + ", " + t + ")", 0, comparator.compare(t, t));
 for (int j = i + 1; j < valuesInExpectedOrder.size(); j++) {
  T greater = valuesInExpectedOrder.get(j);
  assertTrue(
    comparator + ".compare(" + greater + ", " + t + ")",
    comparator.compare(greater, t) > 0);

代码示例来源:origin: apache/incubator-druid

@Test
public void testSplitOccursRoaring()
{
 Random rand = ThreadLocalRandom.current();
 for (int i = 0; i < 100; i++) {
  roaringtree.insert(new float[]{rand.nextFloat(), rand.nextFloat()}, i);
 }
 Assert.assertTrue(roaringtree.getRoot().getChildren().size() > 1);
}

代码示例来源:origin: apache/ignite

@Override public Object call() throws Exception {
    List<ClusterNode> checkNodes = new ArrayList<>(nodes);
    assert checkNodes.size() > 1;
    b.await();
    for (int i = 0; i < 100; i++) {
      IgniteFuture<BitSet> fut = spi.checkConnection(checkNodes);
      BitSet res = fut.get();
      for (int n = 0; n < checkNodes.size(); n++)
        assertTrue(res.get(n));
    }
    return null;
  }
}));

代码示例来源:origin: json-path/JsonPath

@Test
public void size_filters_evaluates() throws Exception {
  Map<String, Object> check = new HashMap<String, Object>();
  check.put("items", asList(1, 2, 3));
  check.put("items_empty", Collections.emptyList());
  assertTrue(filter(where("items").size(3)).apply(createPredicateContext(check)));
  assertTrue(filter(where("items_empty").size(0)).apply(createPredicateContext(check)));
  assertFalse(filter(where("items").size(2)).apply(createPredicateContext(check)));
}

代码示例来源:origin: apache/incubator-druid

@Test
 public void testSigarLoad()
 {
  Sigar sigar = SigarUtil.getSigar();
  Assert.assertTrue(sigar.getPid() > 0);
 }
}

代码示例来源:origin: facebook/facebook-android-sdk

@Test
  public void testJsonObjectValues() throws JSONException {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("hello", "world");
    jsonObject.put("hocus", "pocus");

    Collection<Object> values = JsonUtil.jsonObjectValues(jsonObject);

    assertEquals(2, values.size());
    assertTrue(values.contains("world"));
  }
}

代码示例来源:origin: facebook/facebook-android-sdk

@Test
  public void testGetAttachmentFile() throws Exception {
    NativeAppCallAttachmentStore.ensureAttachmentsDirectoryExists();
    File dir = NativeAppCallAttachmentStore.getAttachmentFile(CALL_ID, ATTACHMENT_NAME, false);
    assertNotNull(dir);
    assertTrue(
        dir.getAbsolutePath().contains(NativeAppCallAttachmentStore.ATTACHMENTS_DIR_NAME));
    assertTrue(dir.getAbsolutePath().contains(CALL_ID.toString()));
    assertTrue(dir.getAbsolutePath().contains(ATTACHMENT_NAME.toString()));
  }
}

代码示例来源:origin: apache/avro

protected void checkRPCMetaMap(Map<String,ByteBuffer> rpcMeta) {
 Assert.assertNotNull(rpcMeta);
 Assert.assertTrue("key not present in map", rpcMeta.containsKey(key));
 ByteBuffer keybuf = rpcMeta.get(key);
 Assert.assertNotNull(keybuf);
 Assert.assertTrue("key BB had nothing remaining", keybuf.remaining() > 0);
 String str = new String(keybuf.array());
 Assert.assertEquals("apache", str);
}

代码示例来源:origin: google/guava

public void testCompletedFuture(@Nullable Object expectedValue)
  throws InterruptedException, ExecutionException {
 assertTrue(future.isDone());
 assertFalse(future.isCancelled());
 assertTrue(latch.await(5, TimeUnit.SECONDS));
 assertTrue(future.isDone());
 assertFalse(future.isCancelled());
 assertEquals(expectedValue, future.get());
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public void loadCache(IgniteBiInClosure<Integer, Integer> clo,
  @Nullable Object... args) throws CacheLoaderException {
  assertNotNull(args);
  assertTrue(args.length > 0);
  for (Object arg : args) {
    Integer k = (Integer)arg;
    clo.apply(k, k);
  }
}

代码示例来源:origin: google/guava

public void testFailedFuture(@Nullable String message) throws InterruptedException {
  assertTrue(future.isDone());
  assertFalse(future.isCancelled());

  assertTrue(latch.await(5, TimeUnit.SECONDS));
  assertTrue(future.isDone());
  assertFalse(future.isCancelled());

  try {
   future.get();
   fail("Future should rethrow the exception.");
  } catch (ExecutionException e) {
   assertThat(e).hasCauseThat().hasMessageThat().isEqualTo(message);
  }
 }
}

代码示例来源:origin: google/guava

assertFalse(resultsForStrategy.contains(null));
 comparator = (Comparator) Comparator.naturalOrder();
assertTrue(Ordering.from(comparator).isOrdered(resultsForStrategy));
assertEquals(Ints.checkedCast(estimatedSize), resultsForStrategy.size());

代码示例来源:origin: apache/incubator-druid

@Test
public void testSplitOccurs()
{
 Random rand = ThreadLocalRandom.current();
 for (int i = 0; i < 100; i++) {
  tree.insert(new float[]{rand.nextFloat(), rand.nextFloat()}, i);
 }
 Assert.assertTrue(tree.getRoot().getChildren().size() > 1);
}

代码示例来源:origin: voldemort/voldemort

private void assertPresence(int start, int end) {
  for (int i = start; i < end; i++) {
    ByteArray b = new ByteArray(Integer.toString(i).getBytes());
    List<Versioned<byte[]>> found = engine.get(b, null);
    assertTrue("Did not find key '" + i + "' in store!", found.size() > 0);
  }
}

代码示例来源:origin: apache/incubator-pinot

private void testAllFailed(List<String> segments) {
 HelixAdmin helixAdmin = makeHelixAdmin();
 ZkHelixPropertyStore<ZNRecord> propertyStore = makePropertyStore();
 FakeDeletionManager deletionManager = new FakeDeletionManager(helixAdmin, propertyStore);
 deletionManager.deleteSegmentsFromPropertyStoreAndLocal(tableName, segments);
 Assert.assertTrue(deletionManager.segmentsToRetry.containsAll(segments));
 Assert.assertEquals(deletionManager.segmentsToRetry.size(), segments.size());
 Assert.assertEquals(deletionManager.segmentsRemovedFromStore.size(), 0);
}

代码示例来源:origin: json-path/JsonPath

@Test
public void all_filters_evaluates() throws Exception {
  Map<String, Object> check = new HashMap<String, Object>();
  check.put("items", asList(1, 2, 3));
  assertTrue(filter(where("items").all(1, 2, 3)).apply(createPredicateContext(check)));
  assertFalse(filter(where("items").all(1, 2, 3, 4)).apply(createPredicateContext(check)));
}

代码示例来源:origin: airbnb/lottie-android

@Test
public void testDisabled() {
 performanceTracker.setEnabled(false);
 performanceTracker.recordRenderTime("Hello", 16f);
 assertTrue(performanceTracker.getSortedRenderTimes().isEmpty());
}

代码示例来源:origin: apache/hive

@Test
public void testValidTxnsEmpty() throws Exception {
 GetOpenTxnsInfoResponse txnsInfo = txnHandler.getOpenTxnsInfo();
 assertEquals(0L, txnsInfo.getTxn_high_water_mark());
 assertTrue(txnsInfo.getOpen_txns().isEmpty());
 GetOpenTxnsResponse txns = txnHandler.getOpenTxns();
 assertEquals(0L, txns.getTxn_high_water_mark());
 assertTrue(txns.getOpen_txns().isEmpty());
}

相关文章