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

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

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

Mockito.anyString介绍

暂无

代码示例

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

@Test
public void testFirstOrElseOfSome() {
  Observable<String> src = Observable.just("a", "b", "c");
  src.first("default").subscribe(wo);
  verify(wo, times(1)).onSuccess(anyString());
  verify(wo, times(1)).onSuccess("a");
  verify(wo, never()).onError(any(Throwable.class));
}

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

@Test
@Ignore("Null values no longer allowed")
public void testDistinctOfSourceWithExceptionsFromKeySelector() {
  Observable<String> src = Observable.just("a", "b", null, "c");
  src.distinct(TO_UPPER_WITH_EXCEPTION).subscribe(w);
  InOrder inOrder = inOrder(w);
  inOrder.verify(w, times(1)).onNext("a");
  inOrder.verify(w, times(1)).onNext("b");
  inOrder.verify(w, times(1)).onError(any(NullPointerException.class));
  inOrder.verify(w, never()).onNext(anyString());
  inOrder.verify(w, never()).onComplete();
}

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

@Test
public void testConcat() {
  Observer<String> observer = TestHelper.mockObserver();
  final String[] o = { "1", "3", "5", "7" };
  final String[] e = { "2", "4", "6" };
  final Observable<String> odds = Observable.fromArray(o);
  final Observable<String> even = Observable.fromArray(e);
  Observable<String> concat = Observable.concat(odds, even);
  concat.subscribe(observer);
  verify(observer, times(7)).onNext(anyString());
}

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

@Test
public void testFindUserDnWhenUserDnPositive() throws NamingException {
 NamingEnumeration<SearchResult> searchResult = mockNamingEnumeration("CN=User1,OU=org1,DC=foo,DC=bar");
 when(ctx.search(anyString(), anyString(), any(SearchControls.class)))
   .thenReturn(searchResult)
   .thenThrow(NamingException.class);
 search = new LdapSearch(conf, ctx);
 String expected = "CN=User1,OU=org1,DC=foo,DC=bar";
 String actual = search.findUserDn("CN=User1,OU=org1");
 assertEquals(expected, actual);
}

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

@Test
public void shouldGetPlainTextValue() throws CryptoException {
  GoCipher mockGoCipher = mock(GoCipher.class);
  String plainText = "password";
  EnvironmentVariableConfig environmentVariableConfig = new EnvironmentVariableConfig(mockGoCipher);
  HashMap attrs = getAttributeMap(plainText, "false", "1");
  environmentVariableConfig.setConfigAttributes(attrs);
  assertThat(environmentVariableConfig.getValue(), is(plainText));
  verify(mockGoCipher, never()).decrypt(anyString());
  verify(mockGoCipher, never()).encrypt(anyString());
}

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

@Test
//PDI-16258
public void testShowHidden() throws KettleException {
 IUser user = Mockito.mock( IUser.class );
 Mockito.when( user.isAdmin() ).thenReturn( true );
 Mockito.when( repoExtended.getUserInfo() ).thenReturn( user );
 init( repoExtended, "/", false, ".*", "", All, 0 );
 Mockito.verify( repoExtended, Mockito.never() )
  .loadRepositoryDirectoryTree( Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.eq( false ),
   Mockito.anyBoolean(), anyBoolean() );
 Mockito.when( user.isAdmin() ).thenReturn( false );
 init( repoExtended, "/", false, ".*", "", All, 0 );
 Mockito.verify( repoExtended )
  .loadRepositoryDirectoryTree( Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.eq( false ),
   Mockito.anyBoolean(), Mockito.anyBoolean() );
}

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

/**
 * PDI-10762 - Trans and TransMeta leak
 */
@Test
public void testLoggingObjectIsNotLeakInTrans() throws KettleException {
 Repository rep = Mockito.mock( Repository.class );
 RepositoryDirectoryInterface repInt = Mockito.mock( RepositoryDirectoryInterface.class );
 Mockito.when(
  rep.loadTransformation( Mockito.anyString(), Mockito.any( RepositoryDirectoryInterface.class ), Mockito
   .any( ProgressMonitorListener.class ), Mockito.anyBoolean(), Mockito.anyString() ) ).thenReturn( meta );
 Mockito.when( rep.findDirectory( Mockito.anyString() ) ).thenReturn( repInt );
 Trans trans = new Trans( meta, rep, "junit", "junitDir", "fileName" );
 assertEquals( "Log channel General assigned", LogChannel.GENERAL.getLogChannelId(), trans.log
  .getLogChannelId() );
}

