1package org.mockito.internal.verification;
2
3import org.junit.Before;
4import org.junit.Rule;
5import org.junit.Test;
6import org.junit.rules.ExpectedException;
7import org.mockito.Mock;
8import org.mockito.exceptions.base.MockitoAssertionError;
9import org.mockito.exceptions.verification.junit.ArgumentsAreDifferent;
10import org.mockito.verification.VerificationMode;
11
12import static org.hamcrest.CoreMatchers.is;
13import static org.mockito.Mockito.doThrow;
14import static org.mockito.Mockito.verify;
15import static org.mockito.MockitoAnnotations.initMocks;
16
17public class VerificationOverTimeImplTest {
18    @Mock
19    private VerificationMode delegate;
20    private VerificationOverTimeImpl impl;
21
22    @Rule
23    public ExpectedException exception = ExpectedException.none();
24
25    @Before
26    public void setUp() {
27        initMocks(this);
28        impl = new VerificationOverTimeImpl(10, 1000, delegate, true);
29    }
30
31    @Test
32    public void should_return_on_success() {
33        impl.verify(null);
34        verify(delegate).verify(null);
35    }
36
37    @Test
38    public void should_throw_mockito_assertion_error() {
39        MockitoAssertionError toBeThrown = new MockitoAssertionError("message");
40        exception.expect(is(toBeThrown));
41
42        doThrow(toBeThrown).when(delegate).verify(null);
43        impl.verify(null);
44    }
45
46    @Test
47    public void should_deal_with_junit_assertion_error() {
48        ArgumentsAreDifferent toBeThrown = new ArgumentsAreDifferent("message", "wanted", "actual");
49        exception.expect(is(toBeThrown));
50        exception.expectMessage("message");
51
52        doThrow(toBeThrown).when(delegate).verify(null);
53        impl.verify(null);
54    }
55
56    @Test
57    public void should_not_wrap_other_exceptions() {
58        RuntimeException toBeThrown = new RuntimeException();
59        exception.expect(is(toBeThrown));
60
61        doThrow(toBeThrown).when(delegate).verify(null);
62        impl.verify(null);
63    }
64}
65