1 /* 2 * Copyright (c) 2016 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockito.internal.junit; 6 7 import org.mockito.internal.invocation.finder.AllInvocationsFinder; 8 import org.mockito.invocation.Invocation; 9 import org.mockito.stubbing.Stubbing; 10 11 /** 12 * For given mocks, finds stubbing arg mismatches 13 */ 14 class ArgMismatchFinder { 15 getStubbingArgMismatches(Iterable<?> mocks)16 StubbingArgMismatches getStubbingArgMismatches(Iterable<?> mocks) { 17 StubbingArgMismatches mismatches = new StubbingArgMismatches(); 18 for (Invocation i : AllInvocationsFinder.find(mocks)) { 19 if (i.stubInfo() != null) { 20 continue; 21 } 22 for (Stubbing stubbing : AllInvocationsFinder.findStubbings(mocks)) { 23 //method name & mock matches 24 if (!stubbing.wasUsed() && stubbing.getInvocation().getMock() == i.getMock() 25 && stubbing.getInvocation().getMethod().getName().equals(i.getMethod().getName())) { 26 mismatches.add(i, stubbing.getInvocation()); 27 } 28 } 29 } 30 return mismatches; 31 } 32 } 33