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

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

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

EasyMock.niceMock介绍

[英]Creates a mock object that implements the given interface, order checking is disabled by default, and the mock object will return 0, null or false for unexpected invocations.
[中]创建实现给定接口的模拟对象,默认情况下禁用顺序检查,对于意外调用,模拟对象将返回0、null或false。

代码示例

代码示例来源:origin: org.easymock/easymock

/**
 * Creates a mock object that implements the given interface, order checking
 * is disabled by default, and the mock object will return {@code 0},
 * {@code null} or {@code false} for unexpected invocations.
 * <p>
 * <b>Note:</b> This is the old version of {@link #niceMock(Class)}, which is more completion friendly
 *
 * @param toMock
 *            the class or interface that should be mocked.
 * @param <T>
 *            the interface that the mock object should implement. It is expected to be of
 *            class {@code toMock}.
 * @return the mock object.
 */
public static <T> T createNiceMock(Class<?> toMock) {
  return niceMock(toMock);
}

代码示例来源:origin: org.easymock/easymock

/**
 * Creates a mock object that implements the given interface, order checking
 * is disabled by default, and the mock object will return {@code 0},
 * {@code null} or {@code false} for unexpected invocations.
 * <p>
 * <b>Note:</b> This is the old version of {@link #niceMock(String, Class)}, which is more completion friendly
 *
 * @param name
 *            the name of the mock object.
 * @param toMock
 *            the class or interface that should be mocked.
 * @param <T>
 *            the interface that the mock object should implement. It is expected to be of
 *            class {@code toMock}.
 * @return the mock object.
 * @throws IllegalArgumentException
 *             if the name is not a valid Java identifier.
 */
public static <T> T createNiceMock(String name, Class<?> toMock) {
  return niceMock(name, toMock);
}

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

private static HttpServletRequest newRequest()
{
 final HttpServletRequest request = EasyMock.niceMock(HttpServletRequest.class);
 EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null);
 EasyMock.expect(request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT))
     .andReturn(new AuthenticationResult("test", "test", "test", Collections.emptyMap()));
 EasyMock.replay(request);
 return request;
}

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

private KsqlEngine createKsqlEngine() {
 final KsqlEngineMetrics engineMetrics = EasyMock.niceMock(KsqlEngineMetrics.class);
 EasyMock.replay(engineMetrics);
 return KsqlEngineTestUtil.createKsqlEngine(
   serviceContext,
   new MetaStoreImpl(new InternalFunctionRegistry()),
   engineMetrics);
}

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

@Override
protected void before() {
 if (restServer != null) {
  after();
 }
 try {
  restServer = KsqlRestApplication.buildApplication(
    buildConfig(),
    (booleanSupplier) -> niceMock(VersionCheckerAgent.class),
    3
  );
 } catch (final Exception e) {
  throw new RuntimeException("Failed to initialise", e);
 }
 try {
  restServer.start();
  listeners.addAll(restServer.getListeners());
 } catch (Exception var2) {
  throw new RuntimeException("Failed to start Ksql rest server", var2);
 }
}

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

