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

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

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

Mockito.atLeastOnce介绍

[英]Allows at-least-once verification. E.g:

verify(mock, atLeastOnce()).someMethod("some arg");

Alias to atLeast(1).

See examples in javadoc for Mockito class
[中]允许至少进行一次验证。例如:

verify(mock, atLeastOnce()).someMethod("some arg");

化名为atLeast(1)
有关Mockito类,请参见javadoc中的示例

代码示例

代码示例来源:origin: bumptech/glide

@Test
public void testWaitsForGivenTimeoutMillisIfTimeoutSet() throws InterruptedException {
 long timeout = 2;
 try {
  future.get(timeout, TimeUnit.MILLISECONDS);
 } catch (InterruptedException | ExecutionException e) {
  throw new RuntimeException(e);
 } catch (TimeoutException e) {
  // Expected.
 }
 verify(waiter, atLeastOnce()).waitForTimeout(eq(future), eq(timeout));
}

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

/**
 * see #testTruncateNotCalledIfSizeIsSameAsTargetSize
 */
@Test
public void testTruncateIfSizeIsDifferentToTargetSize() throws IOException {
  FileChannel channelMock = mock(FileChannel.class);
  when(channelMock.size()).thenReturn(42L);
  when(channelMock.truncate(anyLong())).thenReturn(channelMock);
  FileRecords fileRecords = new FileRecords(tempFile(), channelMock, 0, Integer.MAX_VALUE, false);
  fileRecords.truncateTo(23);
  verify(channelMock, atLeastOnce()).size();
  verify(channelMock).truncate(23);
}

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

private String getHostFromClient() throws Exception {
  ArgumentCaptor<InetAddress> addrCaptor = ArgumentCaptor.forClass( InetAddress.class );
  verify( ftpClient, atLeastOnce() ).setRemoteAddr( addrCaptor.capture() );
  return addrCaptor.getValue().getHostName();
 }
}

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

@Test
public void testResetNextBatchExpiry() throws Exception {
  client = spy(new MockClient(time, metadata));
  setupWithTransactionState(null);
  accumulator.append(tp0, 0L, "key".getBytes(), "value".getBytes(), null, null,
      MAX_BLOCK_TIMEOUT);
  sender.run(time.milliseconds());
  sender.run(time.milliseconds());
  time.setCurrentTimeMs(time.milliseconds() + accumulator.getDeliveryTimeoutMs() + 1);
  sender.run(time.milliseconds());
  InOrder inOrder = inOrder(client);
  inOrder.verify(client, atLeastOnce()).ready(any(), anyLong());
  inOrder.verify(client, atLeastOnce()).newClientRequest(anyString(), any(), anyLong(), anyBoolean(), anyInt(),
      any());
  inOrder.verify(client, atLeastOnce()).send(any(), anyLong());
  inOrder.verify(client).poll(eq(0L), anyLong());
  inOrder.verify(client).poll(eq(accumulator.getDeliveryTimeoutMs()), anyLong());
  inOrder.verify(client).poll(geq(1L), anyLong());
}

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

when(mockAssigner.assignWindows(anyInt(), anyLong(), anyAssignerContext()))
    .thenReturn(Arrays.asList(new TimeWindow(0, 100)));
timeAdaptor.verifyTriggerCallback(mockTrigger, atLeastOnce(), 1L, new TimeWindow(0, 100));
timeAdaptor.verifyTriggerCallback(mockTrigger, times(1), null, null);
assertEquals(3, timeAdaptor.numTimers(testHarness)); // +1 because of the GC timer of the window
timeAdaptor.verifyTriggerCallback(mockTrigger, atLeastOnce(), 17L, new TimeWindow(0, 100));
timeAdaptor.verifyTriggerCallback(mockTrigger, atLeastOnce(), 42L, new TimeWindow(0, 100));
timeAdaptor.verifyTriggerCallback(mockTrigger, times(3), null, null);
assertEquals(1, timeAdaptor.numTimers(testHarness)); // +1 because of the GC timer of the window

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

