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

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

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

EasyMock.expect介绍

[英]Returns the expectation setter for the last expected invocation in the current thread.
[中]返回当前线程中最后一次预期调用的预期设置程序。

代码示例

代码示例来源:origin: apache/incubator-druid

  1. @Test
  2. public void testHasNext()
  3. {
  4. boolean expected = true;
  5. EasyMock.expect(peekIterator.hasNext()).andReturn(expected);
  6. EasyMock.replay(peekIterator);
  7. boolean actual = testingIterator.hasNext();
  8. EasyMock.verify(peekIterator);
  9. Assert.assertEquals("The hasNext function is broken", expected, actual);
  10. }

代码示例来源:origin: apache/incubator-druid

  1. private static LoadQueuePeon createLoadingPeon(List<DataSegment> segments)
  2. {
  3. final Set<DataSegment> segs = ImmutableSet.copyOf(segments);
  4. final long loadingSize = segs.stream().mapToLong(DataSegment::getSize).sum();
  5. final LoadQueuePeon mockPeon = EasyMock.createMock(LoadQueuePeon.class);
  6. EasyMock.expect(mockPeon.getSegmentsToLoad()).andReturn(segs).anyTimes();
  7. EasyMock.expect(mockPeon.getSegmentsMarkedToDrop()).andReturn(new HashSet<>()).anyTimes();
  8. EasyMock.expect(mockPeon.getLoadQueueSize()).andReturn(loadingSize).anyTimes();
  9. EasyMock.expect(mockPeon.getNumberOfSegmentsInQueue()).andReturn(segs.size()).anyTimes();
  10. return mockPeon;
  11. }
  12. }

代码示例来源:origin: org.apache.commons/commons-lang3

  1. @Test(expected = Error.class)
  2. public void testWhenComputableThrowsError() throws Exception {
  3. final Integer input = 1;
  4. final Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable);
  5. final Error error = new Error();
  6. expect(computable.compute(input)).andThrow(error);
  7. replay(computable);
  8. memoizer.compute(input);
  9. }
  10. }

代码示例来源:origin: apache/incubator-druid

  1. @Test
  2. public void testStartAlreadyStarted()
  3. {
  4. EasyMock.expect(metadataSupervisorManager.getLatest()).andReturn(ImmutableMap.of());
  5. replayAll();
  6. exception.expect(IllegalStateException.class);
  7. manager.start();
  8. manager.start();
  9. }

代码示例来源:origin: apache/incubator-druid

  1. private void mockCoordinator()
  2. {
  3. EasyMock.expect(coordinator.getDynamicConfigs()).andReturn(createCoordinatorDynamicConfig()).anyTimes();
  4. coordinator.removeSegment(EasyMock.anyObject());
  5. EasyMock.expectLastCall().anyTimes();
  6. EasyMock.replay(coordinator);
  7. }

代码示例来源:origin: apache/incubator-druid

  1. @Before
  2. public void setUp()
  3. {
  4. mapper.registerSubtypes(SomeBeanClass.class);
  5. req = EasyMock.createNiceMock(HttpServletRequest.class);
  6. EasyMock.expect(req.getContentType()).andReturn(MediaType.APPLICATION_JSON).anyTimes();
  7. EasyMock.replay(req);
  8. }

代码示例来源:origin: apache/incubator-druid

  1. @Test
  2. public void testRewriteURI()
  3. {
  4. DruidLeaderClient druidLeaderClient = EasyMock.createMock(DruidLeaderClient.class);
  5. EasyMock.expect(druidLeaderClient.findCurrentLeader()).andReturn("https://overlord:port");
  6. HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
  7. EasyMock.expect(request.getQueryString()).andReturn("param1=test&param2=test2").anyTimes();
  8. // %3A is a colon; test to make sure urlencoded paths work right.
  9. EasyMock.expect(request.getRequestURI()).andReturn("/druid/over%3Alord/worker").anyTimes();
  10. EasyMock.replay(druidLeaderClient, request);
  11. URI uri = URI.create(new OverlordProxyServlet(druidLeaderClient, null, null).rewriteTarget(request));
  12. Assert.assertEquals("https://overlord:port/druid/over%3Alord/worker?param1=test&param2=test2", uri.toString());
  13. }

