/** * Checks whether the given method was called with the arguments given in expectedParamValues. * * @param name method name * @param expectedParamValues parameter values * @return true if the method was called with these parameters, false otherwise */ public boolean wasMethodCalled(String name, Object... expectedParamValues) { MethodInvocation expected = new MethodInvocation(name, expectedParamValues); for (MethodInvocation invocation : invocations) { if (invocation.equals(expected)) { return true; } } return false; }
/** * Checks whether the given methods were called in the given order. * * @param methodInvocations methods that should have been called * @return true if the method with the given parameters was called, false otherwise */ public boolean wereMethodsCalledInOrder(MethodInvocation... methodInvocations) { if (methodInvocations == null || methodInvocations.length == 0) return true; int i = 0; for (MethodInvocation invocation : invocations) { if (invocation.equals(methodInvocations[i])) { i++; if (i >= methodInvocations.length) return true; } } return false; }