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