Home | History | Annotate | Download | only in debugging
      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 @SuppressWarnings("unchecked")
     15 public class WarningsFinder {
     16     private final List<Invocation> baseUnusedStubs;
     17     private final List<InvocationMatcher> baseAllInvocations;
     18 
     19     public WarningsFinder(List<Invocation> unusedStubs, List<InvocationMatcher> allInvocations) {
     20         this.baseUnusedStubs = unusedStubs;
     21         this.baseAllInvocations = allInvocations;
     22     }
     23 
     24     public void find(FindingsListener findingsListener) {
     25         List<Invocation> unusedStubs = new LinkedList(this.baseUnusedStubs);
     26         List<InvocationMatcher> allInvocations = new LinkedList(this.baseAllInvocations);
     27 
     28         Iterator<Invocation> unusedIterator = unusedStubs.iterator();
     29         while(unusedIterator.hasNext()) {
     30             Invocation unused = unusedIterator.next();
     31             Iterator<InvocationMatcher> unstubbedIterator = allInvocations.iterator();
     32             while(unstubbedIterator.hasNext()) {
     33                 InvocationMatcher unstubbed = unstubbedIterator.next();
     34                 if(unstubbed.hasSimilarMethod(unused)) {
     35                     findingsListener.foundStubCalledWithDifferentArgs(unused, unstubbed);
     36                     unusedIterator.remove();
     37                     unstubbedIterator.remove();
     38                 }
     39             }
     40         }
     41 
     42         for (Invocation i : unusedStubs) {
     43             findingsListener.foundUnusedStub(i);
     44         }
     45 
     46         for (InvocationMatcher i : allInvocations) {
     47             findingsListener.foundUnstubbed(i);
     48         }
     49     }
     50 }
     51