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

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

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

EasyMock.createMockBuilder介绍

[英]Create a mock builder allowing to create a partial mock for the given class or interface.

Note: This is the old version of #partialMockBuilder(Class), which is more completion friendly
[中]创建一个模拟生成器,允许为给定的类或接口创建部分模拟。
注意:这是#partialMockBuilder(类)的旧版本,它更便于完成

代码示例

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

@Before
public void setUp()
{
 // use startPort and endPort to generate usable ports.
 PortFinder finder1 = EasyMock.createMockBuilder(PortFinder.class)
                .withConstructor(1200, 1201, ImmutableList.of())
                .addMockedMethod("canBind")
                .createMock();
 // chose usable ports from candidates
 PortFinder finder2 = EasyMock.createMockBuilder(PortFinder.class)
                .withConstructor(1024, 1025, ImmutableList.of(1200, 1201))
                .addMockedMethod("canBind")
                .createMock();
 finders.add(finder1);
 finders.add(finder2);
}

代码示例来源:origin: geoserver/geoserver

EasyMock.createMockBuilder(GeoServerResourceLoader.class)
    .withConstructor()
    .createMock();

代码示例来源:origin: geoserver/geoserver

EasyMock.createMockBuilder(GeoServerResourceLoader.class)
    .withConstructor()
    .createMock();

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

SystemSchema.ServersTable serversTable = EasyMock.createMockBuilder(SystemSchema.ServersTable.class)
                         .withConstructor(serverView, authMapper)
                         .createMock();

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

.createMockBuilder(SystemSchema.ServerSegmentsTable.class)
.withConstructor(serverView, authMapper)
.createMock();

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

SystemSchema.TasksTable tasksTable = EasyMock.createMockBuilder(SystemSchema.TasksTable.class)
                       .withConstructor(client, mapper, responseHandler, authMapper)
                       .createMock();

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

.createMockBuilder(SystemSchema.SegmentsTable.class)
.withConstructor(druidSchema, client, mapper, responseHandler, authMapper)
.createMock();

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

@Test
public void censusHttpExecuteInterceptorShouldInjectHeader() throws IOException {
 Random random = new Random();
 SpanContext spanContext =
   SpanContext.create(
     TraceId.generateRandomId(random),
     SpanId.generateRandomId(random),
     TraceOptions.DEFAULT);
 Span mockSpan =
   createMockBuilder(Span.class)
     .withConstructor(SpanContext.class, EnumSet.class)
     .withArgs(spanContext, null)
     .createMock();
 Scope scope = tracer.withSpan(mockSpan);
 try {
  HttpExecuteInterceptor interceptor = censusHttpModule.new CensusHttpExecuteInterceptor(null);
  interceptor.intercept(httpRequest);
  assertThat(httpRequest.getHeaders().get("X-Cloud-Trace-Context")).isNotNull();
 } finally {
  scope.close();
 }
}

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

