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.internal.invocation.UnusedStubsFinder;
      9 import org.mockito.internal.invocation.finder.AllInvocationsFinder;
     10 import org.mockito.internal.listeners.CollectCreatedMocks;
     11 import org.mockito.internal.progress.MockingProgress;
     12 import org.mockito.internal.progress.ThreadSafeMockingProgress;
     13 import org.mockito.invocation.Invocation;
     14 
     15 import java.util.LinkedList;
     16 import java.util.List;
     17 
     18 @SuppressWarnings("unchecked")
     19 public class WarningsCollector {
     20 
     21     List createdMocks;
     22 
     23     public WarningsCollector() {
     24         createdMocks = new LinkedList();
     25         MockingProgress progress = new ThreadSafeMockingProgress();
     26         progress.setListener(new CollectCreatedMocks(createdMocks));
     27     }
     28 
     29     public String getWarnings() {
     30         List<Invocation> unused = new UnusedStubsFinder().find(createdMocks);
     31         List<Invocation> all = new AllInvocationsFinder().find(createdMocks);
     32         List<InvocationMatcher> allInvocationMatchers = InvocationMatcher.createFrom(all);
     33 
     34         String warnings = new WarningsPrinterImpl(unused, allInvocationMatchers, false).print();
     35 
     36         return warnings;
     37     }
     38 }