org.junit.Assert.assertFalse()方法的使用及代码示例

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

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

Assert.assertFalse介绍

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

代码示例

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

@Test
public void test() {
  assertNotNull("TestRule should have been @Autowired", autowiredTestRule);
  // Rationale for the following assertion:
  //
  // The field value for the custom rule is null when JUnit sees it. JUnit then
  // ignores the null value, and at a later point in time Spring injects the rule
  // from the ApplicationContext and overrides the null field value. But that's too
  // late: JUnit never sees the rule supplied by Spring via dependency injection.
  assertFalse("@Autowired TestRule should NOT have been applied", autowiredTestRule.applied);
}

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

@Test
public void verifyRootWacConfig() {
  ApplicationContext parent = wac.getParent();
  assertNotNull(parent);
  assertFalse(parent instanceof WebApplicationContext);
  assertEquals("ear", ear);
  assertEquals("root", root);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void hidden() {
  assertTrue(Maybe.just(1) instanceof ScalarCallable);
  assertFalse(Maybe.just(1).hide() instanceof ScalarCallable);
}

代码示例来源:origin: commons-io/commons-io

private void assertLines(final List<String> lines, final LineIterator iterator) {
  try {
    for (int i = 0; i < lines.size(); i++) {
      final String line = iterator.nextLine();
      assertEquals("nextLine() line " + i, lines.get(i), line);
    }
    assertFalse("No more expected", iterator.hasNext());
  } finally {
    LineIterator.closeQuietly(iterator);
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testTakeOneSubscriber() {
  BehaviorSubject<Integer> source = BehaviorSubject.createDefault(1);
  final Observer<Object> o = TestHelper.mockObserver();
  source.take(1).subscribe(o);
  verify(o).onNext(1);
  verify(o).onComplete();
  verify(o, never()).onError(any(Throwable.class));
  assertEquals(0, source.subscriberCount());
  assertFalse(source.hasObservers());
}

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

/** Tests that basic executeQuery() (with query statement) works. */
@Test
public void testExecuteQueryBasicCaseWorks() throws SQLException {
 try (PreparedStatement stmt = connection.prepareStatement( "VALUES 11" )) {
  try(ResultSet rs = stmt.executeQuery()) {
   assertThat("Unexpected column count",
     rs.getMetaData().getColumnCount(), equalTo(1)
   );
   assertTrue("No expected first row", rs.next());
   assertThat(rs.getInt(1), equalTo(11));
   assertFalse("Unexpected second row", rs.next());
  }
 }
}

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

private void doTestLazyResourceInjection(Class<? extends TestBeanHolder> annotatedBeanClass) {
  AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
  RootBeanDefinition abd = new RootBeanDefinition(annotatedBeanClass);
  abd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
  ac.registerBeanDefinition("annotatedBean", abd);
  RootBeanDefinition tbd = new RootBeanDefinition(TestBean.class);
  tbd.setLazyInit(true);
  ac.registerBeanDefinition("testBean", tbd);
  ac.refresh();
  TestBeanHolder bean = ac.getBean("annotatedBean", TestBeanHolder.class);
  assertFalse(ac.getBeanFactory().containsSingleton("testBean"));
  assertNotNull(bean.getTestBean());
  assertNull(bean.getTestBean().getName());
  assertTrue(ac.getBeanFactory().containsSingleton("testBean"));
  TestBean tb = (TestBean) ac.getBean("testBean");
  tb.setName("tb");
  assertSame("tb", bean.getTestBean().getName());
}

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

@Test
public void testStaticScriptWithInlineDefinedInstanceUsingJsr223() throws Exception {
  ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContextWithJsr223.xml", getClass());
  assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstanceInline"));
  Messenger messenger = (Messenger) ctx.getBean("messengerInstanceInline");
  assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger));
  assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);
  String desiredMessage = "Hello World!";
  assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
  assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void untilPublisherMainSuccess() {
  MaybeSubject<Integer> main = MaybeSubject.create();
  PublishProcessor<Integer> other = PublishProcessor.create();
  TestObserver<Integer> to = main.takeUntil(other).test();
  assertTrue("Main no observers?", main.hasObservers());
  assertTrue("Other no observers?", other.hasSubscribers());
  main.onSuccess(1);
  assertFalse("Main has observers?", main.hasObservers());
  assertFalse("Other has observers?", other.hasSubscribers());
  to.assertResult(1);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyCompleted() {
  ReplaySubject<Object> rs = ReplaySubject.createUnbounded();
  rs.onComplete();
  assertEquals(0, rs.size());
  assertFalse(rs.hasValue());
}

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

/** Tests that basic executeQuery() (with query statement) works. */
@Test
public void testExecuteQueryBasicCaseWorks() throws SQLException {
 try (PreparedStatement stmt = connection.prepareStatement( "VALUES 11" )) {
  try(ResultSet rs = stmt.executeQuery()) {
   assertThat("Unexpected column count",
     rs.getMetaData().getColumnCount(), equalTo(1)
   );
   assertTrue("No expected first row", rs.next());
   assertThat(rs.getInt(1), equalTo(11));
   assertFalse("Unexpected second row", rs.next());
  }
 }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void normal() {
  TestDisposableObserver<Integer> tc = new TestDisposableObserver<Integer>();
  assertFalse(tc.isDisposed());
  assertEquals(0, tc.start);
  assertTrue(tc.values.isEmpty());
  assertTrue(tc.errors.isEmpty());
  Observable.just(1).subscribe(tc);
  assertFalse(tc.isDisposed());
  assertEquals(1, tc.start);
  assertEquals(1, tc.values.get(0).intValue());
  assertTrue(tc.errors.isEmpty());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnDispose() {
  final PublishProcessor<String> processor = PublishProcessor.create();
  final TestScheduler scheduler = new TestScheduler();
  final TestSubscriber<String> subscriber = processor
      .timeout(100, TimeUnit.MILLISECONDS, scheduler)
      .test();
  assertTrue(processor.hasSubscribers());
  subscriber.dispose();
  assertFalse(processor.hasSubscribers());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testSizeAndHasAnyValueUnboundedEmptyCompleted() {
  ReplayProcessor<Object> rs = ReplayProcessor.create();
  rs.onComplete();
  assertEquals(0, rs.size());
  assertFalse(rs.hasValue());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void normal() {
  TestSingle<Integer> tc = new TestSingle<Integer>();
  assertFalse(tc.isDisposed());
  assertEquals(0, tc.start);
  assertTrue(tc.values.isEmpty());
  assertTrue(tc.errors.isEmpty());
  Single.just(1).subscribe(tc);
  assertFalse(tc.isDisposed());
  assertEquals(1, tc.start);
  assertEquals(1, tc.values.get(0).intValue());
  assertTrue(tc.errors.isEmpty());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void dispose() {
  PublishProcessor<Integer> pp = PublishProcessor.create();
  TestObserver<Integer> to = pp.singleElement().delay(100, TimeUnit.MILLISECONDS).test();
  assertTrue(pp.hasSubscribers());
  to.cancel();
  assertFalse(pp.hasSubscribers());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyCompleted() {
  ReplayProcessor<Object> rs = ReplayProcessor.createUnbounded();
  rs.onComplete();
  assertEquals(0, rs.size());
  assertFalse(rs.hasValue());
}

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

@Test
@SuppressWarnings("unchecked")
public void testEntityManagerProxyIsProxy() {
  EntityManager em = entityManagerFactory.createEntityManager();
  assertTrue(Proxy.isProxyClass(em.getClass()));
  Query q = em.createQuery("select p from Person as p");
  List<Person> people = q.getResultList();
  assertNotNull(people);
  assertTrue("Should be open to start with", em.isOpen());
  em.close();
  assertFalse("Close should work on application managed EM", em.isOpen());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void dispose() {
  PublishProcessor<Integer> pp = PublishProcessor.create();
  TestObserver<Integer> to = pp.singleElement().switchIfEmpty(Single.just(2)).test();
  assertTrue(pp.hasSubscribers());
  to.cancel();
  assertFalse(pp.hasSubscribers());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testSizeAndHasAnyValueUnboundedEmptyError() {
  ReplayProcessor<Object> rs = ReplayProcessor.create();
  rs.onError(new TestException());
  assertEquals(0, rs.size());
  assertFalse(rs.hasValue());
}

相关文章