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

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

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

Mockito.eq介绍

暂无

代码示例

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

@Test
public void partial() throws Exception {
  XMLInputFactory inputFactory = XMLInputFactory.newInstance();
  XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT));
  eventReader.nextTag();  // skip to root
  StaxEventXMLReader xmlReader = new StaxEventXMLReader(eventReader);
  ContentHandler contentHandler = mock(ContentHandler.class);
  xmlReader.setContentHandler(contentHandler);
  xmlReader.parse(new InputSource());
  verify(contentHandler).startDocument();
  verify(contentHandler).startElement(eq("http://springframework.org/spring-ws"), eq("child"), eq("child"), any(Attributes.class));
  verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child");
  verify(contentHandler).endDocument();
}

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

@Test
@SuppressWarnings({"rawtypes", "unchecked"})
public void cancelInactivityTasks() throws Exception {
  TcpConnection<byte[]> tcpConnection = getTcpConnection();
  ScheduledFuture future = mock(ScheduledFuture.class);
  when(this.taskScheduler.scheduleWithFixedDelay(any(), eq(1L))).thenReturn(future);
  tcpConnection.onReadInactivity(mock(Runnable.class), 2L);
  tcpConnection.onWriteInactivity(mock(Runnable.class), 2L);
  this.webSocketHandlerCaptor.getValue().afterConnectionClosed(this.webSocketSession, CloseStatus.NORMAL);
  verify(future, times(2)).cancel(true);
  verifyNoMoreInteractions(future);
}

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

@Test
public void importSelectors() {
  DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
  context.register(Config.class);
  context.refresh();
  context.getBean(Config.class);
  InOrder ordered = inOrder(beanFactory);
  ordered.verify(beanFactory).registerBeanDefinition(eq("a"), any());
  ordered.verify(beanFactory).registerBeanDefinition(eq("b"), any());
  ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any());
  ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
}

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

@Test
  public void setRuntimeContext() throws Exception {
    RuntimeContext mockRuntimeContext = Mockito.mock(RuntimeContext.class);

    // Make sure setRuntimeContext of the rich output format is called
    RichOutputFormat<?> mockRichOutputFormat = Mockito.mock(RichOutputFormat.class);
    new OutputFormatSinkFunction<>(mockRichOutputFormat).setRuntimeContext(mockRuntimeContext);
    Mockito.verify(mockRichOutputFormat, Mockito.times(1)).setRuntimeContext(Mockito.eq(mockRuntimeContext));

    // Make sure setRuntimeContext work well when output format is not RichOutputFormat
    OutputFormat<?> mockOutputFormat = Mockito.mock(OutputFormat.class);
    new OutputFormatSinkFunction<>(mockOutputFormat).setRuntimeContext(mockRuntimeContext);
  }
}

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

public void testAdd_firstFewWithSuccess() {
 final int COUNT = 400;
 when(backingMap.get(KEY)).thenReturn(null);
 when(backingMap.putIfAbsent(eq(KEY), isA(AtomicInteger.class))).thenReturn(null);
 assertEquals(0, multiset.add(KEY, COUNT));
}

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

private void testInactivityTaskScheduling(Runnable runnable, long delay, long sleepTime)
    throws InterruptedException {
  ArgumentCaptor<Runnable> inactivityTaskCaptor = ArgumentCaptor.forClass(Runnable.class);
  verify(this.taskScheduler).scheduleWithFixedDelay(inactivityTaskCaptor.capture(), eq(delay/2));
  verifyNoMoreInteractions(this.taskScheduler);
  if (sleepTime > 0) {
    Thread.sleep(sleepTime);
  }
  Runnable inactivityTask = inactivityTaskCaptor.getValue();
  assertNotNull(inactivityTask);
  inactivityTask.run();
  if (sleepTime > 0) {
    verify(runnable).run();
  }
  else {
    verifyNoMoreInteractions(runnable);
  }
}

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

private Runnable getUserRegistryTask() {
  BrokerAvailabilityEvent event = new BrokerAvailabilityEvent(true, this);
  this.handler.onApplicationEvent(event);
  ArgumentCaptor<? extends Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
  verify(this.taskScheduler).scheduleWithFixedDelay(captor.capture(), eq(10000L));
  return captor.getValue();
}

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

@Test
public void shouldRetryUponUploadFailure() throws IOException {
  String data = "Some text whose checksum can be asserted";
  final String md5 = CachedDigestUtils.md5Hex(data);
  FileUtils.writeStringToFile(tempFile, data, UTF_8);
  Properties properties = new Properties();
  properties.setProperty("dest/path/file.txt", md5);
  when(httpService.upload(eq("http://baseurl/artifacts/dest/path?attempt=1&buildId=build42"), eq(tempFile.length()), any(File.class), eq(properties))).thenReturn(HttpServletResponse.SC_BAD_GATEWAY);
  when(httpService.upload(eq("http://baseurl/artifacts/dest/path?attempt=2&buildId=build42"), eq(tempFile.length()), any(File.class), eq(properties))).thenReturn(HttpServletResponse.SC_BAD_GATEWAY);
  when(httpService.upload(eq("http://baseurl/artifacts/dest/path?attempt=3&buildId=build42"), eq(tempFile.length()), any(File.class), eq(properties))).thenReturn(HttpServletResponse.SC_OK);
  artifactsRepository.upload(console, tempFile, "dest/path", "build42");
}

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

