org.easymock.EasyMock.same()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(14.8k)|赞(0)|评价(0)|浏览(191)

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

EasyMock.same介绍

[英]Expects an Object that is the same as the given value. For details, see the EasyMock documentation.
[中]需要与给定值相同的对象。有关详细信息,请参阅EasyMock文档。

代码示例

代码示例来源:origin: confluentinc/ksql

@SuppressWarnings("unchecked")
@Test
public void shouldGetMergerForSessionWindowsFromUdafAggregator() {
 EasyMock.expect(groupedStreamMock.windowedBy(EasyMock.capture(sessionWindows))).andReturn(sessionWindowed);
 EasyMock.expect(sessionWindowed.aggregate(same(initializer),
   same(aggregator),
   same(merger),
   same(materialized))).andReturn(null);
 EasyMock.expect(aggregator.getMerger()).andReturn(merger);
 EasyMock.replay(groupedStreamMock, aggregator, sessionWindowed);
 expression.applyAggregate(groupedStreamMock, initializer, aggregator, materialized);
 EasyMock.verify(aggregator);
}

代码示例来源:origin: confluentinc/ksql

@SuppressWarnings("unchecked")
@Test
public void shouldCreateSessionWindowedStreamWithInactiviyGap() {
 EasyMock.expect(groupedStreamMock.windowedBy(EasyMock.capture(sessionWindows))).andReturn(sessionWindowed);
 EasyMock.expect(sessionWindowed.aggregate(same(initializer),
   same(aggregator),
   anyObject(Merger.class),
   same(materialized))).andReturn(null);
 EasyMock.replay(groupedStreamMock, aggregator, sessionWindowed);
 expression.applyAggregate(groupedStreamMock, initializer, aggregator, materialized);
 assertThat(sessionWindows.getValue().inactivityGap(), equalTo(5000L));
 EasyMock.verify(groupedStreamMock);
}

代码示例来源:origin: confluentinc/ksql

@Test
public void shouldCreateTumblingWindowAggregate() {
 final KGroupedStream stream = EasyMock.createNiceMock(KGroupedStream.class);
 final TimeWindowedKStream windowedKStream = EasyMock.createNiceMock(TimeWindowedKStream.class);
 final UdafAggregator aggregator = EasyMock.createNiceMock(UdafAggregator.class);
 final TumblingWindowExpression windowExpression = new TumblingWindowExpression(10, TimeUnit.SECONDS);
 final Initializer initializer = () -> 0;
 final Materialized<String, GenericRow, WindowStore<Bytes, byte[]>> store = Materialized.as("store");
 EasyMock.expect(stream.windowedBy(TimeWindows.of(Duration.ofMillis(10000L)))).andReturn(windowedKStream);
 EasyMock.expect(windowedKStream.aggregate(same(initializer), same(aggregator), same(store))).andReturn(null);
 EasyMock.replay(stream, windowedKStream);
 windowExpression.applyAggregate(stream, initializer, aggregator, store);
 EasyMock.verify(stream, windowedKStream);
}

代码示例来源:origin: confluentinc/ksql

@Test
public void shouldCreateHoppingWindowAggregate() {
 final KGroupedStream stream = EasyMock.createNiceMock(KGroupedStream.class);
 final TimeWindowedKStream windowedKStream = EasyMock.createNiceMock(TimeWindowedKStream.class);
 final UdafAggregator aggregator = EasyMock.createNiceMock(UdafAggregator.class);
 final HoppingWindowExpression windowExpression = new HoppingWindowExpression(10, TimeUnit.SECONDS, 4, TimeUnit.MILLISECONDS);
 final Initializer initializer = () -> 0;
 final Materialized<String, GenericRow, WindowStore<Bytes, byte[]>> store = Materialized.as("store");
 EasyMock.expect(stream.windowedBy(TimeWindows.of(Duration.ofMillis(10000L)).advanceBy(Duration.ofMillis(4L)))).andReturn(windowedKStream);
 EasyMock.expect(windowedKStream.aggregate(same(initializer), same(aggregator), same(store))).andReturn(null);
 EasyMock.replay(stream, windowedKStream);
 windowExpression.applyAggregate(stream, initializer, aggregator, store);
 EasyMock.verify(stream, windowedKStream);
}

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

