org.easymock.EasyMock类的使用及代码示例

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

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

EasyMock介绍

[英]Stubs for EasyMock methods
[中]EasyMock方法的存根

代码示例

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

@Test
public void testNullGetTheDataSource()
{
 EasyMock.expect(server.getDataSource("none")).andReturn(null).atLeastOnce();
 EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).atLeastOnce();
 EasyMock.replay(inventoryView, server);
 DataSourcesResource DataSourcesResource =
   new DataSourcesResource(inventoryView, null, null, null, new AuthConfig(), null);
 Assert.assertEquals(204, DataSourcesResource.getTheDataSource("none", null).getStatus());
 EasyMock.verify(inventoryView, server);
}

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

private Task createMockTask(String type)
{
 Task mock = EasyMock.createMock(Task.class);
 EasyMock.expect(mock.getType()).andReturn(type).anyTimes();
 EasyMock.replay(mock);
 return mock;
}

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

@Test
public void testValidRequest() throws Exception
{
 HttpServletRequest req = EasyMock.createStrictMock(HttpServletRequest.class);
 HttpServletResponse resp = EasyMock.createStrictMock(HttpServletResponse.class);
 FilterChain filterChain = EasyMock.createStrictMock(FilterChain.class);
 EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).once();
 EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).once();
 EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(null).once();
 filterChain.doFilter(req, resp);
 EasyMock.expectLastCall().once();
 EasyMock.replay(req, filterChain);
 SecuritySanityCheckFilter filter = new SecuritySanityCheckFilter(new DefaultObjectMapper());
 filter.doFilter(req, resp, filterChain);
 EasyMock.verify(req, filterChain);
}

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

/**
 * Prepares an executor service mock to expect the start of the timer.
 *
 * @param service the mock
 * @param future the future
 */
private void prepareStartTimer(final ScheduledExecutorService service,
    final ScheduledFuture<?> future) {
  service.scheduleAtFixedRate((Runnable) EasyMock.anyObject(), EasyMock
      .eq(PERIOD), EasyMock.eq(PERIOD), EasyMock.eq(UNIT));
  EasyMock.expectLastCall().andReturn(future);
}

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

private void mockCoordinator(DruidCoordinator coordinator)
{
 coordinator.moveSegment(
   EasyMock.anyObject(),
   EasyMock.anyObject(),
   EasyMock.anyObject(),
   EasyMock.anyObject()
 );
 EasyMock.expectLastCall().anyTimes();
 EasyMock.replay(coordinator);
}

代码示例来源:origin: linkedin/flashback

@Test
public void testPlayback()
  throws IOException {
 Scene scene = EasyMock.createMock(Scene.class);
 EasyMock.expect(scene.isReadable()).andReturn(true).anyTimes();
 EasyMock.expect(scene.isSequential()).andReturn(false).anyTimes();
 SceneWriter sceneWriter = EasyMock.createStrictMock(SceneWriter.class);
 RecordedHttpExchange recordedHttpExchange1 = EasyMock.createStrictMock(RecordedHttpExchange.class);
 RecordedHttpExchange recordedHttpExchange2 = EasyMock.createStrictMock(RecordedHttpExchange.class);
 RecordedHttpRequest recordedHttpRequest1 = EasyMock.createStrictMock(RecordedHttpRequest.class);
 RecordedHttpRequest recordedHttpRequest2 = EasyMock.createStrictMock(RecordedHttpRequest.class);
 RecordedHttpResponse recordedHttpResponse1 = EasyMock.createStrictMock(RecordedHttpResponse.class);
 RecordedHttpResponse recordedHttpResponse2 = EasyMock.createStrictMock(RecordedHttpResponse.class);
 EasyMock.expect(recordedHttpExchange1.getRecordedHttpRequest()).andReturn(recordedHttpRequest1);
 EasyMock.expect(recordedHttpExchange2.getRecordedHttpRequest()).andReturn(recordedHttpRequest2);
 EasyMock.expect(recordedHttpExchange1.getRecordedHttpResponse()).andReturn(recordedHttpResponse1);
 EasyMock.expect(recordedHttpExchange2.getRecordedHttpResponse()).andReturn(recordedHttpResponse2);
 RecordedHttpRequest incomingHttpRequest = EasyMock.createStrictMock(RecordedHttpRequest.class);
 ArrayList<RecordedHttpExchange> recordedHttpExchangeArrayList = new ArrayList<>();
 recordedHttpExchangeArrayList.add(recordedHttpExchange1);
 recordedHttpExchangeArrayList.add(recordedHttpExchange2);
 EasyMock.expect(scene.getRecordedHttpExchangeList()).andReturn(recordedHttpExchangeArrayList).times(2);
 MatchRule matchRule = EasyMock.createStrictMock(MatchRule.class);
 EasyMock.expect(matchRule.test(incomingHttpRequest, recordedHttpRequest1)).andReturn(true);
 EasyMock.replay(scene, recordedHttpExchange1, recordedHttpRequest1, matchRule);
 SceneAccessLayer sceneAccessLayer = new SceneAccessLayer(scene, sceneWriter, matchRule);
 Assert.assertEquals(sceneAccessLayer.playback(incomingHttpRequest), recordedHttpResponse1);
 EasyMock.verify(scene, recordedHttpExchange1, recordedHttpRequest1, matchRule);
}

