Search in sources :

Example 1 with MockingDetails

use of org.mockito.MockingDetails in project hazelcast by hazelcast.

the class MapOperationProviderDelegatorTest method testDelegator.

@Test
public void testDelegator() throws Exception {
    Method[] methods = MapOperationProviderDelegator.class.getDeclaredMethods();
    // invoke all methods of MapOperationProviderDelegator
    for (Method method : methods) {
        if (isAbstract(method.getModifiers()) || isPrivate(method.getModifiers())) {
            continue;
        }
        Object[] parameters = getParameters(method);
        try {
            method.invoke(delegator, parameters);
        } catch (Exception e) {
            System.err.println(format("Could not invoke method %s: %s", method.getName(), e.getMessage()));
        }
    }
    // get a list of all method invocations from Mockito
    List<String> methodsCalled = new ArrayList<String>();
    MockingDetails mockingDetails = Mockito.mockingDetails(operationProvider);
    Collection<Invocation> invocations = mockingDetails.getInvocations();
    for (Invocation invocation : invocations) {
        methodsCalled.add(invocation.getMethod().getName());
    }
    // verify that all methods have been called on the delegated MapOperationProvider
    for (Method method : methods) {
        if (isAbstract(method.getModifiers()) || isPrivate(method.getModifiers())) {
            continue;
        }
        assertTrue(format("Method %s() should have been called", method.getName()), methodsCalled.contains(method.getName()));
    }
}
Also used : Invocation(org.mockito.invocation.Invocation) ArrayList(java.util.ArrayList) MockingDetails(org.mockito.MockingDetails) Method(java.lang.reflect.Method) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with MockingDetails

use of org.mockito.MockingDetails in project goci by EBISPOT.

the class CallChain method on.

public <M> Argument<T> on(M methodCall) {
    MockingDetails mockingDetails = Mockito.mockingDetails(template);
    if (mockingDetails.isMock()) {
        Collection<Invocation> invocations = mockingDetails.getInvocations();
        Method method = invocations.stream().reduce((current, next) -> next).get().getMethod();
        return new Argument<T>(template, method);
    } else {
        InvocationHandler h = Proxy.getInvocationHandler(template);
        if (h instanceof MethodLogger) {
            Method method = ((MethodLogger) h).getLastInvokedMethod();
            return new Argument<T>(template, method);
        } else {
            throw new IllegalArgumentException("Cannot refine the supplied template - " + "did you first call Filtering.template()?");
        }
    }
}
Also used : Invocation(org.mockito.invocation.Invocation) MockingDetails(org.mockito.MockingDetails) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler)

Aggregations

Method (java.lang.reflect.Method)2 MockingDetails (org.mockito.MockingDetails)2 Invocation (org.mockito.invocation.Invocation)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1