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.junit.Test;
      8 import org.mockito.Mock;
      9 import org.mockito.internal.invocation.InvocationBuilder;
     10 import org.mockito.internal.invocation.InvocationMatcher;
     11 import org.mockito.invocation.Invocation;
     12 import org.mockitousage.IMethods;
     13 import org.mockitoutil.TestBase;
     14 
     15 import java.util.Arrays;
     16 
     17 import static java.util.Arrays.asList;
     18 import static org.mockito.Mockito.only;
     19 import static org.mockito.Mockito.verify;
     20 
     21 public class WarningsFinderTest extends TestBase {
     22 
     23     @Mock private IMethods mock;
     24     @Mock private FindingsListener listener;
     25 
     26     @Test
     27     public void shouldPrintUnusedStub() {
     28         // given
     29         Invocation unusedStub = new InvocationBuilder().simpleMethod().toInvocation();
     30 
     31         // when
     32         WarningsFinder finder = new WarningsFinder(asList(unusedStub), Arrays.<InvocationMatcher>asList());
     33         finder.find(listener);
     34 
     35         // then
     36         verify(listener, only()).foundUnusedStub(unusedStub);
     37     }
     38 
     39     @Test
     40     public void shouldPrintUnstubbedInvocation() {
     41         // given
     42         InvocationMatcher unstubbedInvocation = new InvocationBuilder().differentMethod().toInvocationMatcher();
     43 
     44         // when
     45         WarningsFinder finder = new WarningsFinder(Arrays.<Invocation>asList(), Arrays.<InvocationMatcher>asList(unstubbedInvocation));
     46         finder.find(listener);
     47 
     48         // then
     49         verify(listener, only()).foundUnstubbed(unstubbedInvocation);
     50     }
     51 
     52     @Test
     53     public void shouldPrintStubWasUsedWithDifferentArgs() {
     54         // given
     55         Invocation stub = new InvocationBuilder().arg("foo").mock(mock).toInvocation();
     56         InvocationMatcher wrongArg = new InvocationBuilder().arg("bar").mock(mock).toInvocationMatcher();
     57 
     58         // when
     59         WarningsFinder finder = new WarningsFinder(Arrays.<Invocation> asList(stub), Arrays.<InvocationMatcher> asList(wrongArg));
     60         finder.find(listener);
     61 
     62         // then
     63         verify(listener, only()).foundStubCalledWithDifferentArgs(stub, wrongArg);
     64     }
     65 }
     66