代码示例来源:origin: linkedin/flashback

@Test(expectedExceptions = IllegalStateException.class,
  expectedExceptionsMessageRegExp = SceneAccessLayer.THE_SCENE_IS_NOT_READABLE)
public void testPlaybackNotReadable()
  throws IOException {
 Scene scene = EasyMock.createStrictMock(Scene.class);
 EasyMock.expect(scene.isReadable()).andReturn(false);
 SceneWriter sceneWriter = EasyMock.createStrictMock(SceneWriter.class);
 MatchRule matchRule = EasyMock.createStrictMock(MatchRule.class);
 RecordedHttpRequest incomingHttpRequest = EasyMock.createStrictMock(RecordedHttpRequest.class);
 EasyMock.replay(scene);
 SceneAccessLayer sceneAccessLayer = new SceneAccessLayer(scene, sceneWriter, matchRule);
 sceneAccessLayer.playback(incomingHttpRequest);
 EasyMock.verify(scene);
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testListEmptyImagesForProject() {
 compute = options.getService();
 ImmutableList<com.google.api.services.compute.model.Image> images = ImmutableList.of();
 Tuple<String, Iterable<com.google.api.services.compute.model.Image>> result =
   Tuple.<String, Iterable<com.google.api.services.compute.model.Image>>of(null, images);
 EasyMock.expect(computeRpcMock.listImages("otherProject", EMPTY_RPC_OPTIONS)).andReturn(result);
 EasyMock.replay(computeRpcMock);
 Page<Image> page = compute.listImages("otherProject");
 assertNull(page.getNextPageToken());
 assertArrayEquals(images.toArray(), Iterables.toArray(page.getValues(), Image.class));
}

代码示例来源:origin: linkedin/flashback

@Test
public void testCreateSceneExistInSequentialRecordMode()
  throws Exception {
 Scene expectedScene = EasyMock.createStrictMock(Scene.class);
 List<RecordedHttpExchange> recordedHttpExchanges = new ArrayList<>();
 Date now = new Date();
 recordedHttpExchanges.add(new RecordedHttpExchange(null, null, now));
 EasyMock.expect(expectedScene.getRecordedHttpExchangeList()).andReturn(recordedHttpExchanges);
 EasyMock.replay(expectedScene);
 Scene result = runTestGetResult(SceneMode.SEQUENTIAL_RECORD, expectedScene);
 Assert.assertNotNull(result);
 Assert.assertEquals(result.getName(), NAME);
 Assert.assertEquals(result.getSceneRoot(), ROOT);
 Assert.assertFalse(result.isReadable());
 // Creating a Scene in sequential record mode should clear the list of exchanges to allow for re-recording
 Assert.assertEquals(result.getRecordedHttpExchangeList().size(), 0);
}

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

private static ShardSpec shardSpec(String dimension, boolean contained)
 {
  ShardSpec shard = EasyMock.createMock(ShardSpec.class);
  EasyMock.expect(shard.getDomainDimensions())
      .andReturn(ImmutableList.of(dimension))
      .anyTimes();
  EasyMock.expect(shard.possibleInDomain(EasyMock.anyObject()))
      .andReturn(contained)
      .anyTimes();
  return shard;
 }
}

代码示例来源:origin: linkedin/flashback