代码示例来源:origin: org.apache.commons/commons-lang3

  1. @Test(expected = RuntimeException.class)
  2. public void testWhenComputableThrowsRuntimeException() throws Exception {
  3. final Integer input = 1;
  4. final Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable);
  5. final RuntimeException runtimeException = new RuntimeException("Some runtime exception");
  6. expect(computable.compute(input)).andThrow(runtimeException);
  7. replay(computable);
  8. memoizer.compute(input);
  9. }

代码示例来源:origin: apache/incubator-druid

  1. private static LoadQueuePeon createEmptyPeon()
  2. {
  3. final LoadQueuePeon mockPeon = EasyMock.createMock(LoadQueuePeon.class);
  4. EasyMock.expect(mockPeon.getSegmentsToLoad()).andReturn(new HashSet<>()).anyTimes();
  5. EasyMock.expect(mockPeon.getSegmentsMarkedToDrop()).andReturn(new HashSet<>()).anyTimes();
  6. EasyMock.expect(mockPeon.getLoadQueueSize()).andReturn(0L).anyTimes();
  7. EasyMock.expect(mockPeon.getNumberOfSegmentsInQueue()).andReturn(0).anyTimes();
  8. return mockPeon;
  9. }

代码示例来源:origin: apache/incubator-druid

  1. @Test
  2. public void testGetEmitter()
  3. {
  4. ComposingEmitterConfig config = EasyMock.createMock(ComposingEmitterConfig.class);
  5. EasyMock.expect(config.getEmitters()).andReturn(Collections.singletonList(testEmitterType)).anyTimes();
  6. Injector injector = EasyMock.createMock(Injector.class);
  7. EasyMock.expect(injector.getInstance(Key.get(Emitter.class, Names.named(testEmitterType)))).andReturn(emitter);
  8. EasyMock.replay(config, injector);
  9. Emitter composingEmitter = new ComposingEmitterModule().getEmitter(config, injector);
  10. composingEmitter.start();
  11. EasyMock.verify(config, emitter, injector);
  12. }

代码示例来源:origin: apache/incubator-druid

  1. private static ShardSpec shardSpec(String dimension, boolean contained)
  2. {
  3. ShardSpec shard = EasyMock.createMock(ShardSpec.class);
  4. EasyMock.expect(shard.getDomainDimensions())
  5. .andReturn(ImmutableList.of(dimension))
  6. .anyTimes();
  7. EasyMock.expect(shard.possibleInDomain(EasyMock.anyObject()))
  8. .andReturn(contained)
  9. .anyTimes();
  10. return shard;
  11. }
  12. }

代码示例来源:origin: apache/incubator-druid

  1. @Test(expected = NoSuchElementException.class)
  2. public void testExceptionInNext()
  3. {
  4. boolean expected = false;
  5. EasyMock.expect(peekIterator.hasNext()).andReturn(expected);
  6. EasyMock.replay(peekIterator);
  7. testingIterator.next();
  8. EasyMock.verify(peekIterator);
  9. }

代码示例来源:origin: apache/incubator-druid

  1. @Before
  2. public void setUp()
  3. {
  4. tierSelectorStrategy = EasyMock.createMock(TierSelectorStrategy.class);
  5. expect(tierSelectorStrategy.getComparator()).andReturn(Integer::compare).anyTimes();
  6. }

代码示例来源:origin: apache/incubator-druid

  1. @Test
  2. public void testShutdownAllTasksForNonExistingDataSource()
  3. {
  4. final TaskQueue taskQueue = EasyMock.createMock(TaskQueue.class);
  5. EasyMock.expect(taskMaster.isLeader()).andReturn(true).anyTimes();
  6. EasyMock.expect(taskMaster.getTaskQueue()).andReturn(Optional.of(taskQueue)).anyTimes();
  7. EasyMock.expect(taskStorageQueryAdapter.getActiveTaskInfo(EasyMock.anyString())).andReturn(Collections.emptyList());
  8. EasyMock.replay(taskRunner, taskMaster, taskStorageQueryAdapter, indexerMetadataStorageAdapter, req);
  9. final Response response = overlordResource.shutdownTasksForDataSource("notExisting");
  10. Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
  11. }

