use of org.mockito.invocation.Invocation in project mockito by mockito.
the class OnlyTest method shouldMarkAsVerified.
@Test
public void shouldMarkAsVerified() {
//given
Invocation invocation = new InvocationBuilder().toInvocation();
assertFalse(invocation.isVerified());
//when
only.verify(new VerificationDataStub(new InvocationMatcher(invocation), invocation));
//then
assertTrue(invocation.isVerified());
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class InvocationsFinderTest method shouldFindInvocationWithTheSameMethod.
@Test
public void shouldFindInvocationWithTheSameMethod() throws Exception {
Invocation overloadedDifferentMethod = new InvocationBuilder().differentMethod().arg("test").toInvocation();
invocations.add(overloadedDifferentMethod);
Invocation found = InvocationsFinder.findSimilarInvocation(invocations, new InvocationMatcher(overloadedDifferentMethod));
assertSame(found, overloadedDifferentMethod);
}
use of org.mockito.invocation.Invocation 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.invocation.Invocation in project mockito by mockito.
the class WarningsFinder method find.
public void find(FindingsListener findingsListener) {
List<Invocation> unusedStubs = new LinkedList<Invocation>(this.baseUnusedStubs);
List<InvocationMatcher> allInvocations = new LinkedList<InvocationMatcher>(this.baseAllInvocations);
Iterator<Invocation> unusedIterator = unusedStubs.iterator();
while (unusedIterator.hasNext()) {
Invocation unused = unusedIterator.next();
Iterator<InvocationMatcher> unstubbedIterator = allInvocations.iterator();
while (unstubbedIterator.hasNext()) {
InvocationMatcher unstubbed = unstubbedIterator.next();
if (unstubbed.hasSimilarMethod(unused)) {
findingsListener.foundStubCalledWithDifferentArgs(unused, unstubbed);
unusedIterator.remove();
unstubbedIterator.remove();
}
}
}
for (Invocation i : unusedStubs) {
findingsListener.foundUnusedStub(i);
}
for (InvocationMatcher i : allInvocations) {
findingsListener.foundUnstubbed(i);
}
}
use of org.mockito.invocation.Invocation in project mockito by mockito.
the class Reporter method formatUnncessaryStubbingException.
public static UnnecessaryStubbingException formatUnncessaryStubbingException(Class<?> testClass, Collection<Invocation> unnecessaryStubbings) {
StringBuilder stubbings = new StringBuilder();
int count = 1;
for (Invocation u : unnecessaryStubbings) {
stubbings.append("\n ").append(count++).append(". ").append(u.getLocation());
}
String heading = (testClass != null) ? "Unnecessary stubbings detected in test class: " + testClass.getSimpleName() : "Unnecessary stubbings detected.";
return new UnnecessaryStubbingException(join(heading, "Clean & maintainable test code requires zero unnecessary code.", "Following stubbings are unnecessary (click to navigate to relevant line of code):" + stubbings, "Please remove unnecessary stubbings or use 'silent' option. More info: javadoc for UnnecessaryStubbingException class."));
}
Aggregations