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()));
}
}
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()?");
}
}
}
Aggregations