当前位置: 首页>>代码示例>>Java>>正文


Java OngoingStubbing.thenReturn方法代码示例

本文整理汇总了Java中org.mockito.stubbing.OngoingStubbing.thenReturn方法的典型用法代码示例。如果您正苦于以下问题:Java OngoingStubbing.thenReturn方法的具体用法?Java OngoingStubbing.thenReturn怎么用?Java OngoingStubbing.thenReturn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mockito.stubbing.OngoingStubbing的用法示例。


在下文中一共展示了OngoingStubbing.thenReturn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mockedConnectionsForClient

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
private List<Connection> mockedConnectionsForClient(Client client, int numConnections) throws IOException {
    final ConnectionFactory mockFactory = mock(ConnectionFactory.class);
    final OngoingStubbing<Connection> newConnectionStub = when(mockFactory.newConnection());
    List<Connection> conns = new ArrayList<Connection>(numConnections);
    // TODO OMG this is ugly. there's got to be a better way.
    OngoingStubbing<Connection> connectionOngoingStubbing = null;
    for (int i = 0; i < numConnections; i++) {
        final Connection mockConnection = mock(Connection.class);
        if (i == 0) {
            connectionOngoingStubbing = newConnectionStub.thenReturn(mockConnection);
        } else {
            connectionOngoingStubbing.thenReturn(mockConnection);
        }
        final Channel mockChannel = mock(Channel.class);
        when(mockConnection.createChannel()).thenReturn(mockChannel);
        conns.add(mockConnection);
    }
    client.setConnectionFactory(mockFactory);
    return conns;
}
 
开发者ID:xing,项目名称:java-beetle,代码行数:21,代码来源:ClientTest.java

示例2: mockBucketResponses

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
private void mockBucketResponses(final int count, final TagValue... tagValues) {
    when(element.getName()).thenReturn(
        new QName("", IdolParametricValuesServiceImpl.VALUES_NODE_NAME),
        new QName("", IdolParametricValuesServiceImpl.VALUE_NODE_NAME)
    );

    OngoingStubbing<Serializable> stub = when(element.getValue()).thenReturn(count);

    for(final TagValue tagValue : tagValues) {
        stub = stub.thenReturn(tagValue);
    }

    final GetQueryTagValuesResponseData responseData = new GetQueryTagValuesResponseData();
    final FlatField field2 = new FlatField();
    field2.getName().add("ParametricNumericDateField");
    field2.getValueAndSubvalueOrValues().add(element);
    for(final TagValue ignored : tagValues) {
        field2.getValueAndSubvalueOrValues().add(element);
    }
    responseData.getField().add(field2);

    when(queryExecutor.executeGetQueryTagValues(any(AciParameters.class), any())).thenReturn(responseData);
}
 
开发者ID:hpe-idol,项目名称:haven-search-components,代码行数:24,代码来源:IdolParametricValuesServiceTest.java

