1/* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5package org.mockito.internal.debugging; 6 7import org.mockito.internal.invocation.InvocationMatcher; 8import org.mockito.internal.invocation.UnusedStubsFinder; 9import org.mockito.internal.invocation.finder.AllInvocationsFinder; 10import org.mockito.internal.listeners.CollectCreatedMocks; 11import org.mockito.internal.progress.MockingProgress; 12import org.mockito.internal.progress.ThreadSafeMockingProgress; 13import org.mockito.invocation.Invocation; 14 15import java.util.LinkedList; 16import java.util.List; 17 18@SuppressWarnings("unchecked") 19public 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}