org.mockito.Mockito.notNull()方法的使用及代码示例

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

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

Mockito.notNull介绍

暂无

代码示例

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

private static void verifyObserver(Observer<Integer> mock, int numSubscriptions, int numItemsExpected, Throwable error) {
  verify(mock, times(numItemsExpected)).onNext((Integer) notNull());
  verify(mock, times(numSubscriptions)).onError(error);
  verifyNoMoreInteractions(mock);
}

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

private static void verifyObserverMock(Observer<Integer> mock, int numSubscriptions, int numItemsExpected) {
  verify(mock, times(numItemsExpected)).onNext((Integer) notNull());
  verify(mock, times(numSubscriptions)).onComplete();
  verifyNoMoreInteractions(mock);
}

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

private static void verifyObserver(Subscriber<Integer> mock, int numSubscriptions, int numItemsExpected, Throwable error) {
  verify(mock, times(numItemsExpected)).onNext((Integer) notNull());
  verify(mock, times(numSubscriptions)).onError(error);
  verifyNoMoreInteractions(mock);
}

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

private static void verifyObserverMock(Subscriber<Integer> mock, int numSubscriptions, int numItemsExpected) {
  verify(mock, times(numItemsExpected)).onNext((Integer) notNull());
  verify(mock, times(numSubscriptions)).onComplete();
  verifyNoMoreInteractions(mock);
}

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

@Test
public void testTakeDoesntLeakErrors() {
  Observable<String> source = Observable.unsafeCreate(new ObservableSource<String>() {
    @Override
    public void subscribe(Observer<? super String> observer) {
      observer.onSubscribe(Disposables.empty());
      observer.onNext("one");
      observer.onError(new Throwable("test failed"));
    }
  });
  Observer<String> observer = TestHelper.mockObserver();
  source.take(1).subscribe(observer);
  verify(observer).onSubscribe((Disposable)notNull());
  verify(observer, times(1)).onNext("one");
  // even though onError is called we take(1) so shouldn't see it
  verify(observer, never()).onError(any(Throwable.class));
  verify(observer, times(1)).onComplete();
  verifyNoMoreInteractions(observer);
}

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

@Test
public void webSocketConnectionEstablished() throws Exception {
  connect().afterConnectionEstablished(this.webSocketSession);
  verify(this.stompSession).afterConnected(notNull());
}

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

@Test
public void testOnErrorFromNotificationHandler() {
  Observer<String> observer = TestHelper.mockObserver();
  Observable<String> origin = Observable.unsafeCreate(new FuncWithErrors(2));
  origin.retryWhen(new Function<Observable<? extends Throwable>, Observable<?>>() {
    @Override
    public Observable<?> apply(Observable<? extends Throwable> t1) {
      return Observable.error(new RuntimeException());
    }
  }).subscribe(observer);
  InOrder inOrder = inOrder(observer);
  inOrder.verify(observer).onSubscribe((Disposable)notNull());
  inOrder.verify(observer, never()).onNext("beginningEveryTime");
  inOrder.verify(observer, never()).onNext("onSuccessOnly");
  inOrder.verify(observer, never()).onComplete();
  inOrder.verify(observer, times(1)).onError(any(RuntimeException.class));
  inOrder.verifyNoMoreInteractions();
}

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

@Test
public void testOnErrorFromNotificationHandler() {
  Subscriber<String> subscriber = TestHelper.mockSubscriber();
  Flowable<String> origin = Flowable.unsafeCreate(new FuncWithErrors(2));
  origin.retryWhen(new Function<Flowable<? extends Throwable>, Flowable<Object>>() {
    @Override
    public Flowable<Object> apply(Flowable<? extends Throwable> t1) {
      return Flowable.error(new RuntimeException());
    }
  }).subscribe(subscriber);
  InOrder inOrder = inOrder(subscriber);
  inOrder.verify(subscriber).onSubscribe((Subscription)notNull());
  inOrder.verify(subscriber, never()).onNext("beginningEveryTime");
  inOrder.verify(subscriber, never()).onNext("onSuccessOnly");
  inOrder.verify(subscriber, never()).onComplete();
  inOrder.verify(subscriber, times(1)).onError(any(RuntimeException.class));
  inOrder.verifyNoMoreInteractions();
}

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