@Test
public void partial() throws Exception {
  XMLInputFactory inputFactory = XMLInputFactory.newInstance();
  XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(CONTENT));
  streamReader.nextTag();  // skip to root
  assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "root"),
      streamReader.getName());
  streamReader.nextTag();  // skip to child
  assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "child"),
      streamReader.getName());
  StaxStreamXMLReader xmlReader = new StaxStreamXMLReader(streamReader);
  ContentHandler contentHandler = mock(ContentHandler.class);
  xmlReader.setContentHandler(contentHandler);
  xmlReader.parse(new InputSource());
  verify(contentHandler).setDocumentLocator(any(Locator.class));
  verify(contentHandler).startDocument();
  verify(contentHandler).startElement(eq("http://springframework.org/spring-ws"), eq("child"), eq("child"), any(Attributes.class));
  verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child");
  verify(contentHandler).endDocument();
}

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

@Test
public void importSelectorsWithGroup() {
  DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
  context.register(GroupedConfig.class);
  context.refresh();
  InOrder ordered = inOrder(beanFactory);
  ordered.verify(beanFactory).registerBeanDefinition(eq("a"), any());
  ordered.verify(beanFactory).registerBeanDefinition(eq("b"), any());
  ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
  ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any());
  assertThat(TestImportGroup.instancesCount.get(), equalTo(1));
  assertThat(TestImportGroup.imports.size(), equalTo(1));
  assertThat(TestImportGroup.imports.values().iterator().next().size(), equalTo(2));
}

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

@Test
public void readWriteIntervalCalculation() throws Exception {
  this.messageHandler.setHeartbeatValue(new long[] {1, 1});
  this.messageHandler.setTaskScheduler(this.taskScheduler);
  this.messageHandler.start();
  ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class);
  verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L));
  Runnable heartbeatTask = taskCaptor.getValue();
  assertNotNull(heartbeatTask);
  String id = "sess1";
  TestPrincipal user = new TestPrincipal("joe");
  Message<String> connectMessage = createConnectMessage(id, user, new long[] {10000, 10000});
  this.messageHandler.handleMessage(connectMessage);
  Thread.sleep(10);
  heartbeatTask.run();
  verify(this.clientOutChannel, times(1)).send(this.messageCaptor.capture());
  List<Message<?>> messages = this.messageCaptor.getAllValues();
  assertEquals(1, messages.size());
  assertEquals(SimpMessageType.CONNECT_ACK,
      messages.get(0).getHeaders().get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER));
}

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

@SuppressWarnings("unchecked")
@Test
public void startAndStopWithHeartbeatValue() {
  ScheduledFuture future = mock(ScheduledFuture.class);
  when(this.taskScheduler.scheduleWithFixedDelay(any(Runnable.class), eq(15000L))).thenReturn(future);
  this.messageHandler.setTaskScheduler(this.taskScheduler);
  this.messageHandler.setHeartbeatValue(new long[] {15000, 16000});
  this.messageHandler.start();
  verify(this.taskScheduler).scheduleWithFixedDelay(any(Runnable.class), eq(15000L));
  verifyNoMoreInteractions(this.taskScheduler, future);
  this.messageHandler.stop();
  verify(future).cancel(true);
  verifyNoMoreInteractions(future);
}

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

@Test
public void testHookSubscribeStart() throws Exception {
  TestSubscriber<String> ts = new TestSubscriber<String>();
  Completable completable = Completable.unsafeCreate(new CompletableSource() {
    @Override public void subscribe(CompletableObserver observer) {
      observer.onComplete();
    }
  });
  completable.<String>toFlowable().subscribe(ts);
  verify(onStart, times(1)).apply(eq(completable), any(CompletableObserver.class));
}

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

@Test
public void importSelectorsSeparateWithGroup() {
  DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
  context.register(GroupedConfig1.class);
  context.register(GroupedConfig2.class);
  context.refresh();
  InOrder ordered = inOrder(beanFactory);
  ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
  ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any());
  assertThat(TestImportGroup.instancesCount.get(), equalTo(1));
  assertThat(TestImportGroup.imports.size(), equalTo(2));
  Iterator<AnnotationMetadata> iterator = TestImportGroup.imports.keySet().iterator();
  assertThat(iterator.next().getClassName(), equalTo(GroupedConfig2.class.getName()));
  assertThat(iterator.next().getClassName(), equalTo(GroupedConfig1.class.getName()));
}

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