mapper = TestHelper.makeJsonMapper();
responseHolder = EasyMock.createMock(FullResponseHolder.class);
responseHandler = EasyMock.createMockBuilder(BytesAccumulatingResponseHandler.class)
             .withConstructor()
             .addMockedMethod(

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

private void mockImplMethods(final String... methods) {
  mockedImpl = true;
  impl = createMockBuilder(CachingExec.class).withConstructor(
      mockCache,
      mockValidityPolicy,
      mockResponsePolicy,
      mockResponseGenerator,
      mockRequestPolicy,
      mockSuitabilityChecker,
      mockResponseProtocolCompliance,
      mockRequestProtocolCompliance,
      mockCacheRevalidator,
      mockConditionalRequestBuilder,
      config).addMockedMethods(methods).createNiceMock();
}

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

new Random().nextBytes(bytes);
final HttpEntity mockBody = EasyMock.createMockBuilder(ByteArrayEntity.class).withConstructor(
    new Object[] { bytes }).addMockedMethods("getContentLength").createNiceMock();
org.easymock.EasyMock.expect(mockBody.getContentLength()).andReturn(-1L).anyTimes();

代码示例来源:origin: org.apache.mahout/mahout-mrlegacy

private static Counter newCounter() {
 try {
  // 0.23 case
  String c = "org.apache.hadoop.mapreduce.counters.GenericCounter";
  return (Counter) EasyMock.createMockBuilder(Class.forName(c)).createMock();
 } catch (ClassNotFoundException e) {
  // 0.20 case
  return EasyMock.createMockBuilder(Counter.class).createMock();
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testExitStatusOfCommandGreaterThanZeroTrueWhen1() {
 SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction")
      .createStrictMock();
 expect(commandRunner.runAction("status")).andReturn(new ExecResponse("", "", 1));
 replay(commandRunner);
 Predicate<String> pred = new ExitStatusOfCommandGreaterThanZero(commandRunner);
 assertEquals(pred.apply("status"), true);
 verify(commandRunner);
}

代码示例来源:origin: jclouds/legacy-jclouds

public void testExitStatusOfCommandGreaterThanZeroFalseWhen0() {
 SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction")
      .createStrictMock();
 expect(commandRunner.runAction("status")).andReturn(new ExecResponse("", "", 0));
 replay(commandRunner);
 Predicate<String> pred = new ExitStatusOfCommandGreaterThanZero(commandRunner);
 assertEquals(pred.apply("status"), false);
 verify(commandRunner);
}

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

public void testExitStatusOfCommandGreaterThanZeroTrueWhen1() {
 SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction")
      .createStrictMock();
 expect(commandRunner.runAction("status")).andReturn(new ExecResponse("", "", 1));
 replay(commandRunner);
 Predicate<String> pred = new ExitStatusOfCommandGreaterThanZero(commandRunner);
 assertEquals(pred.apply("status"), true);
 verify(commandRunner);
}

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

public void testExitStatusOfCommandGreaterThanZeroFalseWhen0() {
 SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction")
      .createStrictMock();
 expect(commandRunner.runAction("status")).andReturn(new ExecResponse("", "", 0));
 replay(commandRunner);
 Predicate<String> pred = new ExitStatusOfCommandGreaterThanZero(commandRunner);
 assertEquals(pred.apply("status"), false);
 verify(commandRunner);
}

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

/**
 * Creates a strict mock object for the given class, adds it to the internal
 * list of all mocks, and returns it.
 *
 * @param clazz Class to be mocked.
 * @return A mock instance of the given type.
 **/
protected <T> T mock(Class<T> clazz, Method[] methods, boolean strict) {
 IMockBuilder<T> builder = EasyMock.createMockBuilder(clazz).addMockedMethods(methods);
 T m = strict ? builder.createMock() : builder.createNiceMock();
 mocks.add(m);
 return m;
}

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

/**
 * Creates a strict mock object for the given class, adds it to the internal
 * list of all mocks, and returns it.
 *
 * @param clazz Class to be mocked.
 * @return A mock instance of the given type.
 **/
protected <T> T mock(Class<T> clazz, Method[] methods, boolean strict) {
 IMockBuilder<T> builder = EasyMock.createMockBuilder(clazz).addMockedMethods(methods);
 T m = strict ? builder.createMock() : builder.createNiceMock();
 mocks.add(m);
 return m;
}

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

private ClosureJsCompiler newProfilingClosureJsCompiler(CompilerOptions realOptions,
  DefaultJsCompiler defaultComp, CacheProvider cache) {
 ClosureJsCompiler compiler =
   createMockBuilder(ClosureJsCompiler.class)
     .addMockedMethods("getCompilerOptions")
     .withConstructor(defaultComp, cache, "simple").createMock();
 expect(compiler.getCompilerOptions(isA(JsUri.class))).andReturn(realOptions).anyTimes();
 replay(compiler);
 return compiler;
}

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

private ClosureJsCompiler newProfilingClosureJsCompiler(CompilerOptions realOptions,
  DefaultJsCompiler defaultComp, CacheProvider cache) {
 ClosureJsCompiler compiler =
   createMockBuilder(ClosureJsCompiler.class)
     .addMockedMethods("getCompilerOptions")
     .withConstructor(defaultComp, cache, "simple").createMock();
 expect(compiler.getCompilerOptions(isA(JsUri.class))).andReturn(realOptions).anyTimes();
 replay(compiler);
 return compiler;
}

相关文章