@Test
  public void testUnsubscribeAfterTake() {
    TestFlowableFunc f = new TestFlowableFunc("one", "two", "three");
    Flowable<String> w = Flowable.unsafeCreate(f);

    Subscriber<String> subscriber = TestHelper.mockSubscriber();

    Flowable<String> take = w.take(1);
    take.subscribe(subscriber);

    // wait for the Flowable to complete
    try {
      f.t.join();
    } catch (Throwable e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    System.out.println("TestFlowable thread finished");
    verify(subscriber).onSubscribe((Subscription)notNull());
    verify(subscriber, times(1)).onNext("one");
    verify(subscriber, never()).onNext("two");
    verify(subscriber, never()).onNext("three");
    verify(subscriber, times(1)).onComplete();
    // FIXME no longer assertable
//        verify(s, times(1)).unsubscribe();
    verifyNoMoreInteractions(subscriber);
  }

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

@Test
  public void testUnsubscribeAfterTake() {
    TestObservableFunc f = new TestObservableFunc("one", "two", "three");
    Observable<String> w = Observable.unsafeCreate(f);

    Observer<String> observer = TestHelper.mockObserver();

    Observable<String> take = w.take(1);
    take.subscribe(observer);

    // wait for the Observable to complete
    try {
      f.t.join();
    } catch (Throwable e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    System.out.println("TestObservable thread finished");
    verify(observer).onSubscribe((Disposable)notNull());
    verify(observer, times(1)).onNext("one");
    verify(observer, never()).onNext("two");
    verify(observer, never()).onNext("three");
    verify(observer, times(1)).onComplete();
    // FIXME no longer assertable
//        verify(s, times(1)).unsubscribe();
    verifyNoMoreInteractions(observer);
  }

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

@Test
public void testCompletedAfterError() {
  ReplayProcessor<String> processor = ReplayProcessor.create();
  Subscriber<String> subscriber = TestHelper.mockSubscriber();
  processor.onNext("one");
  processor.onError(testException);
  processor.onNext("two");
  processor.onComplete();
  processor.onError(new RuntimeException());
  processor.subscribe(subscriber);
  verify(subscriber).onSubscribe((Subscription)notNull());
  verify(subscriber, times(1)).onNext("one");
  verify(subscriber, times(1)).onError(testException);
  verifyNoMoreInteractions(subscriber);
}

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

@Test
public void testOnCompletedFromNotificationHandler() {
  Observer<String> observer = TestHelper.mockObserver();
  Observable<String> origin = Observable.unsafeCreate(new FuncWithErrors(1));
  TestObserver<String> to = new TestObserver<String>(observer);
  origin.retryWhen(new Function<Observable<? extends Throwable>, Observable<?>>() {
    @Override
    public Observable<?> apply(Observable<? extends Throwable> t1) {
      return Observable.empty();
    }
  }).subscribe(to);
  InOrder inOrder = inOrder(observer);
  inOrder.verify(observer).onSubscribe((Disposable)notNull());
  inOrder.verify(observer, never()).onNext("beginningEveryTime");
  inOrder.verify(observer, never()).onNext("onSuccessOnly");
  inOrder.verify(observer, times(1)).onComplete();
  inOrder.verify(observer, never()).onError(any(Exception.class));
  inOrder.verifyNoMoreInteractions();
}

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

@Test
public void testOnCompletedFromNotificationHandler() {
  Subscriber<String> subscriber = TestHelper.mockSubscriber();
  Flowable<String> origin = Flowable.unsafeCreate(new FuncWithErrors(1));
  TestSubscriber<String> ts = new TestSubscriber<String>(subscriber);
  origin.retryWhen(new Function<Flowable<? extends Throwable>, Flowable<Object>>() {
    @Override
    public Flowable<Object> apply(Flowable<? extends Throwable> t1) {
      return Flowable.empty();
    }
  }).subscribe(ts);
  InOrder inOrder = inOrder(subscriber);
  inOrder.verify(subscriber).onSubscribe((Subscription)notNull());
  inOrder.verify(subscriber, never()).onNext("beginningEveryTime");
  inOrder.verify(subscriber, never()).onNext("onSuccessOnly");
  inOrder.verify(subscriber, times(1)).onComplete();
  inOrder.verify(subscriber, never()).onError(any(Exception.class));
  inOrder.verifyNoMoreInteractions();
}

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

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void receiptNotReceived() {
  TaskScheduler taskScheduler = mock(TaskScheduler.class);
  this.session.afterConnected(this.connection);
  this.session.setTaskScheduler(taskScheduler);
  AtomicReference<Boolean> notReceived = new AtomicReference<>();
  ScheduledFuture future = mock(ScheduledFuture.class);
  when(taskScheduler.schedule(any(Runnable.class), any(Date.class))).thenReturn(future);
  StompHeaders headers = new StompHeaders();
  headers.setDestination("/topic/foo");
  headers.setReceipt("my-receipt");
  Receiptable receiptable = this.session.send(headers, "payload");
  receiptable.addReceiptLostTask(() -> notReceived.set(true));
  ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class);
  verify(taskScheduler).schedule(taskCaptor.capture(), (Date) notNull());
  Runnable scheduledTask = taskCaptor.getValue();
  assertNotNull(scheduledTask);
  assertNull(notReceived.get());
  scheduledTask.run();
  assertTrue(notReceived.get());
  verify(future).cancel(true);
  verifyNoMoreInteractions(future);
}

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

@Test
public void testCompletedAfterError() {
  ReplaySubject<String> subject = ReplaySubject.create();
  Observer<String> observer = TestHelper.mockObserver();
  subject.onNext("one");
  subject.onError(testException);
  subject.onNext("two");
  subject.onComplete();
  subject.onError(new RuntimeException());
  subject.subscribe(observer);
  verify(observer).onSubscribe((Disposable)notNull());
  verify(observer, times(1)).onNext("one");
  verify(observer, times(1)).onError(testException);
  verifyNoMoreInteractions(observer);
}

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

@Test
public void testTakeDoesntLeakErrors() {
  List<Throwable> errors = TestHelper.trackPluginErrors();
  try {
    Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {
      @Override
      public void subscribe(Subscriber<? super String> subscriber) {
        subscriber.onSubscribe(new BooleanSubscription());
        subscriber.onNext("one");
        subscriber.onError(new Throwable("test failed"));
      }
    });
    Subscriber<String> subscriber = TestHelper.mockSubscriber();
    source.take(1).subscribe(subscriber);
    verify(subscriber).onSubscribe((Subscription)notNull());
    verify(subscriber, times(1)).onNext("one");
    // even though onError is called we take(1) so shouldn't see it
    verify(subscriber, never()).onError(any(Throwable.class));
    verify(subscriber, times(1)).onComplete();
    verifyNoMoreInteractions(subscriber);
    TestHelper.assertUndeliverable(errors, 0, Throwable.class, "test failed");
  } finally {
    RxJavaPlugins.reset();
  }
}

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

