Java 类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    文件: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
}