本文整理了Java中org.mockito.MockSettings.stubOnly()
方法的一些代码示例,展示了MockSettings.stubOnly()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockSettings.stubOnly()
方法的具体详情如下:
包路径:org.mockito.MockSettings
类名称:MockSettings
方法名:stubOnly
[英]A stub-only mock does not record method invocations, thus saving memory but disallowing verification of invocations.
Example:
List stubOnly = mock(List.class, withSettings().stubOnly());
[中]只有存根的模拟不记录方法调用,因此节省内存,但不允许验证调用。
例子:
List stubOnly = mock(List.class, withSettings().stubOnly());
代码示例来源:origin: org.mockito/mockito-core
public static Object processAnnotationForMock(Mock annotation, Class<?> type, String name) {
MockSettings mockSettings = Mockito.withSettings();
if (annotation.extraInterfaces().length > 0) { // never null
mockSettings.extraInterfaces(annotation.extraInterfaces());
}
if ("".equals(annotation.name())) {
mockSettings.name(name);
} else {
mockSettings.name(annotation.name());
}
if(annotation.serializable()){
mockSettings.serializable();
}
if(annotation.stubOnly()){
mockSettings.stubOnly();
}
if(annotation.lenient()){
mockSettings.lenient();
}
// see @Mock answer default value
mockSettings.defaultAnswer(annotation.answer());
return Mockito.mock(type, mockSettings);
}
}
代码示例来源:origin: jerrinot/subzero
public static <T> T deserialize(StreamSerializer<T> serializer, byte[] blob) throws IOException {
InternalSerializationService mockSerializationService = mock(InternalSerializationService.class, withSettings().stubOnly());
ObjectDataInputStream odis = new ObjectDataInputStream(new ByteArrayInputStream(blob), mockSerializationService);
return serializer.read(odis);
}
代码示例来源:origin: jerrinot/subzero
public static <T> byte[] serialize(StreamSerializer<T> serializer, T input) throws IOException{
ByteArrayOutputStream os = new ByteArrayOutputStream();
InternalSerializationService mockSerializationService = mock(InternalSerializationService.class, withSettings().stubOnly());
ObjectDataOutputStream odos = new ObjectDataOutputStream(os, mockSerializationService);
serializer.write(odos, input);
return os.toByteArray();
}
代码示例来源:origin: teiid/teiid
private ResultSetImpl helpExecuteQuery(int fetchSize, int totalResults, int cursorType) throws SQLException, TeiidProcessingException {
StatementImpl statement = createMockStatement(cursorType, withSettings().stubOnly());
return TestAllResultsImpl.helpTestBatching(statement, fetchSize, Math.min(fetchSize, totalResults), totalResults);
}
代码示例来源:origin: tmurakami/dexopener
.will(answer((src, out) -> {
dalvik.system.DexFile file = mock(dalvik.system.DexFile.class,
withSettings().stubOnly());
given(file.loadClass(anyString(), eq(loader))).willReturn(MyClass.class);
return file;
代码示例来源:origin: tmurakami/dexopener
@Test(expected = IllegalStateException.class)
public void should_throw_IllegalStateException_if_already_installed() {
ClassInjector injector = mock(ClassInjector.class, withSettings().stubOnly());
given(instrumentation.getTargetContext()).willReturn(context);
ClassLoader loader = new ClassLoader(injector) {
};
given(context.getClassLoader()).willReturn(loader);
DexOpener.install(instrumentation);
}
内容来源于网络,如有侵权,请联系作者删除!