/**
 * Test that truncateTo only calls truncate on the FileChannel if the size of the
 * FileChannel is bigger than the target size. This is important because some JVMs
 * change the mtime of the file, even if truncate should do nothing.
 */
@Test
public void testTruncateNotCalledIfSizeIsSameAsTargetSize() throws IOException {
  FileChannel channelMock = mock(FileChannel.class);
  when(channelMock.size()).thenReturn(42L);
  when(channelMock.position(42L)).thenReturn(null);
  FileRecords fileRecords = new FileRecords(tempFile(), channelMock, 0, Integer.MAX_VALUE, false);
  fileRecords.truncateTo(42);
  verify(channelMock, atLeastOnce()).size();
  verify(channelMock, times(0)).truncate(anyLong());
}

代码示例来源:origin: bumptech/glide

@Test
public void testConvertsOtherTimeUnitsToMillisForWaiter() throws InterruptedException {
 long timeoutMicros = 1000;
 try {
  future.get(timeoutMicros, TimeUnit.MICROSECONDS);
 } catch (InterruptedException | ExecutionException e) {
  throw new RuntimeException(e);
 } catch (TimeoutException e) {
  // Expected.
 }
 verify(waiter, atLeastOnce())
   .waitForTimeout(eq(future), eq(TimeUnit.MICROSECONDS.toMillis(timeoutMicros)));
}

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

private void assertAllNamingEnumerationsClosed(MockResultCollection resultCollection) throws NamingException {
 for (NamingEnumeration<SearchResult> namingEnumeration : resultCollection) {
  verify(namingEnumeration, atLeastOnce()).close();
 }
}

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

@Test
public void shouldUnloadAPlugin() throws BundleException {
  GoPluginDescriptor pluginDescriptor = mock(GoPluginDescriptor.class);
  when(pluginDescriptor.bundle()).thenReturn(bundle);
  spy.unloadPlugin(pluginDescriptor);
  verify(bundle, atLeastOnce()).stop();
  verify(bundle, atLeastOnce()).uninstall();
}

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

@Test
public void testClose() throws NamingException {
 search = new LdapSearch(conf, ctx);
 search.close();
 verify(ctx, atLeastOnce()).close();
}

代码示例来源:origin: SonarSource/sonarqube

private void assertChangeOfCreationDateTo(long createdAt) {
  verify(issueUpdater, atLeastOnce())
   .setCreationDate(same(issue), eq(new Date(createdAt)), any());
 }
}

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

@Test
public void testReadFullyIfEofIsReached() throws IOException {
  final FileChannel channelMock = mock(FileChannel.class);
  final int bufferSize = 100;
  final String fileChannelContent = "abcdefghkl";
  ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
  when(channelMock.read(any(), anyLong())).then(invocation -> {
    ByteBuffer bufferArg = invocation.getArgument(0);
    bufferArg.put(fileChannelContent.getBytes());
    return -1;
  });
  Utils.readFully(channelMock, buffer, 0L);
  assertEquals("abcdefghkl", new String(buffer.array(), 0, buffer.position()));
  assertEquals(fileChannelContent.length(), buffer.position());
  assertTrue(buffer.hasRemaining());
  verify(channelMock, atLeastOnce()).read(any(), anyLong());
}

代码示例来源:origin: k9mail/k-9

@Test()
public void clearFolderSynchronous_shouldListFolders() throws MessagingException {
  controller.clearFolderSynchronous(account, FOLDER_NAME, listener);
  verify(listener, atLeastOnce()).listFoldersStarted(account);
}

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