代码示例来源:origin: apache/incubator-druid

  1. @Test
  2. public void testGetRedirectURL()
  3. {
  4. String query = "foo=bar&x=y";
  5. String request = "/request";
  6. EasyMock.expect(druidCoordinator.getCurrentLeader()).andReturn("http://localhost").anyTimes();
  7. EasyMock.replay(druidCoordinator);
  8. URL url = coordinatorRedirectInfo.getRedirectURL(query, request);
  9. Assert.assertEquals("http://localhost/request?foo=bar&x=y", url.toString());
  10. EasyMock.verify(druidCoordinator);
  11. }
  12. }

代码示例来源:origin: apache/incubator-druid

  1. @Test
  2. public void testGetRedirectURL()
  3. {
  4. String host = "http://localhost";
  5. String query = "foo=bar&x=y";
  6. String request = "/request";
  7. EasyMock.expect(taskMaster.getCurrentLeader()).andReturn(host).anyTimes();
  8. EasyMock.replay(taskMaster);
  9. URL url = redirectInfo.getRedirectURL(query, request);
  10. Assert.assertEquals("http://localhost/request?foo=bar&x=y", url.toString());
  11. EasyMock.verify(taskMaster);
  12. }

代码示例来源:origin: apache/incubator-druid

  1. @Test
  2. public void testDatasourcesResourcesFilteringBadPath()
  3. {
  4. final String badRequestPath = WORD.matcher(requestPath).replaceAll("droid");
  5. EasyMock.expect(request.getPath()).andReturn(badRequestPath).anyTimes();
  6. EasyMock.replay(req, request, authorizerMapper);
  7. }

代码示例来源:origin: apache/incubator-druid

  1. @Test
  2. public void testNotImplementedIntrospectLookup()
  3. {
  4. EasyMock.expect(lookupExtractorFactory.getIntrospectHandler()).andReturn(null);
  5. EasyMock.expect(lookupExtractorFactory.get()).andReturn(new MapLookupExtractor(ImmutableMap.of(), false)).anyTimes();
  6. EasyMock.replay(lookupExtractorFactory);
  7. Assert.assertEquals(Response.status(Response.Status.NOT_FOUND).build().getStatus(), ((Response) lookupIntrospectionResource.introspectLookup("lookupId")).getStatus());
  8. }

代码示例来源:origin: org.apache.commons/commons-lang3

  1. /**
  2. * Tests createIfAbsent() if the map does not contain the key in question.
  3. *
  4. * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it
  5. */
  6. @Test
  7. public void testCreateIfAbsentKeyNotPresent() throws ConcurrentException {
  8. @SuppressWarnings("unchecked")
  9. final
  10. ConcurrentInitializer<Integer> init = EasyMock
  11. .createMock(ConcurrentInitializer.class);
  12. final String key = "testKey";
  13. final Integer value = 42;
  14. EasyMock.expect(init.get()).andReturn(value);
  15. EasyMock.replay(init);
  16. final ConcurrentMap<String, Integer> map = new ConcurrentHashMap<>();
  17. assertEquals("Wrong result", value,
  18. ConcurrentUtils.createIfAbsent(map, key, init));
  19. assertEquals("Wrong value in map", value, map.get(key));
  20. EasyMock.verify(init);
  21. }

代码示例来源:origin: apache/incubator-druid

  1. @Test
  2. public void testLeader()
  3. {
  4. EasyMock.expect(taskMaster.getCurrentLeader()).andReturn("boz").once();
  5. EasyMock.replay(taskRunner, taskMaster, taskStorageQueryAdapter, indexerMetadataStorageAdapter, req);
  6. final Response response = overlordResource.getLeader();
  7. Assert.assertEquals("boz", response.getEntity());
  8. Assert.assertEquals(200, response.getStatus());
  9. }

相关文章