verify(sourceCompleted, times(1)).run();
verify(mockScheduler, times(1)).createWorker();
verify(spiedWorker, times(1)).schedule((Runnable)notNull());
verifyObserverMock(mockObserverBeforeConnect, 2, 6);
verifyObserverMock(mockObserverAfterConnect, 2, 6);

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

verify(spiedWorker, times(1)).schedule((Runnable)notNull());
verify(sourceNext, times(1)).accept(1);
verify(sourceError, times(1)).accept(illegalArgumentException);

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

inOrderD.verify(observerD).onComplete();
verify(observerA).onSubscribe((Subscription)notNull());
verify(observerB).onSubscribe((Subscription)notNull());
verify(observerC).onSubscribe((Subscription)notNull());
verify(observerD).onSubscribe((Subscription)notNull());
Mockito.verifyNoMoreInteractions(observerA);
Mockito.verifyNoMoreInteractions(observerB);

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

inOrderD.verify(observerD).onComplete();
verify(observerA).onSubscribe((Disposable)notNull());
verify(observerB).onSubscribe((Disposable)notNull());
verify(observerC).onSubscribe((Disposable)notNull());
verify(observerD).onSubscribe((Disposable)notNull());
Mockito.verifyNoMoreInteractions(observerA);
Mockito.verifyNoMoreInteractions(observerB);

相关文章