private void seekAndAssert(long seekPos) throws IOException {
  Assert.assertEquals(verifyInputStream.getPos(), testInputStream.getPos());
  long delta = seekPos - testInputStream.getPos();
  testInputStream.seek(seekPos);
  if (delta > 0L && delta <= HadoopDataInputStream.MIN_SKIP_BYTES) {
    verify(verifyInputStream, atLeastOnce()).skip(anyLong());
    verify(verifyInputStream, never()).seek(anyLong());
  } else if (delta != 0L) {
    verify(verifyInputStream, atLeastOnce()).seek(seekPos);
    verify(verifyInputStream, never()).skip(anyLong());
  } else {
    verify(verifyInputStream, never()).seek(anyLong());
    verify(verifyInputStream, never()).skip(anyLong());
  }
  Assert.assertEquals(seekPos, verifyInputStream.getPos());
  reset(verifyInputStream);
}

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

/**
 * Expect a KafkaException if targetSize is bigger than the size of
 * the FileRecords.
 */
@Test
public void testTruncateNotCalledIfSizeIsBiggerThanTargetSize() throws IOException {
  FileChannel channelMock = mock(FileChannel.class);
  when(channelMock.size()).thenReturn(42L);
  FileRecords fileRecords = new FileRecords(tempFile(), channelMock, 0, Integer.MAX_VALUE, false);
  try {
    fileRecords.truncateTo(43);
    fail("Should throw KafkaException");
  } catch (KafkaException e) {
    // expected
  }
  verify(channelMock, atLeastOnce()).size();
}

代码示例来源:origin: k9mail/k-9

@Test
public void clearFolderSynchronous_shouldCloseTheFolder() throws MessagingException {
  controller.clearFolderSynchronous(account, FOLDER_NAME, listener);
  verify(localFolder, atLeastOnce()).close();
}

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

private void authenticateUserAndCheckSearchIsClosed(String user) throws IOException {
  auth = new LdapAuthenticationProviderImpl(conf, factory);
  try {
   auth.Authenticate(user, "password doesn't matter");
  } finally {
   verify(search, atLeastOnce()).close();
  }
 }
}

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

/**
 * Tests that `readFullyOrFail` behaves correctly if multiple `FileChannel.read` operations are required to fill
 * the destination buffer.
 */
@Test
public void testReadFullyOrFailWithPartialFileChannelReads() throws IOException {
  FileChannel channelMock = mock(FileChannel.class);
  final int bufferSize = 100;
  ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
  String expectedBufferContent = fileChannelMockExpectReadWithRandomBytes(channelMock, bufferSize);
  Utils.readFullyOrFail(channelMock, buffer, 0L, "test");
  assertEquals("The buffer should be populated correctly", expectedBufferContent,
      new String(buffer.array()));
  assertFalse("The buffer should be filled", buffer.hasRemaining());
  verify(channelMock, atLeastOnce()).read(any(), anyLong());
}

代码示例来源:origin: google/ExoPlayer

@Test
public void testAttachPlayer_setsAdUiViewGroup() {
 setupPlayback(CONTENT_TIMELINE, PREROLL_ADS_DURATIONS_US, PREROLL_CUE_POINTS_SECONDS);
 imaAdsLoader.attachPlayer(fakeExoPlayer, adsLoaderListener, adUiViewGroup);
 verify(adDisplayContainer, atLeastOnce()).setAdContainer(adUiViewGroup);
}

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

/**
 * Tests that `readFullyOrFail` behaves correctly if multiple `FileChannel.read` operations are required to fill
 * the destination buffer.
 */
@Test
public void testReadFullyWithPartialFileChannelReads() throws IOException {
  FileChannel channelMock = mock(FileChannel.class);
  final int bufferSize = 100;
  String expectedBufferContent = fileChannelMockExpectReadWithRandomBytes(channelMock, bufferSize);
  ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
  Utils.readFully(channelMock, buffer, 0L);
  assertEquals("The buffer should be populated correctly.", expectedBufferContent,
      new String(buffer.array()));
  assertFalse("The buffer should be filled", buffer.hasRemaining());
  verify(channelMock, atLeastOnce()).read(any(), anyLong());
}

相关文章

微信公众号

最新文章

更多