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

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

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

Mockito.anyLong介绍

暂无

代码示例

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

@Test
public void testCountAFewItems() {
  Observable<String> o = Observable.just("a", "b", "c", "d");
  o.count().subscribe(wo);
  // we should be called only once
  verify(wo, times(1)).onSuccess(anyLong());
  verify(wo).onSuccess(4L);
  verify(wo, never()).onError(any(Throwable.class));
}

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

private TransitionalPeriodTransactionMessContainer mockKernel()
{
  TransitionalTxManagementKernelTransaction context = mock( TransitionalTxManagementKernelTransaction.class );
  TransitionalPeriodTransactionMessContainer kernel = mock( TransitionalPeriodTransactionMessContainer.class );
  when( kernel.newTransaction( any( Type.class ), any( LoginContext.class ), anyLong() ) ).thenReturn( context );
  return kernel;
}

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

@Test
public void testCountAFewItemsObservable() {
  Observable<String> o = Observable.just("a", "b", "c", "d");
  o.count().toObservable().subscribe(w);
  // we should be called only once
  verify(w, times(1)).onNext(anyLong());
  verify(w).onNext(4L);
  verify(w, never()).onError(any(Throwable.class));
  verify(w, times(1)).onComplete();
}

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

@Test
public void testCountZeroItems() {
  Observable<String> o = Observable.empty();
  o.count().subscribe(wo);
  // we should be called only once
  verify(wo, times(1)).onSuccess(anyLong());
  verify(wo).onSuccess(0L);
  verify(wo, never()).onError(any(Throwable.class));
}

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

@Test
public void testCountZeroItemsObservable() {
  Observable<String> o = Observable.empty();
  o.count().toObservable().subscribe(w);
  // we should be called only once
  verify(w, times(1)).onNext(anyLong());
  verify(w).onNext(0L);
  verify(w, never()).onError(any(Throwable.class));
  verify(w, times(1)).onComplete();
}

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

@Test
public void testCancelOnce() {
  Disposable r = mock(Disposable.class);
  AsyncSubscription as = new AsyncSubscription(r);
  Subscription s = mock(Subscription.class);
  as.setSubscription(s);
  as.cancel();
  as.cancel();
  as.cancel();
  verify(s, never()).request(anyLong());
  verify(s).cancel();
  verify(r).dispose();
}

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

@Test
public void testDelayWithError() {
  Observable<Long> source = Observable.interval(1L, TimeUnit.SECONDS, scheduler)
  .map(new Function<Long, Long>() {
    @Override
    public Long apply(Long value) {
      if (value == 1L) {
        throw new RuntimeException("error!");
      }
      return value;
    }
  });
  Observable<Long> delayed = source.delay(1L, TimeUnit.SECONDS, scheduler);
  delayed.subscribe(observer);
  InOrder inOrder = inOrder(observer);
  scheduler.advanceTimeTo(1999L, TimeUnit.MILLISECONDS);
  verify(observer, never()).onNext(anyLong());
  verify(observer, never()).onComplete();
  verify(observer, never()).onError(any(Throwable.class));
  scheduler.advanceTimeTo(2000L, TimeUnit.MILLISECONDS);
  inOrder.verify(observer, times(1)).onError(any(Throwable.class));
  inOrder.verify(observer, never()).onNext(anyLong());
  verify(observer, never()).onComplete();
  scheduler.advanceTimeTo(5000L, TimeUnit.MILLISECONDS);
  inOrder.verify(observer, never()).onNext(anyLong());
  inOrder.verify(observer, never()).onError(any(Throwable.class));
  verify(observer, never()).onComplete();
}

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

private TransactionHandle getTransactionHandle( TransitionalPeriodTransactionMessContainer kernel,
    QueryExecutionEngine executionEngine, TransactionRegistry registry )
{
  GraphDatabaseQueryService queryService = mock( GraphDatabaseQueryService.class );
  return new TransactionHandle( kernel, executionEngine, queryService, registry, uriScheme, true, AUTH_DISABLED,
      anyLong(), NullLogProvider.getInstance() );
}

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

@Test
public void testLongDelay() {
  Observable<Long> source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3);
  Observable<Long> delayed = source.delay(5L, TimeUnit.SECONDS, scheduler);
  delayed.subscribe(observer);
  InOrder inOrder = inOrder(observer);
  scheduler.advanceTimeTo(5999L, TimeUnit.MILLISECONDS);
  verify(observer, never()).onNext(anyLong());
  verify(observer, never()).onComplete();
  verify(observer, never()).onError(any(Throwable.class));
  scheduler.advanceTimeTo(6000L, TimeUnit.MILLISECONDS);
  inOrder.verify(observer, times(1)).onNext(0L);
  scheduler.advanceTimeTo(6999L, TimeUnit.MILLISECONDS);
  inOrder.verify(observer, never()).onNext(anyLong());
  scheduler.advanceTimeTo(7000L, TimeUnit.MILLISECONDS);
  inOrder.verify(observer, times(1)).onNext(1L);
  scheduler.advanceTimeTo(7999L, TimeUnit.MILLISECONDS);
  inOrder.verify(observer, never()).onNext(anyLong());
  scheduler.advanceTimeTo(8000L, TimeUnit.MILLISECONDS);
  inOrder.verify(observer, times(1)).onNext(2L);
  inOrder.verify(observer, times(1)).onComplete();
  inOrder.verify(observer, never()).onNext(anyLong());
  inOrder.verify(observer, never()).onComplete();
  verify(observer, never()).onError(any(Throwable.class));
}

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

