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

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

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

Assert.assertNull介绍

[英]Asserts that an object is null. If it isn't an AssertionError is thrown.
[中]断言对象为空。如果不是断言,则抛出断言错误。

代码示例

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

@Test
public void loadContextHierarchy() {
  assertNotNull("child ApplicationContext", context);
  assertNull("parent ApplicationContext", context.getParent());
  assertEquals("foo-level-1", foo);
  assertEquals("bar", bar);
}

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

@Test
  public void scalarCallable() {
    Maybe<Integer> m = Maybe.empty();

    assertTrue(m.getClass().toString(), m instanceof ScalarCallable);

    assertNull(((ScalarCallable<?>)m).call());
  }
}

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

@Test
  public void dispose() {
    Queue<Object> q = new ArrayDeque<Object>();

    BlockingObserver<Object> bo = new BlockingObserver<Object>(q);

    bo.dispose();

    assertEquals(BlockingObserver.TERMINATED, q.poll());

    bo.dispose();

    assertNull(q.poll());
  }
}

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

@Test
  public void basicCoverage() throws Exception {
    Disposable d = Disposables.empty();

    DisposeOnCancel doc = new DisposeOnCancel(d);

    assertFalse(doc.cancel(true));

    assertFalse(doc.isCancelled());

    assertFalse(doc.isDone());

    assertNull(doc.get());

    assertNull(doc.get(1, TimeUnit.SECONDS));
  }
}

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

@Test
public void okNoBody() {
  ResponseEntity<Void> responseEntity = ResponseEntity.ok().build();
  assertNotNull(responseEntity);
  assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
  assertNull(responseEntity.getBody());
}

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

@Test
  public void blockingGetErrorTimedOut() {
    final BlockingMultiObserver<Integer> bmo = new BlockingMultiObserver<Integer>();

    try {
      assertNull(bmo.blockingGetError(1, TimeUnit.NANOSECONDS));
      fail("Should have thrown");
    } catch (RuntimeException expected) {
      assertEquals(TimeoutException.class, expected.getCause().getClass());
      assertEquals(timeoutMessage(1, TimeUnit.NANOSECONDS), expected.getCause().getMessage());
    }
  }
}

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

@Test
public void valueOfOnCompleteIsNull() {
  Notification<Integer> notification = Notification.createOnComplete();
  assertNull(notification.getValue());
  assertNull(notification.getError());
  assertTrue(notification.isOnComplete());
}

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

@Test
public void loadContextHierarchy() {
  assertNotNull("child ApplicationContext", context);
  assertNull("parent ApplicationContext", context.getParent());
  assertEquals("foo-level-1", foo);
  assertEquals("bar", bar);
}

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

@Test
public void spscArrayQueueBiOffer() {
  SpscArrayQueue<Object> q = new SpscArrayQueue<Object>(16);
  q.offer(1, 2);
  assertEquals(1, q.poll());
  assertEquals(2, q.poll());
  assertNull(q.poll());
}

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

@Test
public void onCompleteOnError() throws Exception {
  fs.onComplete();
  fs.onError(new TestException("One"));
  try {
    assertNull(fs.get(5, TimeUnit.MILLISECONDS));
  } catch (ExecutionException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof NoSuchElementException);
  }
}

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

@Test
public void loadContextHierarchy() {
  assertNotNull("child ApplicationContext", context);
  assertNull("parent ApplicationContext", context.getParent());
  assertEquals("foo-level-1", foo);
  assertEquals("bar", bar);
}

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

@Test
public void spscLinkedArrayQueueBiOffer() {
  SpscLinkedArrayQueue<Object> q = new SpscLinkedArrayQueue<Object>(16);
  q.offer(1, 2);
  assertEquals(1, q.poll());
  assertEquals(2, q.poll());
  assertNull(q.poll());
}

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

@Test
public void valueOfOnErrorIsNull() {
  Notification<Integer> notification = Notification.createOnError(new TestException());
  assertNull(notification.getValue());
  assertTrue(notification.getError().toString(), notification.getError() instanceof TestException);
}

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

@SuppressWarnings("unchecked")
@Test
public void callable() throws Exception {
  final int[] counter = { 0 };
  Maybe<Void> m = Maybe.fromAction(new Action() {
    @Override
    public void run() throws Exception {
      counter[0]++;
    }
  });
  assertTrue(m.getClass().toString(), m instanceof Callable);
  assertNull(((Callable<Void>)m).call());
  assertEquals(1, counter[0]);
}

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

@Test
public void mpscLinkedQueueBiOffer() {
  MpscLinkedQueue<Object> q = new MpscLinkedQueue<Object>();
  q.offer(1, 2);
  assertEquals(1, q.poll());
  assertEquals(2, q.poll());
  assertNull(q.poll());
}

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

@SuppressWarnings("unchecked")
@Test
public void callable() throws Exception {
  final int[] counter = { 0 };
  Maybe<Void> m = Maybe.fromRunnable(new Runnable() {
    @Override
    public void run() {
      counter[0]++;
    }
  });
  assertTrue(m.getClass().toString(), m instanceof Callable);
  assertNull(((Callable<Void>)m).call());
  assertEquals(1, counter[0]);
}

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

@Test
public void clear() {
  DeferredScalarSubscription<Integer> ds = new DeferredScalarSubscription<Integer>(new TestSubscriber<Integer>());
  ds.value = 1;
  ds.clear();
  assertEquals(DeferredScalarSubscription.FUSED_CONSUMED, ds.get());
  assertNull(ds.value);
}

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

@Test
@Override
public void loadContextHierarchy() {
  assertNotNull("child ApplicationContext", context);
  assertNotNull("parent ApplicationContext", context.getParent());
  assertNull("grandparent ApplicationContext", context.getParent().getParent());
  assertEquals("parent", parent);
  assertEquals("parent + test user", user);
  assertEquals("from TestUserConfig", beanFromTestUserConfig);
  assertNull("Bean from UserConfig should not be present.", beanFromUserConfig);
}

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

@Test
public void error() {
  TestResourceSingleObserver<Integer> rso = new TestResourceSingleObserver<Integer>();
  assertFalse(rso.isDisposed());
  assertEquals(0, rso.start);
  assertNull(rso.value);
  assertTrue(rso.errors.isEmpty());
  final RuntimeException error = new RuntimeException("error");
  Single.<Integer>error(error).subscribe(rso);
  assertTrue(rso.isDisposed());
  assertEquals(1, rso.start);
  assertNull(rso.value);
  assertEquals(1, rso.errors.size());
  assertTrue(rso.errors.contains(error));
}

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

@Test
public void acceptedNoBody() throws URISyntaxException {
  ResponseEntity<Void> responseEntity = ResponseEntity.accepted().build();
  assertNotNull(responseEntity);
  assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
  assertNull(responseEntity.getBody());
}

相关文章