@Test
public void writeInactivity() throws Exception {
  this.messageHandler.setHeartbeatValue(new long[] {1, 0});
  this.messageHandler.setTaskScheduler(this.taskScheduler);
  this.messageHandler.start();
  ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class);
  verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L));
  Runnable heartbeatTask = taskCaptor.getValue();
  assertNotNull(heartbeatTask);
  String id = "sess1";
  TestPrincipal user = new TestPrincipal("joe");
  Message<String> connectMessage = createConnectMessage(id, user, new long[] {0, 1});
  this.messageHandler.handleMessage(connectMessage);
  Thread.sleep(10);
  heartbeatTask.run();
  verify(this.clientOutChannel, times(2)).send(this.messageCaptor.capture());
  List<Message<?>> messages = this.messageCaptor.getAllValues();
  assertEquals(2, messages.size());
  MessageHeaders headers = messages.get(0).getHeaders();
  assertEquals(SimpMessageType.CONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER));
  headers = messages.get(1).getHeaders();
  assertEquals(SimpMessageType.HEARTBEAT, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER));
  assertEquals(id, headers.get(SimpMessageHeaderAccessor.SESSION_ID_HEADER));
  assertEquals(user, headers.get(SimpMessageHeaderAccessor.USER_HEADER));
}

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

@Test
public void uploadShouldBeGivenFileSize() throws IOException {
  when(httpService.upload(any(String.class), eq(tempFile.length()), any(File.class), any(Properties.class))).thenReturn(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
  try {
    artifactsRepository.upload(console, tempFile, "dest", "build42");
    fail("should have thrown request entity too large error");
  } catch (RuntimeException e) {
    verify(httpService).upload(eq("http://baseurl/artifacts/dest?attempt=1&buildId=build42"), eq(tempFile.length()), any(File.class), any(Properties.class));
  }
}

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

@SuppressWarnings("unchecked")
@Test
public void startWithOneZeroHeartbeatValue() {
  this.messageHandler.setTaskScheduler(this.taskScheduler);
  this.messageHandler.setHeartbeatValue(new long[] {0, 10000});
  this.messageHandler.start();
  verify(this.taskScheduler).scheduleWithFixedDelay(any(Runnable.class), eq(10000L));
}

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

@Test
public void importSelectorsWithNestedGroup() {
  DefaultListableBeanFactory beanFactory = spy(new DefaultListableBeanFactory());
  AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(beanFactory);
  context.register(ParentConfiguration1.class);
  context.refresh();
  InOrder ordered = inOrder(beanFactory);
  ordered.verify(beanFactory).registerBeanDefinition(eq("a"), any());
  ordered.verify(beanFactory).registerBeanDefinition(eq("e"), any());
  ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
  assertThat(TestImportGroup.instancesCount.get(), equalTo(2));
   assertThat(TestImportGroup.imports.size(), equalTo(2));
  assertThat(TestImportGroup.allImports(), hasEntry(
      is(ParentConfiguration1.class.getName()),
      IsIterableContainingInOrder.contains(DeferredImportSelector1.class.getName(),
          ChildConfiguration1.class.getName())));
  assertThat(TestImportGroup.allImports(), hasEntry(
      is(ChildConfiguration1.class.getName()),
      IsIterableContainingInOrder.contains(DeferredImportedSelector3.class.getName())));
}

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

@Test
public void readInactivity() throws Exception {
  this.messageHandler.setHeartbeatValue(new long[] {0, 1});
  this.messageHandler.setTaskScheduler(this.taskScheduler);
  this.messageHandler.start();
  ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class);
  verify(this.taskScheduler).scheduleWithFixedDelay(taskCaptor.capture(), eq(1L));
  Runnable heartbeatTask = taskCaptor.getValue();
  assertNotNull(heartbeatTask);
  String id = "sess1";
  TestPrincipal user = new TestPrincipal("joe");
  Message<String> connectMessage = createConnectMessage(id, user, new long[] {1, 0});
  this.messageHandler.handleMessage(connectMessage);
  Thread.sleep(10);
  heartbeatTask.run();
  verify(this.clientOutChannel, atLeast(2)).send(this.messageCaptor.capture());
  List<Message<?>> messages = this.messageCaptor.getAllValues();
  assertEquals(2, messages.size());
  MessageHeaders headers = messages.get(0).getHeaders();
  assertEquals(SimpMessageType.CONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER));
  headers = messages.get(1).getHeaders();
  assertEquals(SimpMessageType.DISCONNECT_ACK, headers.get(SimpMessageHeaderAccessor.MESSAGE_TYPE_HEADER));
  assertEquals(id, headers.get(SimpMessageHeaderAccessor.SESSION_ID_HEADER));
  assertEquals(user, headers.get(SimpMessageHeaderAccessor.USER_HEADER));
}

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

@Test
public void shouldUploadArtifactChecksumWithRightPathWhenArtifactDestinationPathIsEmpty() throws IOException {
  String data = "Some text whose checksum can be asserted";
  final String md5 = CachedDigestUtils.md5Hex(data);
  FileUtils.writeStringToFile(tempFile, data, UTF_8);
  Properties properties = new Properties();
  properties.setProperty("file.txt", md5);
  when(httpService.upload(eq("http://baseurl/artifacts/?attempt=1&buildId=build42"), eq(tempFile.length()), any(File.class), eq(properties))).thenReturn(HttpServletResponse.SC_OK);
  artifactsRepository.upload(console, tempFile, "", "build42");
}

相关文章

微信公众号

最新文章

更多