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

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

本文整理了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

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void shouldGetMergerForSessionWindowsFromUdafAggregator() {
  4. EasyMock.expect(groupedStreamMock.windowedBy(EasyMock.capture(sessionWindows))).andReturn(sessionWindowed);
  5. EasyMock.expect(sessionWindowed.aggregate(same(initializer),
  6. same(aggregator),
  7. same(merger),
  8. same(materialized))).andReturn(null);
  9. EasyMock.expect(aggregator.getMerger()).andReturn(merger);
  10. EasyMock.replay(groupedStreamMock, aggregator, sessionWindowed);
  11. expression.applyAggregate(groupedStreamMock, initializer, aggregator, materialized);
  12. EasyMock.verify(aggregator);
  13. }

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

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void shouldCreateSessionWindowedStreamWithInactiviyGap() {
  4. EasyMock.expect(groupedStreamMock.windowedBy(EasyMock.capture(sessionWindows))).andReturn(sessionWindowed);
  5. EasyMock.expect(sessionWindowed.aggregate(same(initializer),
  6. same(aggregator),
  7. anyObject(Merger.class),
  8. same(materialized))).andReturn(null);
  9. EasyMock.replay(groupedStreamMock, aggregator, sessionWindowed);
  10. expression.applyAggregate(groupedStreamMock, initializer, aggregator, materialized);
  11. assertThat(sessionWindows.getValue().inactivityGap(), equalTo(5000L));
  12. EasyMock.verify(groupedStreamMock);
  13. }

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

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

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

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

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

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

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

  1. @Test
  2. public void testDoFilter() throws Exception {
  3. IMocksControl ctrl = createStrictControl();
  4. FilterChain originalChain = ctrl.createMock(FilterChain.class);
  5. Filter filter1 = ctrl.createMock("filter1", Filter.class);
  6. Filter filter2 = ctrl.createMock("filter2", Filter.class);
  7. ServletRequest request = ctrl.createMock(ServletRequest.class);
  8. ServletResponse response = ctrl.createMock(ServletResponse.class);
  9. Capture<FilterChain> fc1 = new Capture<FilterChain>();
  10. Capture<FilterChain> fc2 = new Capture<FilterChain>();
  11. filter1.doFilter(same(request), same(response), and(anyObject(FilterChain.class), capture(fc1)));
  12. filter2.doFilter(same(request), same(response), and(anyObject(FilterChain.class), capture(fc2)));
  13. originalChain.doFilter(request, response);
  14. ctrl.replay();
  15. SimpleFilterChain underTest = new SimpleFilterChain(originalChain, Arrays.asList(filter1, filter2).iterator());
  16. // all we actually care about is that, if we keep calling the filter chain, everything is called in the right
  17. // order - we don't care what fc actually contains
  18. underTest.doFilter(request, response);
  19. fc1.getValue().doFilter(request, response);
  20. fc2.getValue().doFilter(request, response);
  21. ctrl.verify();
  22. }
  23. }

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

  1. private void handleBackendResponseReturnsResponse(final ClassicHttpRequest request, final ClassicHttpResponse response)
  2. throws IOException {
  3. expect(
  4. impl.handleBackendResponse(
  5. same(host),
  6. same(request),
  7. same(scope),
  8. isA(Date.class),
  9. isA(Date.class),
  10. isA(ClassicHttpResponse.class))).andReturn(response);
  11. }

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

  1. private IExpectationSetters<ClassicHttpResponse> implExpectsAnyRequestAndReturn(
  2. final ClassicHttpResponse response) throws Exception {
  3. final ClassicHttpResponse resp = impl.callBackend(
  4. same(host),
  5. isA(ClassicHttpRequest.class),
  6. isA(ExecChain.Scope.class),
  7. isA(ExecChain.class));
  8. return EasyMock.expect(resp).andReturn(response);
  9. }

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

  1. @Test
  2. public void testSmallEnoughResponsesAreCached() throws Exception {
  3. final HttpHost host = new HttpHost("foo.example.com");
  4. final ClassicHttpRequest request = new HttpGet("http://foo.example.com/bar");
  5. final Date now = new Date();
  6. final Date requestSent = new Date(now.getTime() - 3 * 1000L);
  7. final Date responseGenerated = new Date(now.getTime() - 2 * 1000L);
  8. final Date responseReceived = new Date(now.getTime() - 1 * 1000L);
  9. final ClassicHttpResponse originResponse = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
  10. originResponse.setEntity(HttpTestUtils.makeBody(CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES - 1));
  11. originResponse.setHeader("Cache-Control","public, max-age=3600");
  12. originResponse.setHeader("Date", DateUtils.formatDate(responseGenerated));
  13. originResponse.setHeader("ETag", "\"etag\"");
  14. final HttpCacheEntry httpCacheEntry = HttpTestUtils.makeCacheEntry();
  15. final SimpleHttpResponse response = SimpleHttpResponse.create(HttpStatus.SC_OK);
  16. EasyMock.expect(mockCache.createCacheEntry(
  17. eq(host),
  18. same(request),
  19. same(originResponse),
  20. isA(ByteArrayBuffer.class),
  21. eq(requestSent),
  22. eq(responseReceived))).andReturn(httpCacheEntry).once();
  23. EasyMock.expect(mockResponseGenerator.generateResponse(
  24. same(request),
  25. same(httpCacheEntry))).andReturn(response).once();
  26. replayMocks();
  27. final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, mockEndpoint, context);
  28. impl.cacheAndReturnResponse(host, request, originResponse, scope, requestSent, responseReceived);
  29. verifyMocks();
  30. }

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

  1. @Test
  2. public void testRevalidationCallsHandleBackEndResponseWhenNot200Or304() throws Exception {
  3. mockImplMethods(GET_CURRENT_DATE, HANDLE_BACKEND_RESPONSE);
  4. final ClassicHttpRequest validate = new BasicClassicHttpRequest("GET", "/");
  5. final ClassicHttpResponse originResponse = new BasicClassicHttpResponse(HttpStatus.SC_NOT_FOUND, "Not Found");
  6. final ClassicHttpResponse finalResponse = HttpTestUtils.make200Response();
  7. conditionalRequestBuilderReturns(validate);
  8. getCurrentDateReturns(requestDate);
  9. backendExpectsRequestAndReturn(validate, originResponse);
  10. getCurrentDateReturns(responseDate);
  11. expect(impl.handleBackendResponse(
  12. same(host),
  13. same(validate),
  14. same(scope),
  15. eq(requestDate),
  16. eq(responseDate),
  17. same(originResponse))).andReturn(finalResponse);
  18. replayMocks();
  19. final HttpResponse result =
  20. impl.revalidateCacheEntry(host, request, scope, mockExecChain, entry);
  21. verifyMocks();
  22. Assert.assertSame(finalResponse, result);
  23. }

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

  1. @Test
  2. public void testRevalidationUpdatesCacheEntryAndPutsItToCacheWhen304ReturningCachedResponse()
  3. throws Exception {
  4. mockImplMethods(GET_CURRENT_DATE);
  5. final ClassicHttpRequest validate = new BasicClassicHttpRequest("GET", "/");
  6. final ClassicHttpResponse originResponse = HttpTestUtils.make304Response();
  7. final HttpCacheEntry updatedEntry = HttpTestUtils.makeCacheEntry();
  8. conditionalRequestBuilderReturns(validate);
  9. getCurrentDateReturns(requestDate);
  10. backendExpectsRequestAndReturn(validate, originResponse);
  11. getCurrentDateReturns(responseDate);
  12. expect(mockCache.updateCacheEntry(
  13. eq(host),
  14. same(request),
  15. same(entry),
  16. same(originResponse),
  17. eq(requestDate),
  18. eq(responseDate)))
  19. .andReturn(updatedEntry);
  20. expect(mockSuitabilityChecker.isConditional(request)).andReturn(false);
  21. responseIsGeneratedFromCache(SimpleHttpResponse.create(HttpStatus.SC_OK));
  22. replayMocks();
  23. impl.revalidateCacheEntry(host, request, scope, mockExecChain, entry);
  24. verifyMocks();
  25. }

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

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

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

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

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

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

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

  1. @Test
  2. public void executeWithBlockedBatch() throws Exception {
  3. PipelinedData pipeline = getPipelinedData(BLOCKED_FIRST_BATCH_CONTENT);
  4. // Expect a batch with no content
  5. expect(
  6. preloader.createPreloadTasks(same(context), eqBatch(0, 0)))
  7. .andReturn(ImmutableList.<Callable<PreloadedData>>of());
  8. control.replay();
  9. PipelineExecutor.Results results = executor.execute(context,
  10. ImmutableList.of(pipeline));
  11. assertEquals(0, results.results.size());
  12. assertTrue(results.keyedResults.isEmpty());
  13. assertEquals(1, results.remainingPipelines.size());
  14. assertSame(pipeline, results.remainingPipelines.iterator().next());
  15. control.verify();
  16. }

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

  1. @Test
  2. public void executeWithBlockedBatch() throws Exception {
  3. PipelinedData pipeline = getPipelinedData(BLOCKED_FIRST_BATCH_CONTENT);
  4. // Expect a batch with no content
  5. expect(
  6. preloader.createPreloadTasks(same(context), eqBatch(0, 0)))
  7. .andReturn(ImmutableList.<Callable<PreloadedData>>of());
  8. control.replay();
  9. PipelineExecutor.Results results = executor.execute(context,
  10. ImmutableList.of(pipeline));
  11. assertEquals(0, results.results.size());
  12. assertTrue(results.keyedResults.isEmpty());
  13. assertEquals(1, results.remainingPipelines.size());
  14. assertSame(pipeline, results.remainingPipelines.iterator().next());
  15. control.verify();
  16. }

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

  1. @Test
  2. public void executeWithBlockedBatch() throws Exception {
  3. PipelinedData pipeline = getPipelinedData(BLOCKED_FIRST_BATCH_CONTENT);
  4. // Expect a batch with no content
  5. expect(
  6. preloader.createPreloadTasks(same(context), eqBatch(0, 0)))
  7. .andReturn(ImmutableList.<Callable<PreloadedData>>of());
  8. control.replay();
  9. PipelineExecutor.Results results = executor.execute(context,
  10. ImmutableList.of(pipeline));
  11. assertEquals(0, results.results.size());
  12. assertTrue(results.keyedResults.isEmpty());
  13. assertEquals(1, results.remainingPipelines.size());
  14. assertSame(pipeline, results.remainingPipelines.iterator().next());
  15. control.verify();
  16. }

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

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

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

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

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

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

相关文章