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
}

相关文章

买水果
比较全面的redis工具类
gson 反序列化到多态子类
java 版本的 mb_strwidth
JAVA 反转字符串的最快方法,大概比StringBuffer.reverse()性...
com.google.gson.internal.bind.ArrayTypeAdapter的实例源码...