本文整理了Java中org.mockito.MockSettings.invocationListeners()
方法的一些代码示例,展示了MockSettings.invocationListeners()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockSettings.invocationListeners()
方法的具体详情如下:
包路径:org.mockito.MockSettings
类名称:MockSettings
方法名:invocationListeners
[英]Registers a listener for method invocations on this mock. The listener is notified every time a method on this mock is called.
Multiple listeners may be added, but the same object is only added once. The order, in which the listeners are added, is not guaranteed to be the order in which the listeners are notified. Example:
List mockWithListener = mock(List.class, withSettings().invocationListeners(new YourInvocationListener()));
See the InvocationListener for more details.
[中]在此模拟上注册方法调用的侦听器。每次调用此模拟上的方法时,都会通知侦听器。
可以添加多个侦听器,但同一对象只添加一次。添加侦听器的顺序不能保证是通知侦听器的顺序。例子:
List mockWithListener = mock(List.class, withSettings().invocationListeners(new YourInvocationListener()));
有关更多详细信息,请参阅InvocationListener。
代码示例来源:origin: apache/geode
@Test
public void defaultStackLogsNothing() {
OffHeapStoredObjectAddressStack stack = new OffHeapStoredObjectAddressStack();
Logger lw = mock(Logger.class, withSettings().invocationListeners(new InvocationListener() {
@Override
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
fail("Unexpected invocation");
}
}));
stack.logSizes(lw, "should not be used");
}
代码示例来源:origin: EvoSuite/evosuite
protected MockSettings createMockSettings() {
return withSettings().invocationListeners(listener);
}
代码示例来源:origin: org.springframework.boot/spring-boot-test
/**
* Apply {@link MockReset} to existing {@link MockSettings settings}.
* @param reset the reset type
* @param settings the settings
* @return the configured settings
*/
public static MockSettings apply(MockReset reset, MockSettings settings) {
Assert.notNull(settings, "Settings must not be null");
if (reset != null && reset != NONE) {
settings.invocationListeners(new ResetInvocationListener(reset));
}
return settings;
}
代码示例来源:origin: EvoSuite/evosuite
protected MockSettings createMockSettings() {
return withSettings().defaultAnswer(CALLS_REAL_METHODS).invocationListeners(listener);
}
代码示例来源:origin: EvoSuite/evosuite
@Test
public void testFinal(){
/*
If no special instrumentation is done, we cannot handle final methods
*/
EvoInvocationListener listener = new EvoInvocationListener(AClassWithFinal.class);
AClassWithFinal foo = mock(AClassWithFinal.class, withSettings().invocationListeners(listener));
listener.activate();
foo.getFoo(); // this is not mocked
List<MethodDescriptor> list = listener.getCopyOfMethodDescriptors();
Assert.assertEquals(0, list.size());
}
代码示例来源:origin: EvoSuite/evosuite
@Test
public void testGenerics(){
ParameterizedTypeImpl type = new ParameterizedTypeImpl(AGenericClass.class, new Type[]{String.class}, null);
EvoInvocationListener listener = new EvoInvocationListener(type);
AGenericClass<String> aGenericClass = (AGenericClass<String>) mock(AGenericClass.class, withSettings().invocationListeners(listener));
when(aGenericClass.genericAsInput(any((Class<String>)type.getActualTypeArguments()[0]))).thenReturn(true);
listener.activate();
boolean b = aGenericClass.genericAsInput("foo");
assertTrue(b);
List<MethodDescriptor> list = listener.getCopyOfMethodDescriptors();
Assert.assertEquals(1, list.size());
}
代码示例来源:origin: EvoSuite/evosuite
Foo foo = mock(Foo.class, withSettings().invocationListeners(listener));
内容来源于网络,如有侵权,请联系作者删除!