@Test
public void testLongDelay() {
  Flowable<Long> source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler).take(3);
  Flowable<Long> delayed = source.delay(5L, TimeUnit.SECONDS, scheduler);
  delayed.subscribe(subscriber);
  InOrder inOrder = inOrder(subscriber);
  scheduler.advanceTimeTo(5999L, TimeUnit.MILLISECONDS);
  verify(subscriber, never()).onNext(anyLong());
  verify(subscriber, never()).onComplete();
  verify(subscriber, never()).onError(any(Throwable.class));
  scheduler.advanceTimeTo(6000L, TimeUnit.MILLISECONDS);
  inOrder.verify(subscriber, times(1)).onNext(0L);
  scheduler.advanceTimeTo(6999L, TimeUnit.MILLISECONDS);
  inOrder.verify(subscriber, never()).onNext(anyLong());
  scheduler.advanceTimeTo(7000L, TimeUnit.MILLISECONDS);
  inOrder.verify(subscriber, times(1)).onNext(1L);
  scheduler.advanceTimeTo(7999L, TimeUnit.MILLISECONDS);
  inOrder.verify(subscriber, never()).onNext(anyLong());
  scheduler.advanceTimeTo(8000L, TimeUnit.MILLISECONDS);
  inOrder.verify(subscriber, times(1)).onNext(2L);
  inOrder.verify(subscriber, times(1)).onComplete();
  inOrder.verify(subscriber, never()).onNext(anyLong());
  inOrder.verify(subscriber, never()).onComplete();
  verify(subscriber, never()).onError(any(Throwable.class));
}

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

@Test
public void testWriteRecord() throws Exception {
  OutputFormat<String, Long> dummyOutputFormat = mock(DummyOutputFormat.class);
  DummyRecordWriter recordWriter = mock(DummyRecordWriter.class);
  JobConf jobConf = mock(JobConf.class);
  HadoopOutputFormat<String, Long> outputFormat = new HadoopOutputFormat<>(dummyOutputFormat, jobConf);
  outputFormat.recordWriter = recordWriter;
  outputFormat.writeRecord(new Tuple2<>("key", 1L));
  verify(recordWriter, times(1)).write(anyString(), anyLong());
}

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

verify(subscriber, never()).onNext(anyLong());
verify(subscriber2, never()).onNext(anyLong());
inOrder.verify(subscriber, never()).onNext(anyLong());
inOrder2.verify(subscriber2, never()).onNext(anyLong());
inOrder.verify(subscriber, times(1)).onNext(2L);
inOrder2.verify(subscriber2, times(1)).onNext(2L);
inOrder.verify(subscriber, never()).onNext(anyLong());
inOrder2.verify(subscriber2, never()).onNext(anyLong());
inOrder.verify(subscriber, times(1)).onComplete();
inOrder2.verify(subscriber2, times(1)).onComplete();

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

@Test
  public void setOnceAndRequest() {
    AtomicReference<Subscription> ref = new AtomicReference<Subscription>();

    Subscription sub = mock(Subscription.class);

    assertTrue(SubscriptionHelper.setOnce(ref, sub, 1));

    verify(sub).request(1);
    verify(sub, never()).cancel();

    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
      sub = mock(Subscription.class);

      assertFalse(SubscriptionHelper.setOnce(ref, sub, 1));

      verify(sub, never()).request(anyLong());
      verify(sub).cancel();

      TestHelper.assertError(errors, 0, ProtocolViolationException.class);
    } finally {
      RxJavaPlugins.reset();
    }
  }
}

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

@Test
public void testDelayWithError() {
  Flowable<Long> source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler)
  .map(new Function<Long, Long>() {
    @Override
    public Long apply(Long value) {
      if (value == 1L) {
        throw new RuntimeException("error!");
      }
      return value;
    }
  });
  Flowable<Long> delayed = source.delay(1L, TimeUnit.SECONDS, scheduler);
  delayed.subscribe(subscriber);
  InOrder inOrder = inOrder(subscriber);
  scheduler.advanceTimeTo(1999L, TimeUnit.MILLISECONDS);
  verify(subscriber, never()).onNext(anyLong());
  verify(subscriber, never()).onComplete();
  verify(subscriber, never()).onError(any(Throwable.class));
  scheduler.advanceTimeTo(2000L, TimeUnit.MILLISECONDS);
  inOrder.verify(subscriber, times(1)).onError(any(Throwable.class));
  inOrder.verify(subscriber, never()).onNext(anyLong());
  verify(subscriber, never()).onComplete();
  scheduler.advanceTimeTo(5000L, TimeUnit.MILLISECONDS);
  inOrder.verify(subscriber, never()).onNext(anyLong());
  inOrder.verify(subscriber, never()).onError(any(Throwable.class));
  verify(subscriber, never()).onComplete();
}

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

