1package org.mockitousage.bugs;
2
3import org.junit.Test;
4import org.mockito.exceptions.misusing.WrongTypeOfReturnValue;
5import org.mockito.exceptions.verification.NoInteractionsWanted;
6import org.mockito.invocation.InvocationOnMock;
7import org.mockito.stubbing.Answer;
8
9import static org.mockito.Mockito.mock;
10import static org.mockito.Mockito.verifyZeroInteractions;
11
12public class ClassCastExOnVerifyZeroInteractionsTest {
13    public interface TestMock {
14        boolean m1();
15    }
16
17    @Test(expected = NoInteractionsWanted.class)
18    public void should_not_throw_ClassCastException_when_mock_verification_fails() {
19        TestMock test = mock(TestMock.class, new Answer<Object>() {
20            public Object answer(InvocationOnMock invocation) throws Throwable {
21                return false;
22            }
23        });
24        test.m1();
25        verifyZeroInteractions(test);
26    }
27
28    @Test(expected = WrongTypeOfReturnValue.class)
29    public void should_report_bogus_default_answer() throws Exception {
30        TestMock test = mock(TestMock.class, new Answer<Object>() {
31            public Object answer(InvocationOnMock invocation) throws Throwable {
32                return false;
33            }
34        });
35
36        test.toString();
37    }
38}
39