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


Java OngoingStubbing类代码示例

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


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

示例1: test

import org.mockito.stubbing.OngoingStubbing; //导入依赖的package包/类
@Test
public void test() {
    String pattern = "test\\.test\\..*";

    MetricRegexFilter filter = new MetricRegexFilter(pattern);

    assertEquals(pattern, filter.getPattern());

    OngoingStubbing<String> stub = when(mock(Metric.class).name());

    assertTrue(filter.accept(stub.thenReturn("test.test.1").getMock()));
    assertTrue(filter.accept(stub.thenReturn("test.test.2").getMock()));

    assertFalse(filter.accept(stub.thenReturn("test1").getMock()));
    assertFalse(filter.accept(stub.thenReturn("test1test.2").getMock()));
    assertFalse(filter.accept(stub.thenReturn("invalid").getMock()));
    assertFalse(filter.accept(stub.thenReturn("invalid.test").getMock()));
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:19,代码来源:MetricRegexFilterTest.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: buildMockSheetReader

import org.mockito.stubbing.OngoingStubbing; //导入依赖的package包/类
private SheetReader buildMockSheetReader(LocalDateDoubleTimeSeries lddts) { 
  
  DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
  builder.appendPattern(DATE_FORMAT);
  DateTimeFormatter dateFormat = builder.toFormatter();

  SheetReader mock = mock(SheetReader.class);
  OngoingStubbing<Map<String, String>> stub = when(mock.loadNextRow());
  for (Map.Entry<LocalDate, Double> entry : lddts) {
    Map<String, String> row = new HashMap<String, String>();
    row.put("id", EXISTING_HTSINFO_EXTERNALID.getValue());
    row.put("date", entry.getKey().toString(dateFormat));
    row.put("value", entry.getValue().toString());
    stub = stub.thenReturn(row);
  }
  stub.thenReturn(null);
  return mock;    
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:19,代码来源:TimeSeriesLoaderTest.java

示例5: 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

示例6: withAnyArguments

import org.mockito.stubbing.OngoingStubbing; //导入依赖的package包/类
public OngoingStubbing<T> withAnyArguments() throws Exception {
    if (mockType == null) {
        throw new IllegalArgumentException("Class to expected cannot be null");
    }
    final Class<T> unmockedType = (Class<T>) WhiteboxImpl.getUnmockedType(mockType);
    final Constructor<?>[] allConstructors = WhiteboxImpl.getAllConstructors(unmockedType);
    final Constructor<?> constructor = allConstructors[0];
    final Class<?>[] parameterTypes = constructor.getParameterTypes();
    Object[] paramArgs = new Object[parameterTypes.length];
    for (int i = 0; i < parameterTypes.length; i++) {
        Class<?> paramType = parameterTypes[i];
        paramArgs[i] = Matchers.any(paramType);
    }
    final OngoingStubbing<T> ongoingStubbing = createNewSubstituteMock(mockType, parameterTypes, paramArgs);
    Constructor<?>[] otherCtors = new Constructor<?>[allConstructors.length-1];
    System.arraycopy(allConstructors, 1, otherCtors, 0, allConstructors.length-1);
    return new DelegatingToConstructorsOngoingStubbing<T>(otherCtors, ongoingStubbing);
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:19,代码来源:DefaultConstructorExpectationSetup.java

示例7: invoke

import org.mockito.stubbing.OngoingStubbing; //导入依赖的package包/类
public OngoingStubbing<T> invoke() {
    final InvocationSubstitute<T> mock = stubbing.getMock();
    for (Constructor<?> constructor : ctors) {
        final Class<?>[] parameterTypesForCtor = constructor.getParameterTypes();
        Object[] paramArgs = new Object[parameterTypesForCtor.length];
        for (int i = 0; i < parameterTypesForCtor.length; i++) {
            Class<?> paramType = parameterTypesForCtor[i];
            paramArgs[i] = Matchers.any(paramType);
        }
        try {
            final OngoingStubbing<T> when = when(mock.performSubstitutionLogic(paramArgs));
            performStubbing(when);
        } catch (Exception e) {
            throw new RuntimeException("PowerMock internal error",e);
        }
    }

    return stubbing;
}
 
开发者ID:awenblue,项目名称:powermock,代码行数:20,代码来源:DelegatingToConstructorsOngoingStubbing.java

示例8: whenCreateDatabase

import org.mockito.stubbing.OngoingStubbing; //导入依赖的package包/类
/**
 * wrap when(dbaasStub.createDatabase( ...any parameters... ))
 * @param dbaasStub
 * @return a stub object representing and a call to the createDatabase method with any parameters
 * @throws Exception
 */
public static OngoingStubbing<CreateDatabaseResponseObject> whenCreateDatabase(DbaasApiRemote dbaasStub) throws Exception {
	return when(dbaasStub.createDatabase(
			anyString(), 
			anyString(),
			anyInt(), 
			any(ServiceClassWsEnum.class), 
			any(EngineWsEnum.class), 
			anyString(), 
			anyListOf(DatabaseUserInfo.class),
			any(SloWsEnum.class), 
			anyBoolean(), 
			any(UsageWsEnum.class), 
			anyString(), 
			any(NetworkZoneWsEnum.class), 
			anyString(), 
			anyString(), 
			anyString(), 
			any(BackupPlanWsEnum.class), 
			anyString(), 
			anyBoolean(), 
			anyString()));
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:29,代码来源:DbaasServiceTestUtils.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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