代码示例来源:origin: kaaproject/kaa

@Test
public void testOnServerError() throws Exception {
 AbstractHttpClient client = Mockito.mock(AbstractHttpClient.class);
 RawDataProcessor processor = Mockito.mock(RawDataProcessor.class);
 Map<TransportType, ChannelDirection> transportTypes = new HashMap<>();
 IpTransportInfo serverInfo = Mockito.mock(IpTransportInfo.class);
 Mockito.when(client.executeHttpRequest(Mockito.anyString(), Mockito.any(LinkedHashMap.class), Mockito.anyBoolean())).thenThrow(new Exception());
 PollCommand command = new PollCommand(client, processor, transportTypes, serverInfo);
 command.execute();
 Mockito.verify(processor, Mockito.times(1)).onServerError(serverInfo);
}

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

@Test
public void shouldReportAClassLoadErrorToThePluginHealthService() throws Exception {
  setupClassesInBundle("SomeClass.class");
  when(bundle.loadClass(anyString())).thenThrow(new ClassNotFoundException("Ouch! Failed"));
  activator.start(context);
  verifyErrorsReported("Class [SomeClass] could not be loaded. Message: [Ouch! Failed].", NO_EXT_ERR_MSG);
}

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

@Before
public void before()
{
  when(mockAeron.conductorAgentInvoker()).thenReturn(mock(AgentInvoker.class));
  when(mockEgressPublisher.sendEvent(any(), anyLong(), anyInt(), any(), any())).thenReturn(TRUE);
  when(mockLogPublisher.appendSessionClose(any(), anyLong(), anyLong())).thenReturn(TRUE);
  when(mockLogPublisher.appendSessionOpen(any(), anyLong(), anyLong())).thenReturn(128L);
  when(mockLogPublisher.appendClusterAction(anyLong(), anyLong(), anyLong(), any(ClusterAction.class)))
    .thenReturn(TRUE);
  when(mockAeron.addPublication(anyString(), anyInt())).thenReturn(mockResponsePublication);
  when(mockAeron.addSubscription(anyString(), anyInt())).thenReturn(mock(Subscription.class));
  when(mockAeron.addSubscription(anyString(), anyInt(), eq(null), any(UnavailableImageHandler.class)))
    .thenReturn(mock(Subscription.class));
  when(mockResponsePublication.isConnected()).thenReturn(TRUE);
}

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

private void setUpWindowedProcessorBolt(Processor<?> processor, Window<?, ?> window) {
  ProcessorNode node = new ProcessorNode(processor, "outputstream", new Fields("value"));
  node.setWindowed(true);
  Mockito.when(mockStreamToProcessors.get(Mockito.anyString())).thenReturn(Collections.singletonList(node));
  Mockito.when(mockStreamToProcessors.keySet()).thenReturn(Collections.singleton("inputstream"));
  graph = new DefaultDirectedGraph<>(new StreamsEdgeFactory());
  graph.addVertex(node);
  bolt = new WindowedProcessorBolt("bolt1", graph, Collections.singletonList(node), window);
  bolt.setStreamToInitialProcessors(mockStreamToProcessors);
  bolt.prepare(new HashMap<>(), mockTopologyContext, mockOutputCollector);
}

代码示例来源: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/hive

@Test
public void testFindUserDnWhenUserPatternFoundByUniqueIdentifierNegativeNone() throws NamingException {
 conf.setVar(HiveConf.ConfVars.HIVE_SERVER2_PLAIN_LDAP_USERDNPATTERN,
   "CN=%s,OU=org1,DC=foo,DC=bar");
 when(ctx.search(anyString(), anyString(), any(SearchControls.class)))
   .thenReturn(null)
   .thenReturn(null);
 search = new LdapSearch(conf, ctx);
 assertNull(search.findUserDn("User1"));
}

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

