Home | History | Annotate | Download | only in bugs
      1 package org.mockitousage.bugs;
      2 
      3 import org.junit.Test;
      4 import org.mockito.exceptions.misusing.WrongTypeOfReturnValue;
      5 import org.mockito.exceptions.verification.NoInteractionsWanted;
      6 import org.mockito.invocation.InvocationOnMock;
      7 import org.mockito.stubbing.Answer;
      8 
      9 import static org.mockito.Mockito.mock;
     10 import static org.mockito.Mockito.verifyZeroInteractions;
     11 
     12 public 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