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

x33g5p2x  于2022-01-29 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(219)

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

TestCase.assertTrue介绍

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

代码示例

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

/**
 * Asserts that two iterators contain elements in tandem.
 *
 * <p>This test only works with iterators that iterate over a finite set.
 */
public static void assertIteratorsInOrder(
  Iterator<?> expectedIterator, Iterator<?> actualIterator) {
 int i = 0;
 while (expectedIterator.hasNext()) {
  Object expected = expectedIterator.next();
  assertTrue(
    "index " + i + " expected <" + expected + "., actual is exhausted",
    actualIterator.hasNext());
  Object actual = actualIterator.next();
  assertEquals("index " + i, expected, actual);
  i++;
 }
 if (actualIterator.hasNext()) {
  fail("index " + i + ", expected is exhausted, actual <" + actualIterator.next() + ">");
 }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void setComplete() throws Exception {
  TestServerHttpResponse response = new TestServerHttpResponse();
  response.setComplete().block();
  assertTrue(response.statusCodeWritten);
  assertTrue(response.headersWritten);
  assertTrue(response.cookiesWritten);
  assertTrue(response.body.isEmpty());
}

代码示例来源:origin: LitePalFramework/LitePal

@Test
public void testQueryBySQLWithPlaceHolder() {
  Cursor cursor = LitePal.findBySQL(
      "select * from " + bookTable + " where id=? and bookname=? and pages=?",
      String.valueOf(book.getId()), "数据库", "300");
  assertTrue(cursor.getCount() == 1);
  cursor.moveToFirst();
  String bookName = cursor.getString(cursor.getColumnIndexOrThrow("bookname"));
  int pages = cursor.getInt(cursor.getColumnIndexOrThrow("pages"));
  assertEquals(bookName, "数据库");
  assertEquals(pages, 300);
  cursor.close();
}

代码示例来源:origin: spring-projects/spring-framework

@Test  // SPR-14952
public void writeAndFlushWithFluxOfDefaultDataBuffer() throws Exception {
  TestServerHttpResponse response = new TestServerHttpResponse();
  Flux<Flux<DefaultDataBuffer>> flux = Flux.just(Flux.just(wrap("foo")));
  response.writeAndFlushWith(flux).block();
  assertTrue(response.statusCodeWritten);
  assertTrue(response.headersWritten);
  assertTrue(response.cookiesWritten);
  assertEquals(1, response.body.size());
  assertEquals("foo", new String(response.body.get(0).asByteBuffer().array(), StandardCharsets.UTF_8));
}

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

@Test
  public void testBasics() {
    SinglePointTour tour = new SinglePointTour(new Random(0), 100);
    assertEquals(1, tour.getNumberOfGeneratedPoints());

    assertTrue(0 <= tour.getHeadingForIteration(0));
    assertTrue(360 >= tour.getHeadingForIteration(0));

    assertTrue(29 <= tour.getDistanceForIteration(0));
    assertTrue(37 >= tour.getDistanceForIteration(0));
  }
}

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

@Override
protected void process(ByteBuffer bb) {
 processCalled++;
 assertEquals(ByteOrder.LITTLE_ENDIAN, bb.order());
 assertTrue(bb.remaining() >= chunkSize);
 for (int i = 0; i < chunkSize; i++) {
  out.write(bb.get());
 }
}

代码示例来源:origin: lets-blade/blade

@Test
public void chars2Bytes() throws Exception {
  assertTrue(
      Arrays.equals(
          mBytes1,
          ConvertKit.chars2Bytes(mChars1)
      )
  );
}

代码示例来源:origin: LitePalFramework/LitePal

@Test
public void testFindUniqueColumns() {
  List<String> uniqueColumns = DBUtility.findUniqueColumns(DBUtility.getTableNameByClassName(
          Cellphone.class.getName()), db);
  assertEquals(1, uniqueColumns.size());
  assertTrue(uniqueColumns.contains("serial"));
  uniqueColumns = DBUtility.findUniqueColumns(DBUtility.getTableNameByClassName(Book.class.getName()), db);
  assertEquals(0, uniqueColumns.size());
}

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

@Override
 public void run() {
  try {
   Future<?> future = executor.submit(incrementTask);
   assertTrue(future.isDone());
   assertEquals(1, threadLocalCount.get().intValue());
  } catch (Throwable t) {
   throwableFromOtherThread.set(t);
  }
 }
});

代码示例来源:origin: lets-blade/blade

@Test
public void hexString2Bytes() throws Exception {
  assertTrue(
      Arrays.equals(
          mBytes,
          ConvertKit.hexString2Bytes(hexString)
      )
  );
}