server = EasyMock.niceMock(DruidServer.class);
dataSegmentList = new ArrayList<>();
dataSegmentList.add(

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

expectLastCall();
final OutputNode mockOutputNode = niceMock(OutputNode.class);
expect(mockOutputNode.accept(anyObject(PlanSourceExtractorVisitor.class), anyObject()))
  .andReturn(null);

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

@Test
public void shouldSetFieldsCorrectlyForQueryMetadata() {
 final KafkaStreams queryStreams = niceMock(KafkaStreams.class);
 final FakeSourceNode sourceNode = new FakeSourceNode("source");
 final OutputNode outputNode = new FakeOutputNode(sourceNode);

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

@Before
public void setUp() {
 objectMapper = JsonMapper.INSTANCE.mapper;
 ehCapture = newCapture();
 drainCapture = newCapture();
 limitHandlerCapture = newCapture();
 final Schema schema = SchemaBuilder.struct().field("col1", Schema.OPTIONAL_STRING_SCHEMA).build();
 final KafkaStreams kStreams = niceMock(KafkaStreams.class);
 kStreams.setStateListener(anyObject());
 expectLastCall();
 expect(kStreams.state()).andReturn(State.RUNNING);
 expect(queryMetadata.getRowQueue()).andReturn(rowQueue).anyTimes();
 expect(queryMetadata.getResultSchema()).andReturn(schema).anyTimes();
 queryMetadata.setLimitHandler(capture(limitHandlerCapture));
 expectLastCall().once();
 queryMetadata.setUncaughtExceptionHandler(capture(ehCapture));
 expectLastCall();
 replay(kStreams);
}

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

@SuppressWarnings("unchecked")
@Before
public void setUp() {
 streamName = KsqlIdentifierTestUtil.uniqueIdentifierName();
 lineSupplier = niceMock(Supplier.class);
 terminal = new TestTerminal(lineSupplier);
 rowCaptor = new TestRowCaptor();
 console = new Console(CLI_OUTPUT_FORMAT, terminal, rowCaptor);
 localCli = new Cli(
   STREAMED_QUERY_ROW_LIMIT,
   STREAMED_QUERY_TIMEOUT_MS,
   restClient,
   console
 );
 maybeDropStream("SHOULDRUNSCRIPT");
}

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

@Test
public void shouldSetFieldsCorrectlyForPersistentQueryMetadata() {
 final KafkaStreams queryStreams = niceMock(KafkaStreams.class);
 final FakeSourceNode sourceNode = new FakeSourceNode("source");
 final OutputNode outputNode = new FakeOutputNode(sourceNode);

代码示例来源:origin: briandilley/jsonrpc4j

@SuppressWarnings("unchecked")
@Test
public void callConvertedParameterTransformerShouldBeCalledIfSet() throws Exception {
  final ConvertedParameterTransformer convertedParameterTransformer = EasyMock.niceMock(ConvertedParameterTransformer.class);
  
  EasyMock.expect(mockService.testMethod(param1)).andReturn(param1);
  jsonRpcServer.setConvertedParameterTransformer(convertedParameterTransformer);
  
  EasyMock.expect(convertedParameterTransformer.transformConvertedParameters(anyObject(), anyObject(Object[].class))).andReturn(new Object[]{param1});
  EasyMock.replay(convertedParameterTransformer);
  
  jsonRpcServer.handleRequest(messageWithListParamsStream(1, "testMethod", param1), byteArrayOutputStream);
  
  EasyMock.verify(convertedParameterTransformer);
}

代码示例来源:origin: briandilley/jsonrpc4j

@SuppressWarnings("unchecked")
@Test
public void callConvertedParameterTransformerShouldTransformTheParameters() throws Exception {
  final ConvertedParameterTransformer convertedParameterTransformer = EasyMock.niceMock(ConvertedParameterTransformer.class);
  
  String[] parameters = {param1, param2};
  String[] expectedConvertedParameters = {param2, param1};
  
  EasyMock.expect(mockService.overloadedMethod(param2, param1)).andReturn("converted");
  jsonRpcServer.setConvertedParameterTransformer(convertedParameterTransformer);
  
  EasyMock.expect(convertedParameterTransformer.transformConvertedParameters(anyObject(), anyObject(Object[].class))).andReturn(expectedConvertedParameters);
  EasyMock.replay(mockService, convertedParameterTransformer);
  
  jsonRpcServer.handleRequest(messageWithListParamsStream(1, "overloadedMethod", (Object[]) parameters), byteArrayOutputStream);
  
  JsonNode json = decodeAnswer(byteArrayOutputStream);
  assertEquals("converted", json.get(JsonRpcBasicServer.RESULT).textValue());
  assertNull(json.get(JsonRpcBasicServer.ERROR));
}

代码示例来源:origin: briandilley/jsonrpc4j

/**
 * The {@link com.googlecode.jsonrpc4j.JsonRpcBasicServer} is able to have an instance of
 * {@link com.googlecode.jsonrpc4j.InvocationListener} configured for it.  Prior to a
 * method being invoked, the lister is notified and after the method is invoked, the
 * listener is notified.  This test checks that these two events are hit correctly
 * when a method is invoked.
 */

@SuppressWarnings("unchecked")
@Test
public void callMethodWithInvocationListener() throws Exception {
  final InvocationListener invocationListener = EasyMock.niceMock(InvocationListener.class);
  Method m = ServiceInterface.class.getMethod("throwsMethod", String.class);
  invocationListener.willInvoke(eq(m), anyObject(List.class));
  invocationListener.didInvoke(eq(m), anyObject(List.class), EasyMock.notNull(), EasyMock.<Throwable>isNull(), EasyMock.geq(0L));
  
  jsonRpcServer.setInvocationListener(invocationListener);
  
  EasyMock.expect(mockService.throwsMethod(param1)).andReturn(param1);
  EasyMock.replay(mockService, invocationListener);
  
  jsonRpcServer.handleRequest(messageWithListParamsStream(1, "throwsMethod", param1), byteArrayOutputStream);
  
  EasyMock.verify(invocationListener, mockService);
  
  JsonNode json = decodeAnswer(byteArrayOutputStream);
  assertEquals(param1, json.get(JsonRpcBasicServer.RESULT).textValue());
  assertNull(json.get(JsonRpcBasicServer.ERROR));
}

代码示例来源:origin: briandilley/jsonrpc4j

/**
 * The {@link com.googlecode.jsonrpc4j.JsonRpcBasicServer} is able to have an instance of
 * {@link com.googlecode.jsonrpc4j.InvocationListener} configured for it.  Prior to a
 * method being invoked, the lister is notified and after the method is invoked, the
 * listener is notified.  This test checks that these two events are hit correctly in
 * the case that an exception is raised when the method is invoked.
 */

@Test
@SuppressWarnings("unchecked")
public void callMethodThrowingWithInvocationListener() throws Exception {
  final InvocationListener invocationListener = EasyMock.niceMock(InvocationListener.class);
  Method m = ServiceInterface.class.getMethod("throwsMethod", String.class);
  invocationListener.willInvoke(eq(m), anyObject(List.class));
  invocationListener.didInvoke(eq(m), anyObject(List.class), EasyMock.isNull(), EasyMock.<Throwable>notNull(), EasyMock.geq(0L));
  
  jsonRpcServer.setInvocationListener(invocationListener);
  
  EasyMock.expect(mockService.throwsMethod(param1)).andThrow(new CustomTestException(param1));
  EasyMock.replay(mockService, invocationListener);
  
  jsonRpcServer.handleRequest(messageWithListParamsStream(1, "throwsMethod", param1), byteArrayOutputStream);
  
  EasyMock.verify(invocationListener, mockService);
  
  JsonNode json = decodeAnswer(byteArrayOutputStream);
  assertNull(json.get(JsonRpcBasicServer.RESULT));
  assertNotNull(json.get(JsonRpcBasicServer.ERROR));
}

代码示例来源:origin: hibernate/hibernate-search

final String partitionId = String.valueOf( 0 );
mockedJobContext = niceMock( JobContext.class );
mockedStepContext = niceMock( StepContext.class );

相关文章