filter2a.doFilter(same(request), same(response), anyObject(FilterChain.class));
expect((Filter)injector.getInstance(key2b)).andReturn(filter2b);
filter2b.doFilter(same(request), same(response), anyObject(FilterChain.class));
originalChain.doFilter(request, response);

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

@Test
  public void testDoFilter() throws Exception {
    IMocksControl ctrl = createStrictControl();

    FilterChain originalChain = ctrl.createMock(FilterChain.class);
    Filter filter1 = ctrl.createMock("filter1", Filter.class);
    Filter filter2 = ctrl.createMock("filter2", Filter.class);

    ServletRequest request = ctrl.createMock(ServletRequest.class);
    ServletResponse response = ctrl.createMock(ServletResponse.class);

    Capture<FilterChain> fc1 = new Capture<FilterChain>();
    Capture<FilterChain> fc2 = new Capture<FilterChain>();
    filter1.doFilter(same(request), same(response), and(anyObject(FilterChain.class), capture(fc1)));
    filter2.doFilter(same(request), same(response), and(anyObject(FilterChain.class), capture(fc2)));
    originalChain.doFilter(request, response);

    ctrl.replay();

    SimpleFilterChain underTest = new SimpleFilterChain(originalChain, Arrays.asList(filter1, filter2).iterator());

    // all we actually care about is that, if we keep calling the filter chain, everything is called in the right
    // order - we don't care what fc actually contains
    underTest.doFilter(request, response);
    fc1.getValue().doFilter(request, response);
    fc2.getValue().doFilter(request, response);

    ctrl.verify();
  }
}

代码示例来源:origin: apache/httpcomponents-client

private void handleBackendResponseReturnsResponse(final ClassicHttpRequest request, final ClassicHttpResponse response)
    throws IOException {
  expect(
      impl.handleBackendResponse(
          same(host),
          same(request),
          same(scope),
          isA(Date.class),
          isA(Date.class),
          isA(ClassicHttpResponse.class))).andReturn(response);
}

代码示例来源:origin: apache/httpcomponents-client

