• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 package org.mockito.internal.debugging;
6 
7 import org.mockito.internal.invocation.InvocationMatcher;
8 import org.mockito.invocation.Invocation;
9 
10 import java.util.Iterator;
11 import java.util.LinkedList;
12 import java.util.List;
13 
14 public class WarningsFinder {
15     private final List<Invocation> baseUnusedStubs;
16     private final List<InvocationMatcher> baseAllInvocations;
17 
WarningsFinder(List<Invocation> unusedStubs, List<InvocationMatcher> allInvocations)18     public WarningsFinder(List<Invocation> unusedStubs, List<InvocationMatcher> allInvocations) {
19         this.baseUnusedStubs = unusedStubs;
20         this.baseAllInvocations = allInvocations;
21     }
22 
find(FindingsListener findingsListener)23     public void find(FindingsListener findingsListener) {
24         List<Invocation> unusedStubs = new LinkedList<Invocation>(this.baseUnusedStubs);
25         List<InvocationMatcher> allInvocations = new LinkedList<InvocationMatcher>(this.baseAllInvocations);
26 
27         Iterator<Invocation> unusedIterator = unusedStubs.iterator();
28         while(unusedIterator.hasNext()) {
29             Invocation unused = unusedIterator.next();
30             Iterator<InvocationMatcher> unstubbedIterator = allInvocations.iterator();
31             while(unstubbedIterator.hasNext()) {
32                 InvocationMatcher unstubbed = unstubbedIterator.next();
33                 if(unstubbed.hasSimilarMethod(unused)) {
34                     findingsListener.foundStubCalledWithDifferentArgs(unused, unstubbed);
35                     unusedIterator.remove();
36                     unstubbedIterator.remove();
37                 }
38             }
39         }
40 
41         for (Invocation i : unusedStubs) {
42             findingsListener.foundUnusedStub(i);
43         }
44 
45         for (InvocationMatcher i : allInvocations) {
46             findingsListener.foundUnstubbed(i);
47         }
48     }
49 }
50