本文整理汇总了Java中org.mockito.listeners.MethodInvocationReport类的典型用法代码示例。如果您正苦于以下问题:Java MethodInvocationReport类的具体用法?Java MethodInvocationReport怎么用?Java MethodInvocationReport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodInvocationReport类属于org.mockito.listeners包,在下文中一共展示了MethodInvocationReport类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: should_call_all_listener_when_mock_throws_exception
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
@Test
public void should_call_all_listener_when_mock_throws_exception() throws Exception {
// given
InvocationListener listener1 = mock(InvocationListener.class, "listener1");
InvocationListener listener2 = mock(InvocationListener.class, "listener2");
Foo foo = mock(Foo.class, withSettings().invocationListeners(listener1, listener2));
doThrow(new OvenNotWorking()).when(foo).doSomething("cook");
// when
try {
foo.doSomething("cook");
fail("Exception expected.");
} catch (OvenNotWorking actualException) {
// then
InOrder orderedVerify = inOrder(listener1, listener2);
orderedVerify.verify(listener1).reportInvocation(any(MethodInvocationReport.class));
orderedVerify.verify(listener2).reportInvocation(any(MethodInvocationReport.class));
}
}
示例2: defaultStackLogsNothing
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
@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");
}
示例3: reportInvocation
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
@Override
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
if(! active){
return;
}
DescribedInvocation di = methodInvocationReport.getInvocation();
MethodDescriptor md = null;
if(di instanceof InvocationOnMock){
InvocationOnMock impl = (InvocationOnMock) di;
Method method = impl.getMethod();
md = new MethodDescriptor(method, retvalType);
} else {
//hopefully it should never happen
md = getMethodDescriptor_old(di);
}
if(md.getMethodName().equals("finalize")){
//ignore it, otherwise if we mock it, we ll end up in a lot of side effects... :(
return;
}
if(onlyMockAbstractMethods() && !md.getGenericMethod().isAbstract()) {
return;
}
synchronized (map){
MethodDescriptor current = map.get(md.getID());
if(current == null){
current = md;
}
current.increaseCounter();
map.put(md.getID(),current);
}
}
示例4: reportInvocation
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
printHeader();
printStubInfo(methodInvocationReport);
printInvocation(methodInvocationReport.getInvocation());
printReturnedValueOrThrowable(methodInvocationReport);
printFooter();
}
示例5: printReturnedValueOrThrowable
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
private void printReturnedValueOrThrowable(MethodInvocationReport methodInvocationReport) {
if (methodInvocationReport.threwException()) {
String message = methodInvocationReport.getThrowable().getMessage() == null ? "" : " with message " + methodInvocationReport.getThrowable().getMessage();
printlnIndented("has thrown: " + methodInvocationReport.getThrowable().getClass() + message);
} else {
String type = (methodInvocationReport.getReturnedValue() == null) ? "" : " (" + methodInvocationReport.getReturnedValue().getClass().getName() + ")";
printlnIndented("has returned: \"" + methodInvocationReport.getReturnedValue() + "\"" + type);
}
}
示例6: listener
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
@Test
public void listener() throws Exception {
InvocationListener invocationListener = mock(InvocationListener.class);
List mockedList = mock(List.class, withSettings().invocationListeners(invocationListener));
reset(mockedList);
mockedList.clear();
verify(invocationListener).reportInvocation(any(MethodInvocationReport.class));
}
示例7: should_report_listener_exception
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
@Test
public void should_report_listener_exception() throws Throwable {
willThrow(new NullPointerException()).given(customListener).reportInvocation(any(MethodInvocationReport.class));
try {
notifier.handle(invocation);
fail();
} catch (MockitoException me) {
assertThat(me.getMessage())
.contains("invocation listener")
.contains("CustomListener")
.contains("threw an exception")
.contains("NullPointerException");
}
}
示例8: shouldThrowMockitoExceptionWhenInvocationHandlerThrowsAnything
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
@Test(expected = MockitoException.class)
public void shouldThrowMockitoExceptionWhenInvocationHandlerThrowsAnything() throws Throwable {
// given
InvocationListener throwingListener = mock(InvocationListener.class);
doThrow(new Throwable()).when(throwingListener).reportInvocation(any(MethodInvocationReport.class));
MockHandlerImpl<?> handler = createCorrectlyStubbedHandler(throwingListener);
// when
handler.handle(invocation);
}
示例9: async
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
public static MockSettings async(MockSettings settings) {
return settings.invocationListeners(new InvocationListener() {
@Override
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
DescribedInvocation invocation = methodInvocationReport.getInvocation();
if (invocation instanceof InvocationOnMock) {
Object mock = ((InvocationOnMock) invocation).getMock();
synchronized (mock) {
mock.notifyAll();
}
}
}
});
}
示例10: reportInvocation
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
@Override
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
}
示例11: reportInvocation
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
@Override
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
System.out.println("" +
"Calling method " + methodInvocationReport.getInvocation().toString() +
" and result is " + methodInvocationReport.getReturnedValue());
}
示例12: printStubInfo
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
private void printStubInfo(MethodInvocationReport methodInvocationReport) {
if (methodInvocationReport.getLocationOfStubbing() != null) {
printlnIndented("stubbed: " + methodInvocationReport.getLocationOfStubbing());
}
}
示例13: reportInvocation
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
public void reportInvocation(MethodInvocationReport mcr) {
this.invocation = mcr.getInvocation();
this.returnValue = mcr.getReturnedValue();
this.locationOfStubbing = mcr.getLocationOfStubbing();
}
示例14: reportInvocation
import org.mockito.listeners.MethodInvocationReport; //导入依赖的package包/类
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
// nop
}