|
8 | 8 | import org.mockito.internal.creation.AbstractMockMakerTest;
|
9 | 9 |
|
10 | 10 | import java.io.Serializable;
|
| 11 | +import java.lang.reflect.InvocationHandler; |
11 | 12 | import java.lang.reflect.Proxy;
|
12 | 13 |
|
13 | 14 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -47,5 +48,54 @@ public void should_discover_mockable_input() {
|
47 | 48 | assertThat(mockMaker.isTypeMockable(SomeInterface.class).mockable()).isTrue();
|
48 | 49 | }
|
49 | 50 |
|
| 51 | + @Test |
| 52 | + public void can_compute_hash_code() throws Throwable { |
| 53 | + SomeInterface proxy = |
| 54 | + mockMaker.createMock(settingsFor(SomeInterface.class), dummyHandler()); |
| 55 | + |
| 56 | + InvocationHandler handler = Proxy.getInvocationHandler(proxy); |
| 57 | + |
| 58 | + assertThat(handler.invoke(proxy, Object.class.getMethod("hashCode"), new Object[0])) |
| 59 | + .isEqualTo(System.identityHashCode(proxy)); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void can_compute_equality() throws Throwable { |
| 64 | + SomeInterface proxy = |
| 65 | + mockMaker.createMock(settingsFor(SomeInterface.class), dummyHandler()); |
| 66 | + |
| 67 | + InvocationHandler handler = Proxy.getInvocationHandler(proxy); |
| 68 | + |
| 69 | + assertThat( |
| 70 | + handler.invoke( |
| 71 | + proxy, |
| 72 | + Object.class.getMethod("equals", Object.class), |
| 73 | + new Object[] {proxy})) |
| 74 | + .isEqualTo(true); |
| 75 | + assertThat( |
| 76 | + handler.invoke( |
| 77 | + proxy, |
| 78 | + Object.class.getMethod("equals", Object.class), |
| 79 | + new Object[] {null})) |
| 80 | + .isEqualTo(false); |
| 81 | + assertThat( |
| 82 | + handler.invoke( |
| 83 | + proxy, |
| 84 | + Object.class.getMethod("equals", Object.class), |
| 85 | + new Object[] {new Object()})) |
| 86 | + .isEqualTo(false); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void can_invoke_toString() throws Throwable { |
| 91 | + SomeInterface proxy = |
| 92 | + mockMaker.createMock(settingsFor(SomeInterface.class), dummyHandler()); |
| 93 | + |
| 94 | + InvocationHandler handler = Proxy.getInvocationHandler(proxy); |
| 95 | + |
| 96 | + assertThat(handler.invoke(proxy, Object.class.getMethod("toString"), new Object[0])) |
| 97 | + .isNull(); |
| 98 | + } |
| 99 | + |
50 | 100 | interface SomeInterface {}
|
51 | 101 | }
|
0 commit comments