@Test
public void testFirstOrElseWithPredicateOfNoneMatchingThePredicate() {
  Observable<String> src = Observable.just("a", "b", "c");
  src.filter(IS_D).first("default").subscribe(wo);
  verify(wo, times(1)).onSuccess(anyString());
  verify(wo, times(1)).onSuccess("default");
  verify(wo, never()).onError(any(Throwable.class));
}

代码示例来源:origin: reactor/reactor-core

@Test
public void monoLogWithGivenLogger() {
  Level level = Level.WARNING;
  Mono<String> source = Mono.just("foo");
  Logger mockLogger = Mockito.mock(Logger.class);
  source.log(mockLogger, level, false, SignalType.ON_NEXT)
     .subscribe();
  verify(mockLogger, only()).warn(anyString(), eq(SignalType.ON_NEXT),
      eq("foo"));
  verifyNoMoreInteractions(mockLogger);
}

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

@Test
public void testNeverCompleted() {
  AsyncProcessor<String> processor = AsyncProcessor.create();
  Subscriber<String> subscriber = TestHelper.mockSubscriber();
  processor.subscribe(subscriber);
  processor.onNext("one");
  processor.onNext("two");
  processor.onNext("three");
  verify(subscriber, Mockito.never()).onNext(anyString());
  verify(subscriber, Mockito.never()).onError(testException);
  verify(subscriber, Mockito.never()).onComplete();
}

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

@Test
public void shouldReportMultipleClassLoadErrorsToThePluginHealthService() throws Exception {
  setupClassesInBundle("SomeClass.class", "SomeOtherClass.class");
  when(bundle.loadClass(anyString())).thenThrow(new ClassNotFoundException("Ouch! Failed"));
  activator.start(context);
  verifyErrorsReported("Class [SomeClass] could not be loaded. Message: [Ouch! Failed].", "Class [SomeOtherClass] could not be loaded. Message: [Ouch! Failed]."
      , NO_EXT_ERR_MSG);
}

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

@Test
@Ignore("Null values no longer allowed")
public void testDistinctOfSourceWithExceptionsFromKeySelector() {
  Flowable<String> src = Flowable.just("a", "b", null, "c");
  src.distinct(TO_UPPER_WITH_EXCEPTION).subscribe(w);
  InOrder inOrder = inOrder(w);
  inOrder.verify(w, times(1)).onNext("a");
  inOrder.verify(w, times(1)).onNext("b");
  inOrder.verify(w, times(1)).onError(any(NullPointerException.class));
  inOrder.verify(w, never()).onNext(anyString());
  inOrder.verify(w, never()).onComplete();
}

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

private void setUpStatefulProcessorBolt(Processor<?> processor) {
  ProcessorNode node = new ProcessorNode(processor, "outputstream", new Fields("value"));
  node.setEmitsPair(true);
  Mockito.when(mockStreamToProcessors.get(Mockito.anyString())).thenReturn(Collections.singletonList(node));
  graph = new DefaultDirectedGraph(new StreamsEdgeFactory());
  graph.addVertex(node);
  bolt = new StatefulProcessorBolt<>("bolt1", graph, Collections.singletonList(node));
  bolt.setStreamToInitialProcessors(mockStreamToProcessors);
  bolt.prepare(new HashMap<>(), mockTopologyContext, mockOutputCollector);
  bolt.initState(mockKeyValueState);
}

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

@Test
public void shouldIgnoreSettingsChangeNotificationIfPluginDoesNotSupportsNotification() throws Exception {
  String supportedVersion = "1.0";
  Map<String, String> settings = Collections.singletonMap("foo", "bar");
  extension.registerHandler(supportedVersion, new PluginSettingsJsonMessageHandler1_0());
  when(pluginManager.resolveExtensionVersion(pluginId, extensionName, goSupportedVersions)).thenReturn(supportedVersion);
  extension.notifyPluginSettingsChange(pluginId, settings);
  verify(pluginManager, times(0)).submitTo(anyString(), eq(extensionName), any(GoPluginApiRequest.class));
}

相关文章