本文整理汇总了Java中org.easymock.IExpectationSetters类的典型用法代码示例。如果您正苦于以下问题:Java IExpectationSetters类的具体用法?Java IExpectationSetters怎么用?Java IExpectationSetters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IExpectationSetters类属于org.easymock包,在下文中一共展示了IExpectationSetters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: expectApplyTransformationChain
import org.easymock.IExpectationSetters; //导入依赖的package包/类
private void expectApplyTransformationChain(boolean anyTimes) {
final Capture<SourceRecord> recordCapture = EasyMock.newCapture();
IExpectationSetters<SourceRecord> convertKeyExpect = EasyMock.expect(transformationChain.apply(EasyMock.capture(recordCapture)));
if (anyTimes)
convertKeyExpect.andStubAnswer(new IAnswer<SourceRecord>() {
@Override
public SourceRecord answer() {
return recordCapture.getValue();
}
});
else
convertKeyExpect.andAnswer(new IAnswer<SourceRecord>() {
@Override
public SourceRecord answer() {
return recordCapture.getValue();
}
});
}
示例2: expectOffsetFlush
import org.easymock.IExpectationSetters; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void expectOffsetFlush(boolean succeed) throws Exception {
EasyMock.expect(offsetWriter.beginFlush()).andReturn(true);
Future<Void> flushFuture = PowerMock.createMock(Future.class);
EasyMock.expect(offsetWriter.doFlush(EasyMock.anyObject(Callback.class))).andReturn(flushFuture);
// Should throw for failure
IExpectationSetters<Void> futureGetExpect = EasyMock.expect(
flushFuture.get(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class)));
if (succeed) {
sourceTask.commit();
EasyMock.expectLastCall();
futureGetExpect.andReturn(null);
} else {
futureGetExpect.andThrow(new TimeoutException());
offsetWriter.cancelFlush();
PowerMock.expectLastCall();
}
}
示例3: expectOnePoll
import org.easymock.IExpectationSetters; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private IExpectationSetters<Object> expectOnePoll() {
// Currently the SinkTask's put() method will not be invoked unless we provide some data, so instead of
// returning empty data, we return one record. The expectation is that the data will be ignored by the
// response behavior specified using the return value of this method.
EasyMock.expect(consumer.poll(EasyMock.anyLong())).andAnswer(
new IAnswer<ConsumerRecords<byte[], byte[]>>() {
@Override
public ConsumerRecords<byte[], byte[]> answer() throws Throwable {
// "Sleep" so time will progress
time.sleep(1L);
ConsumerRecords<byte[], byte[]> records = new ConsumerRecords<>(
Collections.singletonMap(
new TopicPartition(TOPIC, PARTITION),
Arrays.asList(
new ConsumerRecord<>(TOPIC, PARTITION, FIRST_OFFSET + recordsReturned, TIMESTAMP, TIMESTAMP_TYPE, 0L, 0, 0, RAW_KEY, RAW_VALUE)
)));
recordsReturned++;
return records;
}
});
EasyMock.expect(keyConverter.toConnectData(TOPIC, RAW_KEY)).andReturn(new SchemaAndValue(KEY_SCHEMA, KEY));
EasyMock.expect(valueConverter.toConnectData(TOPIC, RAW_VALUE)).andReturn(new SchemaAndValue(VALUE_SCHEMA, VALUE));
sinkTask.put(EasyMock.anyObject(Collection.class));
return EasyMock.expectLastCall();
}
示例4: createMockLibrary
import org.easymock.IExpectationSetters; //导入依赖的package包/类
public static AndroidLibrary createMockLibrary(String allResources, String publicResources,
List<AndroidLibrary> dependencies)
throws IOException {
final File tempDir = TestUtils.createTempDirDeletedOnExit();
Files.write(allResources, new File(tempDir, FN_RESOURCE_TEXT), Charsets.UTF_8);
File publicTxtFile = new File(tempDir, FN_PUBLIC_TXT);
if (publicResources != null) {
Files.write(publicResources, publicTxtFile, Charsets.UTF_8);
}
AndroidLibrary library = createNiceMock(AndroidLibrary.class);
expect(library.getPublicResources()).andReturn(publicTxtFile).anyTimes();
// Work around wildcard capture
//expect(mock.getLibraryDependencies()).andReturn(dependencies).anyTimes();
IExpectationSetters setter = expect(library.getLibraryDependencies());
//noinspection unchecked
setter.andReturn(dependencies);
setter.anyTimes();
replay(library);
return library;
}
示例5: expectPrivate
import org.easymock.IExpectationSetters; //导入依赖的package包/类
/**
* Used to specify expectations on private methods. Use this method to
* handle overloaded methods.
*/
@SuppressWarnings("all")
public static synchronized <T> IExpectationSetters<T> expectPrivate(Object instance, String methodName,
Class<?>[] parameterTypes, Object... arguments) throws Exception {
if (arguments == null) {
arguments = new Object[0];
}
if (instance == null) {
throw new IllegalArgumentException("instance cannot be null.");
} else if (arguments.length != parameterTypes.length) {
throw new IllegalArgumentException(
"The length of the arguments must be equal to the number of parameter types.");
}
Method foundMethod = Whitebox.getMethod(instance.getClass(), methodName, parameterTypes);
WhiteboxImpl.throwExceptionIfMethodWasNotFound(instance.getClass(), methodName, foundMethod, parameterTypes);
return doExpectPrivate(instance, foundMethod, arguments);
}
示例6: expectConvertKeyValue
import org.easymock.IExpectationSetters; //导入依赖的package包/类
private void expectConvertKeyValue(boolean anyTimes) {
IExpectationSetters<byte[]> convertKeyExpect = EasyMock.expect(keyConverter.fromConnectData(TOPIC, KEY_SCHEMA, KEY));
if (anyTimes)
convertKeyExpect.andStubReturn(SERIALIZED_KEY);
else
convertKeyExpect.andReturn(SERIALIZED_KEY);
IExpectationSetters<byte[]> convertValueExpect = EasyMock.expect(valueConverter.fromConnectData(TOPIC, RECORD_SCHEMA, RECORD));
if (anyTimes)
convertValueExpect.andStubReturn(SERIALIZED_RECORD);
else
convertValueExpect.andReturn(SERIALIZED_RECORD);
}
示例7: expectTaskCommitRecord
import org.easymock.IExpectationSetters; //导入依赖的package包/类
private void expectTaskCommitRecord(boolean anyTimes, boolean succeed) throws InterruptedException {
sourceTask.commitRecord(EasyMock.anyObject(SourceRecord.class));
IExpectationSetters<Void> expect = EasyMock.expectLastCall();
if (!succeed) {
expect = expect.andThrow(new RuntimeException("Error committing record in source task"));
}
if (anyTimes) {
expect.anyTimes();
}
}
示例8: expectOffsetCommit
import org.easymock.IExpectationSetters; //导入依赖的package包/类
private Capture<OffsetCommitCallback> expectOffsetCommit(final long expectedMessages,
final RuntimeException error,
final Exception consumerCommitError,
final long consumerCommitDelayMs,
final boolean invokeCallback)
throws Exception {
final long finalOffset = FIRST_OFFSET + expectedMessages;
// All assigned partitions will have offsets committed, but we've only processed messages/updated offsets for one
final Map<TopicPartition, OffsetAndMetadata> offsetsToCommit = new HashMap<>();
offsetsToCommit.put(TOPIC_PARTITION, new OffsetAndMetadata(finalOffset));
offsetsToCommit.put(TOPIC_PARTITION2, new OffsetAndMetadata(FIRST_OFFSET));
offsetsToCommit.put(TOPIC_PARTITION3, new OffsetAndMetadata(FIRST_OFFSET));
sinkTask.preCommit(offsetsToCommit);
IExpectationSetters<Object> expectation = PowerMock.expectLastCall();
if (error != null) {
expectation.andThrow(error).once();
return null;
} else {
expectation.andReturn(offsetsToCommit);
}
final Capture<OffsetCommitCallback> capturedCallback = EasyMock.newCapture();
consumer.commitAsync(EasyMock.eq(offsetsToCommit),
EasyMock.capture(capturedCallback));
PowerMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
time.sleep(consumerCommitDelayMs);
if (invokeCallback)
capturedCallback.getValue().onComplete(offsetsToCommit, consumerCommitError);
return null;
}
});
return capturedCallback;
}
示例9: expectAssigned
import org.easymock.IExpectationSetters; //导入依赖的package包/类
private IExpectationSetters<Boolean> expectAssigned(
IScheduledTask task,
Map<String, TaskGroupKey> reservationMap) {
return expect(assigner.maybeAssign(
storageUtil.mutableStoreProvider,
new ResourceRequest(task.getAssignedTask().getTask(), EMPTY),
TaskGroupKey.from(task.getAssignedTask().getTask()),
Tasks.id(task),
reservationMap));
}
示例10: expectGetHostRack
import org.easymock.IExpectationSetters; //导入依赖的package包/类
private IExpectationSetters<?> expectGetHostRack(String host, String rackToReturn) {
IHostAttributes attributes = IHostAttributes.build(new HostAttributes()
.setHost(host)
.setAttributes(ImmutableSet.of(
new Attribute().setName("rack").setValues(ImmutableSet.of(rackToReturn)))));
return expect(storageUtil.attributeStore.getHostAttributes(host))
.andReturn(Optional.of(attributes));
}
示例11: expectFetch
import org.easymock.IExpectationSetters; //导入依赖的package包/类
private IExpectationSetters<?> expectFetch(IAssignedTask... results) {
ImmutableSet.Builder<IScheduledTask> tasks = ImmutableSet.builder();
for (IAssignedTask result : results) {
tasks.add(IScheduledTask.build(new ScheduledTask().setAssignedTask(result.newBuilder())));
}
return expect(store.fetchTasks(Query.jobScoped(JOB).active()))
.andReturn(tasks.build());
}
示例12: expectFiltering
import org.easymock.IExpectationSetters; //导入依赖的package包/类
private IExpectationSetters<Set<SchedulingFilter.Veto>> expectFiltering(
final Optional<Veto> veto) {
return expect(schedulingFilter.filter(
EasyMock.anyObject(),
EasyMock.anyObject()))
.andAnswer(
veto::asSet);
}
示例13: expectWrite
import org.easymock.IExpectationSetters; //导入依赖的package包/类
private IExpectationSetters<Position> expectWrite(String content) throws Exception {
return expect(
logWriter.append(EasyMock.aryEq(content.getBytes(StandardCharsets.UTF_8)),
// Cast is needed to prevent NullPointerException on unboxing.
EasyMock.eq((long) WRITE_TIMEOUT.getValue()),
EasyMock.eq(WRITE_TIMEOUT.getUnit().getTimeUnit())));
}
示例14: expectRead
import org.easymock.IExpectationSetters; //导入依赖的package包/类
private IExpectationSetters<List<Log.Entry>> expectRead(Position position) throws Exception {
expectSetPosition(position);
return expect(logReader.read(
position,
position,
READ_TIMEOUT.getValue(),
READ_TIMEOUT.getUnit().getTimeUnit()));
}
示例15: expectShiroAfterAuthFilter
import org.easymock.IExpectationSetters; //导入依赖的package包/类
private IExpectationSetters<Object> expectShiroAfterAuthFilter()
throws ServletException, IOException {
shiroAfterAuthFilter.doFilter(
isA(HttpServletRequest.class),
isA(HttpServletResponse.class),
isA(FilterChain.class));
return expectLastCall().andAnswer(() -> {
Object[] args = getCurrentArguments();
((FilterChain) args[2]).doFilter((HttpServletRequest) args[0], (HttpServletResponse) args[1]);
return null;
});
}