verify(subscriber, never()).onNext(anyLong());
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
inOrder.verify(subscriber, never()).onNext(anyLong());
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
inOrder.verify(subscriber, never()).onNext(anyLong());
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
inOrder.verify(subscriber, never()).onNext(anyLong());
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
inOrder.verify(subscriber, never()).onNext(anyLong());
verify(subscriber, never()).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));

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

@Test
public void testExecuteTuple() throws Exception {
  Mockito.when(mockWaterMarkEventGenerator.track(Mockito.any(), Mockito.anyLong())).thenReturn(true);
  Tuple mockTuple = Mockito.mock(Tuple.class);
  executor.initState(null);
  executor.waterMarkEventGenerator = mockWaterMarkEventGenerator;
  executor.execute(mockTuple);
  // should be ack-ed once
  Mockito.verify(mockOutputCollector, Mockito.times(1)).ack(mockTuple);
}

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

@Test
public void testOnceObserverThrows() {
  Observable<Long> source = Observable.timer(100, TimeUnit.MILLISECONDS, scheduler);
  source.safeSubscribe(new DefaultObserver<Long>() {
    @Override
    public void onNext(Long t) {
      throw new TestException();
    }
    @Override
    public void onError(Throwable e) {
      observer.onError(e);
    }
    @Override
    public void onComplete() {
      observer.onComplete();
    }
  });
  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  verify(observer).onError(any(TestException.class));
  verify(observer, never()).onNext(anyLong());
  verify(observer, never()).onComplete();
}

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

@Test
public void testOnceObserverThrows() {
  Flowable<Long> source = Flowable.timer(100, TimeUnit.MILLISECONDS, scheduler);
  source.safeSubscribe(new DefaultSubscriber<Long>() {
    @Override
    public void onNext(Long t) {
      throw new TestException();
    }
    @Override
    public void onError(Throwable e) {
      subscriber.onError(e);
    }
    @Override
    public void onComplete() {
      subscriber.onComplete();
    }
  });
  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  verify(subscriber).onError(any(TestException.class));
  verify(subscriber, never()).onNext(anyLong());
  verify(subscriber, never()).onComplete();
}

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

@Test
public void readAsynchronousFileChannelError() throws Exception {
  AsynchronousFileChannel channel = mock(AsynchronousFileChannel.class);
  doAnswer(invocation -> {
    ByteBuffer byteBuffer = invocation.getArgument(0);
    byteBuffer.put("foo".getBytes(StandardCharsets.UTF_8));
    byteBuffer.flip();
    long pos = invocation.getArgument(1);
    assertEquals(0, pos);
    DataBuffer dataBuffer = invocation.getArgument(2);
    CompletionHandler<Integer, DataBuffer> completionHandler = invocation.getArgument(3);
    completionHandler.completed(3, dataBuffer);
    return null;
  }).doAnswer(invocation -> {
    DataBuffer dataBuffer = invocation.getArgument(2);
    CompletionHandler<Integer, DataBuffer> completionHandler = invocation.getArgument(3);
    completionHandler.failed(new IOException(), dataBuffer);
    return null;
  })
  .when(channel).read(any(), anyLong(), any(), any());
  Flux<DataBuffer> result =
      DataBufferUtils.readAsynchronousFileChannel(() -> channel, this.bufferFactory, 3);
  StepVerifier.create(result)
      .consumeNextWith(stringConsumer("foo"))
      .expectError(IOException.class)
      .verify(Duration.ofSeconds(3));
}

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

@Test
public void testFetchNext() throws IOException {
  DummyRecordReader recordReader = mock(DummyRecordReader.class);
  when(recordReader.next(nullable(String.class), nullable(Long.class))).thenReturn(true);
  DummyInputFormat inputFormat = mock(DummyInputFormat.class);
  when(inputFormat.getRecordReader(any(InputSplit.class), any(JobConf.class), any(Reporter.class))).thenReturn(recordReader);
  HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(inputFormat, String.class, Long.class, new JobConf());
  hadoopInputFormat.open(getHadoopInputSplit());
  hadoopInputFormat.fetchNext();
  verify(recordReader, times(1)).next(nullable(String.class), anyLong());
  assertThat(hadoopInputFormat.hasNext, is(true));
  assertThat(hadoopInputFormat.fetched, is(true));
}

相关文章