代码示例来源:origin: LitePalFramework/LitePal

@Test
public void testUpdateM2OAssociationsOnOSideWithNotSavedModel() {
  init();
  c1.getStudentCollection().add(s1);
  c1.getStudentCollection().add(s2);
  assertTrue(c1.save());
  assertTrue(c2.save());
  assertTrue(s1.save());
  c2.getStudentCollection().add(s1);
  c2.getStudentCollection().add(s2);
  assertTrue(c2.save());
  assertEquals(c2.get_id(), getForeignKeyValue(studentTable, classroomTable, s1.getId()));
}

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

@Override
protected void shutDown() {
 assertTrue(startUpCalled);
 assertTrue(runCalled);
 assertFalse(shutDownCalled);
 shutDownCalled = true;
 assertEquals(expectedShutdownState, state());
}

代码示例来源:origin: lets-blade/blade

@Test
public void bytes2Chars() throws Exception {
  assertTrue(
      Arrays.equals(
          mChars1,
          ConvertKit.bytes2Chars(mBytes1)
      )
  );
}

代码示例来源:origin: LitePalFramework/LitePal

@Test
public void testEagerFindLast() {
  resetData();
  Teacher t1 = LitePal.findLast(Teacher.class);
  assertEquals(0, t1.getStudents().size());
  t1 = LitePal.findLast(Teacher.class, true);
  assertTrue(0 < t1.getStudents().size());
}

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

@Override
protected void processRemaining(ByteBuffer bb) {
 assertFalse(remainingCalled);
 remainingCalled = true;
 assertEquals(ByteOrder.LITTLE_ENDIAN, bb.order());
 assertTrue(bb.remaining() > 0);
 assertTrue(bb.remaining() < bufferSize);
 int before = processCalled;
 super.processRemaining(bb);
 int after = processCalled;
 assertEquals(before + 1, after); // default implementation pads and calls process()
 processCalled--; // don't count the tail invocation (makes tests a bit more understandable)
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void writeWith() throws Exception {
  TestServerHttpResponse response = new TestServerHttpResponse();
  response.writeWith(Flux.just(wrap("a"), wrap("b"), wrap("c"))).block();
  assertTrue(response.statusCodeWritten);
  assertTrue(response.headersWritten);
  assertTrue(response.cookiesWritten);
  assertEquals(3, response.body.size());
  assertEquals("a", new String(response.body.get(0).asByteBuffer().array(), StandardCharsets.UTF_8));
  assertEquals("b", new String(response.body.get(1).asByteBuffer().array(), StandardCharsets.UTF_8));
  assertEquals("c", new String(response.body.get(2).asByteBuffer().array(), StandardCharsets.UTF_8));
}

代码示例来源:origin: LitePalFramework/LitePal

@Test
public void testUpdateM2OAssociationsOnOSideWithEmptyCollection() {
  init();
  s1.setClassroom(c1);
  s2.setClassroom(c1);
  assertTrue(c1.save());
  assertTrue(s1.save());
  assertTrue(s2.save());
  c1.getStudentCollection().clear();
  assertTrue(c1.save());
  assertEquals(0, getForeignKeyValue(studentTable, classroomTable, s1.getId()));
  assertEquals(0, getForeignKeyValue(studentTable, classroomTable, s2.getId()));
}

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

@Override
protected void runOneIteration() throws Exception {
 assertTrue(startUpCalled);
 assertFalse(shutDownCalled);
 numberOfTimesRunCalled.incrementAndGet();
 assertEquals(State.RUNNING, state());
 runFirstBarrier.await();
 runSecondBarrier.await();
 if (runException != null) {
  throw runException;
 }
}

代码示例来源:origin: LitePalFramework/LitePal

@Test
public void testQueryBySQL() {
  Cursor cursor = LitePal.findBySQL("select * from " + bookTable);
  assertTrue(cursor.getCount() > 0);
  cursor.close();
}

代码示例来源:origin: LitePalFramework/LitePal

@Test
public void testUpdateM2OAssociationsOnOSideWithNull() {
  init();
  s1.setClassroom(c1);
  s2.setClassroom(c1);
  assertTrue(c1.save());
  assertTrue(s1.save());
  assertTrue(s2.save());
  c1.setStudentCollection(null);
  assertTrue(c1.save());
  assertEquals(0, getForeignKeyValue(studentTable, classroomTable, s1.getId()));
  assertEquals(0, getForeignKeyValue(studentTable, classroomTable, s2.getId()));
}

相关文章