private IExpectationSetters<ClassicHttpResponse> implExpectsAnyRequestAndReturn(
    final ClassicHttpResponse response) throws Exception {
  final ClassicHttpResponse resp = impl.callBackend(
      same(host),
      isA(ClassicHttpRequest.class),
      isA(ExecChain.Scope.class),
      isA(ExecChain.class));
  return EasyMock.expect(resp).andReturn(response);
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testSmallEnoughResponsesAreCached() throws Exception {
  final HttpHost host = new HttpHost("foo.example.com");
  final ClassicHttpRequest request = new HttpGet("http://foo.example.com/bar");
  final Date now = new Date();
  final Date requestSent = new Date(now.getTime() - 3 * 1000L);
  final Date responseGenerated = new Date(now.getTime() - 2 * 1000L);
  final Date responseReceived = new Date(now.getTime() - 1 * 1000L);
  final ClassicHttpResponse originResponse = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
  originResponse.setEntity(HttpTestUtils.makeBody(CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES - 1));
  originResponse.setHeader("Cache-Control","public, max-age=3600");
  originResponse.setHeader("Date", DateUtils.formatDate(responseGenerated));
  originResponse.setHeader("ETag", "\"etag\"");
  final HttpCacheEntry httpCacheEntry = HttpTestUtils.makeCacheEntry();
  final SimpleHttpResponse response = SimpleHttpResponse.create(HttpStatus.SC_OK);
  EasyMock.expect(mockCache.createCacheEntry(
      eq(host),
      same(request),
      same(originResponse),
      isA(ByteArrayBuffer.class),
      eq(requestSent),
      eq(responseReceived))).andReturn(httpCacheEntry).once();
  EasyMock.expect(mockResponseGenerator.generateResponse(
      same(request),
      same(httpCacheEntry))).andReturn(response).once();
  replayMocks();
  final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, mockEndpoint, context);
  impl.cacheAndReturnResponse(host, request, originResponse, scope, requestSent, responseReceived);
  verifyMocks();
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testRevalidationCallsHandleBackEndResponseWhenNot200Or304() throws Exception {
  mockImplMethods(GET_CURRENT_DATE, HANDLE_BACKEND_RESPONSE);
  final ClassicHttpRequest validate = new BasicClassicHttpRequest("GET", "/");
  final ClassicHttpResponse originResponse = new BasicClassicHttpResponse(HttpStatus.SC_NOT_FOUND, "Not Found");
  final ClassicHttpResponse finalResponse =  HttpTestUtils.make200Response();
  conditionalRequestBuilderReturns(validate);
  getCurrentDateReturns(requestDate);
  backendExpectsRequestAndReturn(validate, originResponse);
  getCurrentDateReturns(responseDate);
  expect(impl.handleBackendResponse(
      same(host),
      same(validate),
      same(scope),
      eq(requestDate),
      eq(responseDate),
      same(originResponse))).andReturn(finalResponse);
  replayMocks();
  final HttpResponse result =
    impl.revalidateCacheEntry(host, request, scope, mockExecChain, entry);
  verifyMocks();
  Assert.assertSame(finalResponse, result);
}

代码示例来源:origin: apache/httpcomponents-client

@Test
public void testRevalidationUpdatesCacheEntryAndPutsItToCacheWhen304ReturningCachedResponse()
    throws Exception {
  mockImplMethods(GET_CURRENT_DATE);
  final ClassicHttpRequest validate = new BasicClassicHttpRequest("GET", "/");
  final ClassicHttpResponse originResponse = HttpTestUtils.make304Response();
  final HttpCacheEntry updatedEntry = HttpTestUtils.makeCacheEntry();
  conditionalRequestBuilderReturns(validate);
  getCurrentDateReturns(requestDate);
  backendExpectsRequestAndReturn(validate, originResponse);
  getCurrentDateReturns(responseDate);
  expect(mockCache.updateCacheEntry(
      eq(host),
      same(request),
      same(entry),
      same(originResponse),
      eq(requestDate),
      eq(responseDate)))
    .andReturn(updatedEntry);
  expect(mockSuitabilityChecker.isConditional(request)).andReturn(false);
  responseIsGeneratedFromCache(SimpleHttpResponse.create(HttpStatus.SC_OK));
  replayMocks();
  impl.revalidateCacheEntry(host, request, scope, mockExecChain, entry);
  verifyMocks();
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-gadgets

@Test
public void conditionIsTrue() throws Exception {
 Document doc = documentProvider.createDocument(null, null, null);
 // Create a mock tag;  the name doesn't truly matter
 Element tag = doc.createElement("if");
 tag.setAttribute(IfTagHandler.CONDITION_ATTR, "fakeExpression");
 processor.expressionResults = ImmutableMap.of("fakeExpression", true);
 processor.processChildNodes((Node) isNull(), same(tag));
 replay(processor);
 handler.process(null, tag, processor);
 verify(processor);
}

代码示例来源:origin: com.lmco.shindig/shindig-gadgets

@Test
public void conditionIsTrue() throws Exception {
 Document doc = documentProvider.createDocument(null, null, null);
 // Create a mock tag;  the name doesn't truly matter
 Element tag = doc.createElement("if");
 tag.setAttribute(IfTagHandler.CONDITION_ATTR, "fakeExpression");
 
 processor.expressionResults = ImmutableMap.of("fakeExpression", true);
 processor.processChildNodes((Node) isNull(), same(tag));
 
 replay(processor);
 handler.process(null, tag, processor);
 verify(processor);
}

代码示例来源:origin: org.apache.shindig/shindig-gadgets

@Test
public void conditionIsTrue() throws Exception {
 Document doc = documentProvider.createDocument(null, null, null);
 // Create a mock tag;  the name doesn't truly matter
 Element tag = doc.createElement("if");
 tag.setAttribute(IfTagHandler.CONDITION_ATTR, "fakeExpression");
 processor.expressionResults = ImmutableMap.of("fakeExpression", true);
 processor.processChildNodes((Node) isNull(), same(tag));
 replay(processor);
 handler.process(null, tag, processor);
 verify(processor);
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-gadgets

@Test
public void executeWithBlockedBatch() throws Exception {
 PipelinedData pipeline = getPipelinedData(BLOCKED_FIRST_BATCH_CONTENT);
 // Expect a batch with no content
 expect(
   preloader.createPreloadTasks(same(context), eqBatch(0, 0)))
     .andReturn(ImmutableList.<Callable<PreloadedData>>of());
 control.replay();
 PipelineExecutor.Results results = executor.execute(context,
   ImmutableList.of(pipeline));
 assertEquals(0, results.results.size());
 assertTrue(results.keyedResults.isEmpty());
 assertEquals(1, results.remainingPipelines.size());
 assertSame(pipeline, results.remainingPipelines.iterator().next());
 control.verify();
}

代码示例来源:origin: org.apache.shindig/shindig-gadgets

@Test
public void executeWithBlockedBatch() throws Exception {
 PipelinedData pipeline = getPipelinedData(BLOCKED_FIRST_BATCH_CONTENT);
 // Expect a batch with no content
 expect(
   preloader.createPreloadTasks(same(context), eqBatch(0, 0)))
     .andReturn(ImmutableList.<Callable<PreloadedData>>of());
 control.replay();
 PipelineExecutor.Results results = executor.execute(context,
   ImmutableList.of(pipeline));
 assertEquals(0, results.results.size());
 assertTrue(results.keyedResults.isEmpty());
 assertEquals(1, results.remainingPipelines.size());
 assertSame(pipeline, results.remainingPipelines.iterator().next());
 control.verify();
}

代码示例来源:origin: com.lmco.shindig/shindig-gadgets

@Test
public void executeWithBlockedBatch() throws Exception {
 PipelinedData pipeline = getPipelinedData(BLOCKED_FIRST_BATCH_CONTENT);
 // Expect a batch with no content
 expect(
   preloader.createPreloadTasks(same(context), eqBatch(0, 0)))
     .andReturn(ImmutableList.<Callable<PreloadedData>>of());
 control.replay();
 PipelineExecutor.Results results = executor.execute(context,
   ImmutableList.of(pipeline));
 assertEquals(0, results.results.size());
 assertTrue(results.keyedResults.isEmpty());
 assertEquals(1, results.remainingPipelines.size());
 assertSame(pipeline, results.remainingPipelines.iterator().next());
 
 control.verify();
}

代码示例来源:origin: org.apache.shindig/shindig-gadgets

@Test
public void rewriteWithBlockedBatch() throws Exception {
 setupGadget(getGadgetXml(BLOCKED_FIRST_BATCH_CONTENT));
 // Expect a batch with no content
 expect(
   preloader.createPreloadTasks(same(gadget.getContext()), eqBatch(0, 0)))
     .andReturn(ImmutableList.<Callable<PreloadedData>>of());
 control.replay();
 rewriter.rewrite(gadget, content);
 control.verify();
 // Check there is no DataContext inserted
 assertFalse("DataContext write shouldn't be present", content.getContent().indexOf(
   "DataContext.putDataSet(") > 0);
 // And the os-data elements should be present
 assertTrue("os-data was deleted",
   content.getContent().indexOf("type=\"text/os-data\"") > 0);
}

代码示例来源:origin: org.wso2.org.apache.shindig/shindig-gadgets

@Test
public void rewriteWithBlockedBatch() throws Exception {
 setupGadget(getGadgetXml(BLOCKED_FIRST_BATCH_CONTENT));
 // Expect a batch with no content
 expect(
   preloader.createPreloadTasks(same(gadget.getContext()), eqBatch(0, 0)))
     .andReturn(ImmutableList.<Callable<PreloadedData>>of());
 control.replay();
 rewriter.rewrite(gadget, content);
 control.verify();
 // Check there is no DataContext inserted
 assertFalse("DataContext write shouldn't be present", content.getContent().indexOf(
   "DataContext.putDataSet(") > 0);
 // And the os-data elements should be present
 assertTrue("os-data was deleted",
   content.getContent().indexOf("type=\"text/os-data\"") > 0);
}

代码示例来源:origin: com.lmco.shindig/shindig-gadgets

@Test
public void rewriteWithBlockedBatch() throws Exception {
 setupGadget(getGadgetXml(BLOCKED_FIRST_BATCH_CONTENT));
 // Expect a batch with no content
 expect(
   preloader.createPreloadTasks(same(gadget.getContext()), eqBatch(0, 0)))
     .andReturn(ImmutableList.<Callable<PreloadedData>>of());
 control.replay();
 rewriter.rewrite(gadget, content);
 
 control.verify();
 // Check there is no DataContext inserted
 assertFalse("DataContext write shouldn't be present", content.getContent().indexOf(
   "DataContext.putDataSet(") > 0);
 // And the os-data elements should be present
 assertTrue("os-data was deleted",
   content.getContent().indexOf("type=\"text/os-data\"") > 0);
}

相关文章