微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.mockito.listeners.MethodInvocationReport的实例源码

项目: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));
    }
}
项目:monarch    文件OffheapStoredobjectAddressstackJUnitTest.java   
@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");
    }
}
项目:astor    文件MockHandlerImpltest.java   
@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) {
}
项目:springmock    文件MockitodoubleFactoryTest.java   
@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) {
}
项目:spring-boot-concourse    文件MockReset.java   
@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 举报,一经查实,本站将立刻删除。