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

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

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

Mockito.anyInt介绍

暂无

代码示例

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

@Test
public void testSkipEverything() {
  Observable<Integer> src = Observable.just(1, 2, 3, 4, 3, 2, 1);
  src.skipWhile(LESS_THAN_FIVE).subscribe(w);
  verify(w, never()).onNext(anyInt());
  verify(w, never()).onError(any(Throwable.class));
  verify(w, times(1)).onComplete();
}

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

@Test
public void testSkipError() {
  Observable<Integer> src = Observable.just(1, 2, 42, 5, 3, 1);
  src.skipWhile(LESS_THAN_FIVE).subscribe(w);
  InOrder inOrder = inOrder(w);
  inOrder.verify(w, never()).onNext(anyInt());
  inOrder.verify(w, never()).onComplete();
  inOrder.verify(w, times(1)).onError(any(RuntimeException.class));
}

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

@Test
public void testCreateInputSplits() throws Exception {
  FileSplit[] result = new FileSplit[1];
  result[0] = getFileSplit();
  DummyInputFormat inputFormat = mock(DummyInputFormat.class);
  when(inputFormat.getSplits(any(JobConf.class), anyInt())).thenReturn(result);
  HadoopInputFormat<String, Long> hadoopInputFormat = new HadoopInputFormat<>(inputFormat, String.class, Long.class, new JobConf());
  hadoopInputFormat.createInputSplits(2);
  verify(inputFormat, times(1)).getSplits(any(JobConf.class), anyInt());
}

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

@SuppressWarnings("unchecked")
@Test
public void testRetrySubscribesAgainAfterError() throws Exception {
  // record emitted values with this action
  Consumer<Integer> record = mock(Consumer.class);
  InOrder inOrder = inOrder(record);
  // always throw an exception with this action
  Consumer<Integer> throwException = mock(Consumer.class);
  doThrow(new RuntimeException()).when(throwException).accept(Mockito.anyInt());
  // create a retrying Observable based on a PublishSubject
  PublishSubject<Integer> subject = PublishSubject.create();
  subject
  // record item
  .doOnNext(record)
  // throw a RuntimeException
      .doOnNext(throwException)
      // retry on error
      .retry()
      // subscribe and ignore
      .subscribe();
  inOrder.verifyNoMoreInteractions();
  subject.onNext(1);
  inOrder.verify(record).accept(1);
  subject.onNext(2);
  inOrder.verify(record).accept(2);
  subject.onNext(3);
  inOrder.verify(record).accept(3);
  inOrder.verifyNoMoreInteractions();
}

代码示例来源:origin: real-logic/aeron

@Before
public void setUp()
{
  header.buffer(termBuffer);
  when(termBuffer.getInt(anyInt(), any(ByteOrder.class))).thenReturn(SESSION_ID);
}

代码示例来源:origin: real-logic/agrona

@Before
public void setUp()
{
  when(mockFactory.apply(anyInt())).thenAnswer(
    (inv) ->
    {
      lastValue = mock(AutoCloseable.class);
      return lastValue;
    });
}

代码示例来源:origin: pentaho/pentaho-kettle

private Database mockDatabase() throws KettleDatabaseException {
 Database databaseMock = mock( Database.class );
 RowMeta databaseRowMeta = new RowMeta();
 databaseRowMeta.addValueMeta( new ValueMetaString( "id" ) );
 databaseRowMeta.addValueMeta( new ValueMetaString( "value" ) );
 doReturn( databaseRowMeta ).when( databaseMock ).getTableFields( anyString() );
 doReturn( databaseRowMeta ).when( databaseMock ).getTableFieldsMeta( anyString(), anyString() );
 doReturn( Arrays.asList( new Object[][] { { "1", "value" } } ) ).when( databaseMock ).getRows( anyString(),
   anyInt() );
 doReturn( databaseRowMeta ).when( databaseMock ).getReturnRowMeta();
 return databaseMock;
}

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

@Override
synchronized StreamingConnection newConnection(UserGroupInformation ugi, boolean tokenAuthEnabled) throws InterruptedException,
  ConnectFailure {
  if (mockedStreamingConn == null) {
    mockedStreamingConn = Mockito.mock(StreamingConnection.class);
    mockedTxBatch = Mockito.mock(TransactionBatch.class);
    try {
      Mockito.when(mockedStreamingConn.fetchTransactionBatch(Mockito.anyInt(), Mockito.any(RecordWriter.class)))
          .thenReturn(mockedTxBatch);
    } catch (StreamingException e) {
      throw new RuntimeException(e);
    }
  }
  return mockedStreamingConn;
}

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

@Test
public void testTakeFirstOfSome() {
  Observable<Integer> o = Observable.just(1, 2, 3);
  o.take(1).subscribe(w);
  verify(w, times(1)).onNext(anyInt());
  verify(w).onNext(1);
  verify(w, times(1)).onComplete();
  verify(w, never()).onError(any(Throwable.class));
}

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

@Test
public void testSkipError() {
  Flowable<Integer> src = Flowable.just(1, 2, 42, 5, 3, 1);
  src.skipWhile(LESS_THAN_FIVE).subscribe(w);
  InOrder inOrder = inOrder(w);
  inOrder.verify(w, never()).onNext(anyInt());
  inOrder.verify(w, never()).onComplete();
  inOrder.verify(w, times(1)).onError(any(RuntimeException.class));
}

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

