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.MockitoDebugger; 8 import org.mockito.internal.invocation.UnusedStubsFinder; 9 import org.mockito.internal.invocation.finder.AllInvocationsFinder; 10 import org.mockito.invocation.Invocation; 11 12 import java.util.List; 13 14 import static java.util.Arrays.asList; 15 16 public class MockitoDebuggerImpl implements MockitoDebugger { 17 18 private final UnusedStubsFinder unusedStubsFinder = new UnusedStubsFinder(); 19 20 /** 21 * TODO: when MockitoDebugger is deleted, delete this implementation, too 22 */ 23 @Deprecated printInvocations(Object .... mocks)24 public String printInvocations(Object ... mocks) { 25 String out = ""; 26 List<Invocation> invocations = AllInvocationsFinder.find(asList(mocks)); 27 out += line("********************************"); 28 out += line("*** Mockito interactions log ***"); 29 out += line("********************************"); 30 for(Invocation i:invocations) { 31 out += line(i.toString()); 32 out += line(" invoked: " + i.getLocation()); 33 if (i.stubInfo() != null) { 34 out += line(" stubbed: " + i.stubInfo().stubbedAt().toString()); 35 } 36 } 37 38 invocations = unusedStubsFinder.find(asList(mocks)); 39 if (invocations.isEmpty()) { 40 return print(out); 41 } 42 out += line("********************************"); 43 out += line("*** Unused stubs ***"); 44 out += line("********************************"); 45 46 for(Invocation i:invocations) { 47 out += line(i.toString()); 48 out += line(" stubbed: " + i.getLocation()); 49 } 50 return print(out); 51 } 52 line(String text)53 private String line(String text) { 54 return text + "\n"; 55 } 56 print(String out)57 private String print(String out) { 58 System.out.println(out); 59 return out; 60 } 61 } 62