本文整理了Java中org.easymock.EasyMock.mock()
方法的一些代码示例,展示了EasyMock.mock()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EasyMock.mock()
方法的具体详情如下:
包路径:org.easymock.EasyMock
类名称:EasyMock
方法名:mock
[英]Creates a mock object that implements the given interface, order checking is disabled by default.
[中]创建实现给定接口的模拟对象,默认情况下禁用顺序检查。
代码示例来源:origin: org.easymock/easymock
/**
* Creates a mock object that implements the given interface, order checking
* is disabled by default.
* <p>
* <b>Note:</b> This is the old version of {@link #mock(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 createMock(Class<?> toMock) {
return mock(toMock);
}
代码示例来源:origin: org.easymock/easymock
/**
* Creates a mock object that implements the given interface, order checking
* is disabled by default.
* <p>
* <b>Note:</b> This is the old version of {@link #mock(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 createMock(String name, Class<?> toMock) {
return mock(name, toMock);
}
代码示例来源:origin: org.easymock/easymock
/**
* Creates a mock object, of the requested type, that implements the given interface
* or extends the given class.
* <p>
* <b>Note:</b> This is the old version of {@link #mock(MockType, Class)}, which is more completion friendly
*
* @param type
* the type of the mock to be created.
* @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.
* @since 3.2
*/
public static <T> T createMock(MockType type, Class<?> toMock) {
return mock(type, toMock);
}
代码示例来源:origin: org.easymock/easymock
/**
* Creates a mock object, of the requested type and name, that implements the given interface
* or extends the given class
* <p>
* <b>Note:</b> This is the old version of {@link #mock(String, MockType, Class)}, which is more completion friendly
*
* @param name
* the name of the mock object.
* @param type
* the type of the mock to be created.
* @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.
* @since 3.2
*/
public static <T> T createMock(String name, MockType type, Class<?> toMock) {
return mock(name, type, toMock);
}
代码示例来源:origin: confluentinc/ksql
private UriInfo uriInfo(final String uri) throws URISyntaxException {
final UriInfo uriInfo = mock(UriInfo.class);
expect(uriInfo.getAbsolutePath()).andReturn(new URI(uri));
replay(uriInfo);
return uriInfo;
}
}
代码示例来源:origin: confluentinc/ksql
@Before
public void setUp() {
schemaRegistryClient = mock(SchemaRegistryClient.class);
}
代码示例来源:origin: apache/incubator-druid
private StorageLocation fakeLocation(long total, long free, long max, Double percent)
{
File file = EasyMock.mock(File.class);
EasyMock.expect(file.getTotalSpace()).andReturn(total).anyTimes();
EasyMock.expect(file.getFreeSpace()).andReturn(free).anyTimes();
EasyMock.replay(file);
return new StorageLocation(file, max, percent);
}
代码示例来源:origin: confluentinc/ksql
@Test
public void shouldEnsureRewriteRequirementCorrectly() {
assertThat("Query should be valid for rewrite for struct.", StatementRewriteForStruct.requiresRewrite(EasyMock.mock(Query.class)));
assertThat("CSAS should be valid for rewrite for struct.", StatementRewriteForStruct.requiresRewrite(EasyMock.mock(CreateStreamAsSelect.class)));
assertThat("CTAS should be valid for rewrite for struct.", StatementRewriteForStruct.requiresRewrite(EasyMock.mock(CreateTableAsSelect.class)));
assertThat("Insert Into should be valid for rewrite for struct.", StatementRewriteForStruct.requiresRewrite(EasyMock.mock(InsertInto.class)));
}
代码示例来源:origin: confluentinc/ksql
private StatusResource getTestStatusResource() {
final StatementExecutor mockStatementExecutor = mock(StatementExecutor.class);
expect(mockStatementExecutor.getStatuses()).andReturn(mockCommandStatuses);
for (final Map.Entry<CommandId, CommandStatus> commandEntry : mockCommandStatuses.entrySet()) {
expect(mockStatementExecutor.getStatus(commandEntry.getKey())).andReturn(Optional.of(commandEntry.getValue()));
}
expect(mockStatementExecutor.getStatus(anyObject(CommandId.class))).andReturn(Optional.empty());
replay(mockStatementExecutor);
return new StatusResource(mockStatementExecutor);
}
代码示例来源:origin: confluentinc/ksql
@Test
public void shouldFailTestIfStatementShouldBeRewritten() {
assertThat("Incorrect rewrite requirement enforcement.", !StatementRewriteForStruct.requiresRewrite(EasyMock.mock(CreateTable.class)));
}
代码示例来源:origin: apache/incubator-druid
@Test
public void cleanup()
{
PooledTopNAlgorithm pooledTopNAlgorithm = new PooledTopNAlgorithm(EasyMock.mock(StorageAdapter.class), null, null);
PooledTopNAlgorithm.PooledTopNParams params = EasyMock.createMock(PooledTopNAlgorithm.PooledTopNParams.class);
ResourceHolder<ByteBuffer> resourceHolder = EasyMock.createMock(ResourceHolder.class);
EasyMock.expect(params.getResultsBufHolder()).andReturn(resourceHolder).times(1);
EasyMock.expect(resourceHolder.get()).andReturn(ByteBuffer.allocate(1)).times(1);
resourceHolder.close();
EasyMock.expectLastCall().once();
EasyMock.replay(params);
EasyMock.replay(resourceHolder);
pooledTopNAlgorithm.cleanup(params);
EasyMock.verify(params);
EasyMock.verify(resourceHolder);
}
}
代码示例来源:origin: linkedin/cruise-control
private HttpServletRequest prepareRequest(HttpSession session, String userTaskId, String resource, Map<String, String []> params) {
HttpServletRequest request = EasyMock.mock(HttpServletRequest.class);
EasyMock.expect(request.getSession()).andReturn(session).anyTimes();
EasyMock.expect(request.getSession(false)).andReturn(session).anyTimes();
EasyMock.expect(request.getMethod()).andReturn("GET").anyTimes();
EasyMock.expect(request.getRequestURI()).andReturn(resource).anyTimes();
EasyMock.expect(request.getParameterMap()).andReturn(params).anyTimes();
EasyMock.expect(request.getHeader(UserTaskManager.USER_TASK_HEADER_NAME)).andReturn(userTaskId).anyTimes();
EasyMock.expect(request.getRemoteHost()).andReturn("test-host").anyTimes();
for (String headerName : KafkaCruiseControlServletUtils.HEADERS_TO_TRY) {
EasyMock.expect(request.getHeader(headerName)).andReturn("localhost").anyTimes();
}
EasyMock.replay(request);
return request;
}
}
代码示例来源:origin: confluentinc/ksql
@Test
public void testHandle() throws IOException {
final HttpResponse response = mock(HttpResponse.class);
final StatusLine statusLine = mock(StatusLine.class);
final HttpEntity entity = mock(HttpEntity.class);
final Logger log = mock(Logger.class);
final Header header = mock(Header.class);
expect(response.getStatusLine()).andReturn(statusLine).once();
expect(statusLine.getStatusCode()).andReturn(HttpStatus.SC_OK).once();
expect(response.getEntity()).andReturn(entity).times(2);
final ByteArrayInputStream bais = new ByteArrayInputStream("yolo".getBytes(StandardCharsets.UTF_8));
expect(entity.getContent()).andReturn(bais).times(2);
expect(entity.getContentType()).andReturn(header).times(1);
expect(header.getElements()).andReturn(new HeaderElement[]{});
expect(entity.getContentLength()).andReturn(4L).times(2);
log.warn("yolo");
expectLastCall().once();
replay(response, statusLine, entity, header, log);
final KsqlVersionCheckerResponseHandler kvcr = new KsqlVersionCheckerResponseHandler(log);
kvcr.handle(response);
verify(response, statusLine, entity, header, log);
}
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testCleanupWithNullParams()
{
PooledTopNAlgorithm pooledTopNAlgorithm = new PooledTopNAlgorithm(EasyMock.mock(StorageAdapter.class), null, null);
pooledTopNAlgorithm.cleanup(null);
}
代码示例来源:origin: confluentinc/ksql
@Before
public void setup() {
expect(mockKsqlEngine.isAcceptingStatements()).andReturn(true);
expect(serviceContext.getTopicClient()).andReturn(mockKafkaTopicClient);
expect(mockKsqlEngine.hasActiveQueries()).andReturn(false);
statement = new PreparedStatement<>("s", mock(Statement.class));
expect(mockStatementParser.parseSingleStatement(queryString))
.andReturn(statement);
replay(mockKsqlEngine, mockStatementParser);
testResource = new StreamedQueryResource(
ksqlConfig,
mockKsqlEngine,
serviceContext,
mockStatementParser,
commandQueue,
DISCONNECT_CHECK_INTERVAL,
activenessRegistrar);
}
代码示例来源:origin: linkedin/cruise-control
private BrokerFailureDetector createBrokerFailureDetector(Queue<Anomaly> anomalies, Time time) {
LoadMonitor mockLoadMonitor = EasyMock.mock(LoadMonitor.class);
KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class);
EasyMock.expect(mockLoadMonitor.brokersWithPartitions(anyLong())).andAnswer(() -> new HashSet<>(Arrays.asList(0, 1))).anyTimes();
EasyMock.replay(mockLoadMonitor);
Properties props = KafkaCruiseControlUnitTestUtils.getKafkaCruiseControlProperties();
props.setProperty(KafkaCruiseControlConfig.ZOOKEEPER_CONNECT_CONFIG, zookeeper().getConnectionString());
KafkaCruiseControlConfig kafkaCruiseControlConfig = new KafkaCruiseControlConfig(props);
return new BrokerFailureDetector(kafkaCruiseControlConfig,
mockLoadMonitor,
anomalies,
time,
mockKafkaCruiseControl);
}
代码示例来源:origin: confluentinc/ksql
@Test
@SuppressWarnings("unchecked")
public void shouldUseAThreadLocalSerializer() throws InterruptedException {
final List<Serializer<GenericRow>> serializers = new LinkedList<>();
final ThreadLocalSerializer serializer = new ThreadLocalSerializer(
() -> {
final Serializer<GenericRow> local = mock(Serializer.class);
serializers.add(local);
expect(local.serialize(anyString(), anyObject(GenericRow.class)))
.andReturn(new byte[32])
.times(1);
replay(local);
return serializers.get(serializers.size() - 1);
}
);
for (int i = 0; i < 3; i++) {
final Thread t = new Thread(
() -> serializer.serialize("foo", new GenericRow(Collections.emptyList()))
);
t.start();
t.join();
assertThat(serializers.size(), equalTo(i + 1));
serializers.forEach(EasyMock::verify);
}
}
}
代码示例来源:origin: confluentinc/ksql
@Test
public void shouldPrintErrorIfCantConnectToRestServer() throws Exception {
givenRunInteractivelyWillExit();
final KsqlRestClient mockRestClient = EasyMock.mock(KsqlRestClient.class);
EasyMock.expect(mockRestClient.makeRootRequest()).andThrow(new KsqlRestClientException("Boom", new ProcessingException("")));
EasyMock.expect(mockRestClient.getServerInfo()).andReturn(
RestResponse.of(new ServerInfo("1.x", "testClusterId", "testServiceId")));
EasyMock.expect(mockRestClient.getServerAddress()).andReturn(new URI("http://someserver:8008")).anyTimes();
EasyMock.replay(mockRestClient);
new Cli(1L, 1L, mockRestClient, console)
.runInteractively();
assertThat(terminal.getOutputString(), containsString("Remote server address may not be valid"));
}
代码示例来源:origin: confluentinc/ksql
@Test
public void shouldPrintErrorOnUnsupportedAPI() throws Exception {
givenRunInteractivelyWillExit();
final KsqlRestClient mockRestClient = EasyMock.mock(KsqlRestClient.class);
EasyMock.expect(mockRestClient.makeRootRequest()).andReturn(
RestResponse.erroneous(
new KsqlErrorMessage(
Errors.toErrorCode(NOT_ACCEPTABLE.getStatusCode()),
"Minimum supported client version: 1.0")));
EasyMock.expect(mockRestClient.getServerInfo()).andReturn(
RestResponse.of(new ServerInfo("1.x", "testClusterId", "testServiceId")));
EasyMock.expect(mockRestClient.getServerAddress()).andReturn(new URI("http://someserver:8008"));
EasyMock.replay(mockRestClient);
new Cli(1L, 1L, mockRestClient, console)
.runInteractively();
Assert.assertThat(
terminal.getOutputString(),
containsString("This CLI version no longer supported"));
Assert.assertThat(
terminal.getOutputString(),
containsString("Minimum supported client version: 1.0"));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testBatch() {
RpcBatch batchMock = EasyMock.mock(RpcBatch.class);
EasyMock.expect(storageRpcMock.createBatch()).andReturn(batchMock);
EasyMock.replay(batchMock, storageRpcMock);
initializeService();
StorageBatch batch = storage.batch();
assertSame(options, batch.getOptions());
assertSame(storageRpcMock, batch.getStorageRpc());
assertSame(batchMock, batch.getBatch());
EasyMock.verify(batchMock);
}
内容来源于网络,如有侵权,请联系作者删除!