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