1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 
6 package org.mockitousage.misuse;
7 
8 import org.junit.After;
9 import org.junit.Test;
10 import org.mockito.InOrder;
11 import org.mockito.Mock;
12 import org.mockito.exceptions.base.MockitoException;
13 import org.mockitoutil.TestBase;
14 
15 import java.util.List;
16 
17 import static org.junit.Assert.fail;
18 import static org.assertj.core.api.Assertions.assertThat;
19 import static org.mockito.Mockito.inOrder;
20 import static org.mockito.Mockito.verify;
21 
22 public class RestrictedObjectMethodsTest extends TestBase {
23 
24     @Mock List<?> mock;
25 
26     @After
after()27     public void after() {
28         this.resetState();
29     }
30 
31     @Test
shouldScreamWhenVerifyToString()32     public void shouldScreamWhenVerifyToString() {
33         try {
34             verify(mock).toString();
35             fail();
36         } catch (MockitoException e) {
37             assertThat(e).hasMessageContaining("cannot verify");
38         }
39     }
40 
41     @Test
shouldBeSilentWhenVerifyHashCode()42     public void shouldBeSilentWhenVerifyHashCode() {
43         //because it leads to really weird behavior sometimes
44         //it's because cglib & my code can occasionelly call those methods
45         // and when user has verification started at that time there will be a mess
46         verify(mock).hashCode();
47     }
48 
49     @Test
shouldBeSilentWhenVerifyEquals()50     public void shouldBeSilentWhenVerifyEquals() {
51         //because it leads to really weird behavior sometimes
52         //it's because cglib & my code can occasionelly call those methods
53         // and when user has verification started at that time there will be a mess
54         verify(mock).equals(null);
55     }
56 
57     @Test
shouldBeSilentWhenVerifyEqualsInOrder()58     public void shouldBeSilentWhenVerifyEqualsInOrder() {
59         //because it leads to really weird behavior sometimes
60         //it's because cglib & my code can occasionelly call those methods
61         // and when user has verification started at that time there will be a mess
62         InOrder inOrder = inOrder(mock);
63         inOrder.verify(mock).equals(null);
64     }
65 }
66