@Test
public void testSequentialPlayback()
  throws URISyntaxException, IOException {
 Scene scene = EasyMock.createMock(Scene.class);
 SceneWriter sceneWriter = EasyMock.createMock(SceneWriter.class);
 EasyMock.expect(scene.isSequential()).andReturn(true).anyTimes();
 EasyMock.expect(scene.isReadable()).andReturn(true).anyTimes();
 RecordedHttpExchange recordedHttpExchange1 = EasyMock.createMock(RecordedHttpExchange.class);
 RecordedHttpExchange recordedHttpExchange2 = EasyMock.createMock(RecordedHttpExchange.class);
 RecordedHttpRequest recordedHttpRequest1 = EasyMock.createMock(RecordedHttpRequest.class);
 RecordedHttpRequest recordedHttpRequest2 = EasyMock.createMock(RecordedHttpRequest.class);
 RecordedHttpResponse recordedHttpResponse1 = EasyMock.createMock(RecordedHttpResponse.class);
 RecordedHttpResponse recordedHttpResponse2 = EasyMock.createMock(RecordedHttpResponse.class);
 EasyMock.expect(recordedHttpExchange1.getRecordedHttpRequest()).andReturn(recordedHttpRequest1).anyTimes();
 EasyMock.expect(recordedHttpExchange2.getRecordedHttpRequest()).andReturn(recordedHttpRequest2).anyTimes();
 EasyMock.expect(recordedHttpExchange1.getRecordedHttpResponse()).andReturn(recordedHttpResponse1).anyTimes();
 EasyMock.expect(recordedHttpExchange2.getRecordedHttpResponse()).andReturn(recordedHttpResponse2).anyTimes();
 RecordedHttpRequest incomingHttpRequest1 = EasyMock.createStrictMock(RecordedHttpRequest.class);
 RecordedHttpRequest incomingHttpRequest2 = EasyMock.createStrictMock(RecordedHttpRequest.class);
 EasyMock.expect(scene.getRecordedHttpExchangeList()).andReturn(recordedHttpExchangeArrayList).anyTimes();
 MatchRule matchRule = EasyMock.createMock(MatchRule.class);
 EasyMock.expect(matchRule.test(incomingHttpRequest1, recordedHttpRequest1)).andReturn(true).anyTimes();
 EasyMock.expect(matchRule.test(incomingHttpRequest1, recordedHttpRequest2)).andReturn(false).anyTimes();
 EasyMock.expect(matchRule.test(incomingHttpRequest2, recordedHttpRequest1)).andReturn(false).anyTimes();
 EasyMock.expect(matchRule.test(incomingHttpRequest2, recordedHttpRequest2)).andReturn(true).anyTimes();

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

@Test
public void testFetchSegments() throws SegmentLoadingException, IOException
{
 File expectedFile = temporaryFolder.newFile();
 EasyMock
   .expect(mockSegmentLoaderLocalCacheManager.getSegmentFiles(EasyMock.anyObject()))
   .andReturn(expectedFile).anyTimes();
 EasyMock
   .expect(mockSegmentLoaderLocalCacheManager.withConfig(EasyMock.anyObject()))
   .andReturn(mockSegmentLoaderLocalCacheManager).anyTimes();
 EasyMock.replay(mockSegmentLoaderLocalCacheManager);
 DataSegment dataSegment = DataSegment.builder().dataSource("source").interval(Intervals.of("2012-01-01/P1D")).version("1").size(1).build();
 List<DataSegment> segments = ImmutableList.of
   (
     dataSegment
   );
 Map actualFetchedSegment = taskToolbox.build(task).fetchSegments(segments);
 Assert.assertEquals(expectedFile, actualFetchedSegment.get(dataSegment));
}
@Test

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testListEmptyRegions() {
 ImmutableList<com.google.api.services.compute.model.Region> regions = ImmutableList.of();
 Tuple<String, Iterable<com.google.api.services.compute.model.Region>> result =
   Tuple.<String, Iterable<com.google.api.services.compute.model.Region>>of(null, regions);
 EasyMock.expect(computeRpcMock.listRegions(EMPTY_RPC_OPTIONS)).andReturn(result);
 EasyMock.replay(computeRpcMock);
 compute = options.getService();
 Page<Region> page = compute.listRegions();
 assertNull(page.getNextPageToken());
 assertArrayEquals(regions.toArray(), Iterables.toArray(page.getValues(), Region.class));
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testAggregatedListEmptyAddresses() {
 ImmutableList<com.google.api.services.compute.model.Address> addresses = ImmutableList.of();
 Tuple<String, Iterable<com.google.api.services.compute.model.Address>> result =
   Tuple.<String, Iterable<com.google.api.services.compute.model.Address>>of(null, addresses);
 EasyMock.expect(computeRpcMock.listAddresses(EMPTY_RPC_OPTIONS)).andReturn(result);
 EasyMock.replay(computeRpcMock);
 compute = options.getService();
 Page<Address> page = compute.listAddresses();
 assertNull(page.getNextPageToken());
 assertArrayEquals(addresses.toArray(), Iterables.toArray(page.getValues(), Address.class));
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testListEmptySnapshots() {
 compute = options.getService();
 ImmutableList<com.google.api.services.compute.model.Snapshot> snapshots = ImmutableList.of();
 Tuple<String, Iterable<com.google.api.services.compute.model.Snapshot>> result =
   Tuple.<String, Iterable<com.google.api.services.compute.model.Snapshot>>of(null, snapshots);
 EasyMock.expect(computeRpcMock.listSnapshots(EMPTY_RPC_OPTIONS)).andReturn(result);
 EasyMock.replay(computeRpcMock);
 Page<Snapshot> page = compute.listSnapshots();
 assertNull(page.getNextPageToken());
 assertArrayEquals(snapshots.toArray(), Iterables.toArray(page.getValues(), Snapshot.class));
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testListEmptyNetworks() {
 compute = options.getService();
 ImmutableList<com.google.api.services.compute.model.Network> networks = ImmutableList.of();
 Tuple<String, Iterable<com.google.api.services.compute.model.Network>> result =
   Tuple.<String, Iterable<com.google.api.services.compute.model.Network>>of(null, networks);
 EasyMock.expect(computeRpcMock.listNetworks(EMPTY_RPC_OPTIONS)).andReturn(result);
 EasyMock.replay(computeRpcMock);
 Page<Network> page = compute.listNetworks();
 assertNull(page.getNextPageToken());
 assertArrayEquals(networks.toArray(), Iterables.toArray(page.getValues(), Network.class));
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testListEmptyZones() {
 ImmutableList<com.google.api.services.compute.model.Zone> zones = ImmutableList.of();
 Tuple<String, Iterable<com.google.api.services.compute.model.Zone>> result =
   Tuple.<String, Iterable<com.google.api.services.compute.model.Zone>>of(null, zones);
 EasyMock.expect(computeRpcMock.listZones(EMPTY_RPC_OPTIONS)).andReturn(result);
 EasyMock.replay(computeRpcMock);
 compute = options.getService();
 Page<Zone> page = compute.listZones();
 assertNull(page.getNextPageToken());
 assertArrayEquals(zones.toArray(), Iterables.toArray(page.getValues(), Zone.class));
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testAggregatedListEmptyDisks() {
 compute = options.getService();
 ImmutableList<com.google.api.services.compute.model.Disk> diskList = ImmutableList.of();
 Tuple<String, Iterable<com.google.api.services.compute.model.Disk>> result =
   Tuple.<String, Iterable<com.google.api.services.compute.model.Disk>>of(null, diskList);
 EasyMock.expect(computeRpcMock.listDisks(EMPTY_RPC_OPTIONS)).andReturn(result);
 EasyMock.replay(computeRpcMock);
 Page<Disk> page = compute.listDisks();
 assertNull(page.getNextPageToken());
 assertArrayEquals(diskList.toArray(), Iterables.toArray(page.getValues(), Disk.class));
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testListEmptyGlobalAddresses() {
 ImmutableList<com.google.api.services.compute.model.Address> addresses = ImmutableList.of();
 Tuple<String, Iterable<com.google.api.services.compute.model.Address>> result =
   Tuple.<String, Iterable<com.google.api.services.compute.model.Address>>of(null, addresses);
 EasyMock.expect(computeRpcMock.listGlobalAddresses(EMPTY_RPC_OPTIONS)).andReturn(result);
 EasyMock.replay(computeRpcMock);
 compute = options.getService();
 Page<Address> page = compute.listGlobalAddresses();
 assertNull(page.getNextPageToken());
 assertArrayEquals(addresses.toArray(), Iterables.toArray(page.getValues(), Address.class));
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testAggregatedListEmptyDiskTypes() {
 ImmutableList<com.google.api.services.compute.model.DiskType> diskTypes = ImmutableList.of();
 Tuple<String, Iterable<com.google.api.services.compute.model.DiskType>> result =
   Tuple.<String, Iterable<com.google.api.services.compute.model.DiskType>>of(null, diskTypes);
 EasyMock.expect(computeRpcMock.listDiskTypes(EMPTY_RPC_OPTIONS)).andReturn(result);
 EasyMock.replay(computeRpcMock);
 compute = options.getService();
 Page<DiskType> page = compute.listDiskTypes();
 assertNull(page.getNextPageToken());
 assertArrayEquals(diskTypes.toArray(), Iterables.toArray(page.getValues(), DiskType.class));
}

相关文章