@SuppressWarnings("unchecked")
@Test
public void testRetrySubscribesAgainAfterError() throws Exception {
  // record emitted values with this action
  Consumer<Integer> record = mock(Consumer.class);
  InOrder inOrder = inOrder(record);
  // always throw an exception with this action
  Consumer<Integer> throwException = mock(Consumer.class);
  doThrow(new RuntimeException()).when(throwException).accept(Mockito.anyInt());
  // create a retrying Flowable based on a PublishProcessor
  PublishProcessor<Integer> processor = PublishProcessor.create();
  processor
  // record item
  .doOnNext(record)
  // throw a RuntimeException
      .doOnNext(throwException)
      // retry on error
      .retry()
      // subscribe and ignore
      .subscribe();
  inOrder.verifyNoMoreInteractions();
  processor.onNext(1);
  inOrder.verify(record).accept(1);
  processor.onNext(2);
  inOrder.verify(record).accept(2);
  processor.onNext(3);
  inOrder.verify(record).accept(3);
  inOrder.verifyNoMoreInteractions();
}

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

private static void setMockLocation(ClusterConnection hc, byte[] row, RegionLocations result)
 throws IOException {
 Mockito.when(hc.locateRegion(Mockito.eq(DUMMY_TABLE), Mockito.eq(row), Mockito.anyBoolean(),
  Mockito.anyBoolean(), Mockito.anyInt())).thenReturn(result);
 Mockito.when(hc.locateRegion(Mockito.eq(DUMMY_TABLE), Mockito.eq(row), Mockito.anyBoolean(),
  Mockito.anyBoolean())).thenReturn(result);
}

代码示例来源:origin: real-logic/aeron

@Test
public void shouldDoNotingIfEndArrivesWithoutBegin()
{
  when(header.flags()).thenReturn(FrameDescriptor.END_FRAG_FLAG);
  final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[1024]);
  final int offset = 0;
  final int length = srcBuffer.capacity() / 2;
  adapter.onFragment(srcBuffer, offset, length, header);
  verify(delegateFragmentHandler, never()).onFragment(any(), anyInt(), anyInt(), any());
}

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

@Test
public void testCountError() {
  Flowable<String> f = Flowable.error(new Callable<Throwable>() {
    @Override
    public Throwable call() {
      return new RuntimeException();
    }
  });
  f.count().subscribe(wo);
  verify(wo, never()).onSuccess(anyInt());
  verify(wo, times(1)).onError(any(RuntimeException.class));
}

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

@Test
public void testDelayedErrorDeliveryWhenSafeSubscriberUnsubscribes() {
  TestScheduler testScheduler = new TestScheduler();
  Observable<Integer> source = Observable.concat(Observable.<Integer> error(new TestException()), Observable.just(1));
  Observer<Integer> o = TestHelper.mockObserver();
  InOrder inOrder = inOrder(o);
  source.observeOn(testScheduler).subscribe(o);
  inOrder.verify(o, never()).onError(any(TestException.class));
  testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  inOrder.verify(o).onError(any(TestException.class));
  inOrder.verify(o, never()).onNext(anyInt());
  inOrder.verify(o, never()).onComplete();
}

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

private static void setMockLocation(ClusterConnection hc, byte[] row,
  RegionLocations result) throws IOException {
 Mockito.when(hc.locateRegion(Mockito.eq(DUMMY_TABLE), Mockito.eq(row),
   Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyInt())).thenReturn(result);
 Mockito.when(hc.locateRegion(Mockito.eq(DUMMY_TABLE), Mockito.eq(row),
   Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(result);
}

代码示例来源:origin: real-logic/aeron

@Before
public void before()
{
  when(aeron.addCounter(anyInt(), anyString())).thenReturn(electionStateCounter);
  when(consensusModuleAgent.logRecordingId()).thenReturn(RECORDING_ID);
  when(consensusModuleAgent.addNewLogPublication()).thenReturn(mock(Publication.class));
  when(clusterMarkFile.candidateTermId()).thenReturn((long)Aeron.NULL_VALUE);
}

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

@Test
public void testCountError() {
  Observable<String> o = Observable.error(new Callable<Throwable>() {
    @Override
    public Throwable call() {
      return new RuntimeException();
    }
  });
  o.count().subscribe(wo);
  verify(wo, never()).onSuccess(anyInt());
  verify(wo, times(1)).onError(any(RuntimeException.class));
}

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

@Test
public void testDelayedErrorDeliveryWhenSafeSubscriberUnsubscribes() {
  TestScheduler testScheduler = new TestScheduler();
  Flowable<Integer> source = Flowable.concat(Flowable.<Integer> error(new TestException()), Flowable.just(1));
  Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
  InOrder inOrder = inOrder(subscriber);
  source.observeOn(testScheduler).subscribe(subscriber);
  inOrder.verify(subscriber, never()).onError(any(TestException.class));
  testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  inOrder.verify(subscriber).onError(any(TestException.class));
  inOrder.verify(subscriber, never()).onNext(anyInt());
  inOrder.verify(subscriber, never()).onComplete();
}

代码示例来源:origin: real-logic/aeron

@Test
  public void shouldDoNotingIfMidArrivesWithoutBegin()
  {
    when(header.flags())
      .thenReturn((byte)0)
      .thenReturn(FrameDescriptor.END_FRAG_FLAG);

    final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[1024]);
    final int offset = 0;
    final int length = srcBuffer.capacity() / 2;

    adapter.onFragment(srcBuffer, offset, length, header);
    adapter.onFragment(srcBuffer, offset, length, header);

    verify(delegateFragmentHandler, never()).onFragment(any(), anyInt(), anyInt(), any());
  }
}

相关文章