WarningsFinderTest.java revision 2637d96c202372854a7c71466ddcc6e90fc4fc53
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.junit.Test;
8import org.mockito.Mock;
9import org.mockito.internal.invocation.InvocationBuilder;
10import org.mockito.internal.invocation.InvocationMatcher;
11import org.mockito.invocation.Invocation;
12import org.mockitousage.IMethods;
13import org.mockitoutil.TestBase;
14
15import java.util.Arrays;
16
17import static java.util.Arrays.asList;
18import static org.mockito.Mockito.only;
19import static org.mockito.Mockito.verify;
20
21public 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