示例3: createMockLibrary

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
public static AndroidLibrary createMockLibrary(String allResources, String publicResources,
        List<AndroidLibrary> dependencies)
        throws IOException {
    final File tempDir = TestUtils.createTempDirDeletedOnExit();

    Files.write(allResources, new File(tempDir, FN_RESOURCE_TEXT), Charsets.UTF_8);
    File publicTxtFile = new File(tempDir, FN_PUBLIC_TXT);
    if (publicResources != null) {
        Files.write(publicResources, publicTxtFile, Charsets.UTF_8);
    }
    AndroidLibrary library = mock(AndroidLibrary.class);
    when(library.getPublicResources()).thenReturn(publicTxtFile);

    // Work around wildcard capture
    //when(mock.getLibraryDependencies()).thenReturn(dependencies);
    List libraryDependencies = library.getLibraryDependencies();
    OngoingStubbing<List> setter = when(libraryDependencies);
    setter.thenReturn(dependencies);
    return library;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PrivateResourceDetectorTest.java

示例4: testExtractor

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
@Test
public void testExtractor() throws Exception {
  // setup
  Schema schema = new Schema("testExtractor");
  schema.addColumn(new Text("TextCol"));
  ExtractorContext context = new ExtractorContext(null, writerMock, schema);
  LinkConfiguration linkConfig = new LinkConfiguration();
  FromJobConfiguration jobConfig = new FromJobConfiguration();
  KiteDatasetPartition partition = new KiteDatasetPartition();
  partition.setUri("dataset:hdfs:/path/to/dataset");
  OngoingStubbing<Object[]> readRecordMethodStub = when(executorMock.readRecord());
  final int NUMBER_OF_ROWS = 1000;
  for (int i = 0; i < NUMBER_OF_ROWS; i++) {
    // TODO: SQOOP-1616 will cover more column data types
    readRecordMethodStub = readRecordMethodStub.thenReturn(new Object[]{});
  }
  readRecordMethodStub.thenReturn(null);

  // exercise
  extractor.extract(context, linkConfig, jobConfig, partition);

  // verify
  verify(writerMock, times(NUMBER_OF_ROWS)).writeArrayRecord(
      any(Object[].class));
}
 
开发者ID:vybs,项目名称:sqoop-on-spark,代码行数:26,代码来源:TestKiteExtractor.java

示例5: getAllPrBuildsCommonExpectations

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
private void getAllPrBuildsCommonExpectations(int size) {
    when(job.getBuilds()).thenReturn(builds);
    when(builds.size()).thenReturn(size);
    when(job.getParent()).thenReturn(itemGroup);
    when(itemGroup.getFullName()).thenReturn("JobName");

    when(builds.iterator()).thenReturn(iterator);

    OngoingStubbing<Boolean> hasNextExpectation = size >= 1 ?
            when(iterator.hasNext()).thenReturn(true) : when(iterator.hasNext()).thenReturn(false);
    for (int i = 1; i < size; i++) {
        hasNextExpectation.thenReturn(true);
    }
    hasNextExpectation.thenReturn(false);

    OngoingStubbing<Object> nextExpectation = when(iterator.next()).thenReturn(run);
    for (int i = 1; i < size; i++) {
        nextExpectation.thenReturn(run);
    }
}
 
开发者ID:KostyaSha,项目名称:github-integration-plugin,代码行数:21,代码来源:GitHubPRRepositoryTest.java

示例6: second_stubbing_throws_IndexOutOfBoundsException

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
@Test
public void second_stubbing_throws_IndexOutOfBoundsException() throws Exception {
    Map<String, String> map = mock(Map.class);

    OngoingStubbing<String> mapOngoingStubbing = when(map.get(anyString()));

    mapOngoingStubbing.thenReturn("first stubbing");

    try {
        mapOngoingStubbing.thenReturn("second stubbing");
        fail();
    } catch (MockitoException e) {
        assertThat(e.getMessage())
                .contains("Incorrect use of API detected here")
                .contains(this.getClass().getSimpleName());
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:IOOBExceptionShouldNotBeThrownWhenNotCodingFluentlyTest.java

示例7: shouldPollUntilQueueEmpty_onPoll

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
@Test
public void shouldPollUntilQueueEmpty_onPoll() {
    // Given
    when(mockTransactionalResourceManager.inTransaction()).thenReturn(false);
    final int messageCount = randomInt(5) + 1;
    final InMemoryMessageListener<TypedMessage> mockMemoryMessageListener = mock(InMemoryMessageListener.class);
    poller.register(mockMemoryMessageListener);

    // pollForMessage() should return true for messageCount times
    OngoingStubbing<Boolean> ongoingStubbing = when(mockMemoryMessageListener.receiveAndHandleMessages());
    for (int n = 0; n < messageCount; n++) {
        ongoingStubbing = ongoingStubbing.thenReturn(true);
    }
    ongoingStubbing.thenReturn(false);

    // When
    poller.poll();

    // Then
    verify(mockMemoryMessageListener, times(messageCount + 1)).receiveAndHandleMessages();
}
 
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:22,代码来源:DefaultInMemoryMessageQueuePollerTest.java

示例8: mockContentProviderForTermLists

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
/**
 * Mock a content provider that returns for the first call to
 * {@link SemanticContentProvider#getRelevantContent(SoftwareElement, boolean)} the first list
 * of provided terms, and for the second call the second list.
 *
 * @param terms1
 *            The terms to return for the first call.
 * @param terms2
 *            The terms to return for the second call.
 * @return The prepared mock.
 * @throws UnsupportedSoftwareElementException
 */
private SemanticContentProvider mockContentProviderForTermLists(List<List<String>> termLists)
        throws UnsupportedSoftwareElementException {

    SemanticContentProvider provider = mock(SemanticContentProvider.class);
    OngoingStubbing<SemanticContent> mockStub = when(provider.getRelevantContent(any(SoftwareElement.class),
            anyBoolean()));

    for (List<String> terms : termLists) {
        SemanticContent semantic = new SemanticContent();
        for (String term : terms) {
            semantic.addCode(term);
        }
        mockStub = mockStub.thenReturn(semantic);
    }

    return provider;
}
 
开发者ID:kopl,项目名称:SPLevo,代码行数:30,代码来源:SharedTermSemanticAnalysisTest.java

示例9: createRandom

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
private Random createRandom(int... values) {
    Random random = mock(Random.class);
    
    OngoingStubbing<Integer> ongoingStubbing = when(random.nextInt(36));
    for (int value : values) {
        ongoingStubbing = ongoingStubbing.thenReturn(value);
    }
    
    return random;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:11,代码来源:BoundaryGeneratorTest.java

示例10: configureHttpResponses

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
private void configureHttpResponses(HttpResponse... responses) throws IOException {
    requestCaptor = ArgumentCaptor.forClass(HttpGeneric.class);
    OngoingStubbing<HttpResponse> stubbing =
            when(mockHttpClient.executeOverride(requestCaptor.capture(), any(HttpContext.class)));

    for (HttpResponse response : responses) {
        stubbing = stubbing.thenReturn(response);
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:10,代码来源:WebDavStoreTest.java

示例11: returnOrThrow

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
public OngoingStubbing<byte[]> returnOrThrow(OngoingStubbing<byte[]> setup)
{
    if (_exception != null)
        return setup.thenThrow(_exception);
    else
        return setup.thenReturn(_response);
}
 
开发者ID:timerickson,项目名称:lastpass-java,代码行数:8,代码来源:FetcherTest.java

示例12: mockFiles

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
public static void mockFiles(URL ... urls) throws Exception {
  List<File> files = Arrays.stream(urls)
      .map(URL::getPath)
      .map(File::new)
      .collect(Collectors.toList());
  FileChooser chooser = Mockito.mock(FileChooser.class);
  OngoingStubbing<File> stub = Mockito.when(chooser.showOpenDialog(any()));
  for (File file : files) {
    stub = stub.thenReturn(file);
  }
  Mockito.when(chooser.getExtensionFilters()).thenReturn(FXCollections.observableList(new ArrayList<>()));
  PowerMockito.whenNew(FileChooser.class).withAnyArguments().thenReturn(chooser);
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:14,代码来源:TestUtils.java

示例13: letMovingAverageReturn

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
private void letMovingAverageReturn(final Indicator<Price, FullMarketData<M1>> movingAverage,
        final long... values) {
    OngoingStubbing<Optional<Price>> toStub = when(movingAverage.indicate(any()));
    for (final long value : values) {
        if (value == EMPTY) {
            toStub = toStub.thenReturn(Optional.empty());
        } else {
            toStub = toStub.thenReturn(Optional.of(new Price(value)));
        }
    }
}
 
开发者ID:rbi,项目名称:trading4j,代码行数:12,代码来源:NMovingAveragesExpertAdvisorTest.java

示例14: testReplayBlocksObservable

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
@Test
public void testReplayBlocksObservable() throws Exception {

    List<EthBlock> ethBlocks = Arrays.asList(createBlock(0), createBlock(1), createBlock(2));

    OngoingStubbing<EthBlock> stubbing =
            when(web3jService.send(any(Request.class), eq(EthBlock.class)));
    for (EthBlock ethBlock : ethBlocks) {
        stubbing = stubbing.thenReturn(ethBlock);
    }

    Observable<EthBlock> observable = web3j.replayBlocksObservable(
            new DefaultBlockParameterNumber(BigInteger.ZERO),
            new DefaultBlockParameterNumber(BigInteger.valueOf(2)),
            false);

    CountDownLatch transactionLatch = new CountDownLatch(ethBlocks.size());
    CountDownLatch completedLatch = new CountDownLatch(1);

    List<EthBlock> results = new ArrayList<>(ethBlocks.size());
    Subscription subscription = observable.subscribe(
            result -> {
                results.add(result);
                transactionLatch.countDown();
            },
            throwable -> fail(throwable.getMessage()),
            () -> completedLatch.countDown());

    transactionLatch.await(1, TimeUnit.SECONDS);
    assertThat(results, equalTo(ethBlocks));

    subscription.unsubscribe();

    completedLatch.await(1, TimeUnit.SECONDS);
    assertTrue(subscription.isUnsubscribed());
}
 
开发者ID:web3j,项目名称:web3j,代码行数:37,代码来源:JsonRpc2_0RxTest.java

示例15: testReplayBlocksDescendingObservable

import org.mockito.stubbing.OngoingStubbing; //导入方法依赖的package包/类
@Test
public void testReplayBlocksDescendingObservable() throws Exception {

    List<EthBlock> ethBlocks = Arrays.asList(createBlock(2), createBlock(1), createBlock(0));

    OngoingStubbing<EthBlock> stubbing =
            when(web3jService.send(any(Request.class), eq(EthBlock.class)));
    for (EthBlock ethBlock : ethBlocks) {
        stubbing = stubbing.thenReturn(ethBlock);
    }

    Observable<EthBlock> observable = web3j.replayBlocksObservable(
            new DefaultBlockParameterNumber(BigInteger.ZERO),
            new DefaultBlockParameterNumber(BigInteger.valueOf(2)),
            false, false);

    CountDownLatch transactionLatch = new CountDownLatch(ethBlocks.size());
    CountDownLatch completedLatch = new CountDownLatch(1);

    List<EthBlock> results = new ArrayList<>(ethBlocks.size());
    Subscription subscription = observable.subscribe(
            result -> {
                results.add(result);
                transactionLatch.countDown();
            },
            throwable -> fail(throwable.getMessage()),
            () -> completedLatch.countDown());

    transactionLatch.await(1, TimeUnit.SECONDS);
    assertThat(results, equalTo(ethBlocks));

    subscription.unsubscribe();

    completedLatch.await(1, TimeUnit.SECONDS);
    assertTrue(subscription.isUnsubscribed());
}
 
开发者ID:web3j,项目名称:web3j,代码行数:37,代码来源:JsonRpc2_0RxTest.java


注:本文中的org.mockito.stubbing.OngoingStubbing.thenReturn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。