项目:astor
文件:InvocationListenerCallbackTest.java
@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));
}
}
@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");
}
项目:evosuite
文件:EvoInvocationListener.java
@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);
}
}
项目:astor
文件:VerboseMockInvocationLogger.java
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
printHeader();
printStubInfo(methodInvocationReport);
printInvocation(methodInvocationReport.getInvocation());
printReturnedValueOrThrowable(methodInvocationReport);
printFooter();
}
项目:astor
文件:VerboseMockInvocationLogger.java
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);
}
}
项目:astor
文件:ListenersLostOnResetMockTest.java
@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));
}
项目:astor
文件:InvocationNotifierHandlerTest.java
@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");
}
}
@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);
}
项目:mockito-async
文件:Await.java
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();
}
}
}
});
}
项目:springmock
文件:InvocationListenersTest.java
@Override
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
}
@Override
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
}
项目:springmock
文件:MockitoSamplesApplicationTests.java
@Override
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
System.out.println("" +
"Calling method " + methodInvocationReport.getInvocation().toString() +
" and result is " + methodInvocationReport.getReturnedValue());
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:MockReset.java
@Override
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
}
@Override
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
}
项目:astor
文件:VerboseMockInvocationLogger.java
private void printStubInfo(MethodInvocationReport methodInvocationReport) {
if (methodInvocationReport.getLocationOfStubbing() != null) {
printlnIndented("stubbed: " + methodInvocationReport.getLocationOfStubbing());
}
}
项目:astor
文件:InvocationListenerCallbackTest.java
public void reportInvocation(MethodInvocationReport mcr) {
this.invocation = mcr.getInvocation();
this.returnValue = mcr.getReturnedValue();
this.locationOfStubbing = mcr.getLocationOfStubbing();
}
项目:astor
文件:InvocationNotifierHandlerTest.java
public void reportInvocation(MethodInvocationReport methodInvocationReport) {
// nop
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。