本文整理汇总了Java中org.easymock.IExpectationSetters.andReturn方法的典型用法代码示例。如果您正苦于以下问题:Java IExpectationSetters.andReturn方法的具体用法?Java IExpectationSetters.andReturn怎么用?Java IExpectationSetters.andReturn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.easymock.IExpectationSetters
的用法示例。
在下文中一共展示了IExpectationSetters.andReturn方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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;
}
示例3: 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);
}
示例4: 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;
}
示例5: executeCallback
import org.easymock.IExpectationSetters; //导入方法依赖的package包/类
private MockUnit.Block executeCallback(String defaultUrl, String logoutUrlPattern,
String matchers, boolean multiProfile, Throwable x) {
return unit -> {
SecurityLogic action = unit.get(SecurityLogic.class);
IExpectationSetters<Object> expect = expect(
action.perform(eq(unit.get(WebContext.class)), eq(unit.get(Config.class)),
isA(Pac4jGrantAccessAdapter.class), eq(unit.get(HttpActionAdapter.class)),
eq(defaultUrl), eq(logoutUrlPattern), eq(matchers), eq(multiProfile)));
if (x == null)
expect.andReturn(null);
else
expect.andThrow(x);
};
}
示例6: createNiceMockAndExpectNew
import org.easymock.IExpectationSetters; //导入方法依赖的package包/类
/**
* Convenience method for createNiceMock followed by expectNew.
*
* @param type
* The class that should be mocked.
* @param arguments
* The constructor arguments.
* @return A mock object of the same type as the mock.
* @throws Exception
*/
public static synchronized <T> T createNiceMockAndExpectNew(Class<T> type, Object... arguments) throws Exception {
T mock = createNiceMock(type);
IExpectationSetters<T> expectationSetters = expectNiceNew(type, arguments);
if (expectationSetters != null) {
expectationSetters.andReturn(mock);
}
return mock;
}