1 /* 2 * Copyright (c) 2017 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockito.internal.creation; 6 7 import org.junit.Before; 8 import org.junit.Test; 9 import org.mockitoutil.TestBase; 10 11 import java.lang.reflect.Method; 12 13 import static org.junit.Assert.assertFalse; 14 import static org.junit.Assert.assertTrue; 15 16 public class DelegatingMethodTest extends TestBase { 17 18 private Method someMethod, otherMethod; 19 private DelegatingMethod delegatingMethod; 20 21 @Before 22 public void setup() throws Exception { 23 someMethod = Something.class.getMethod("someMethod", Object.class); 24 otherMethod = Something.class.getMethod("otherMethod", Object.class); 25 delegatingMethod = new DelegatingMethod(someMethod); 26 } 27 28 @Test 29 public void equals_should_return_false_when_not_equal() throws Exception { 30 DelegatingMethod notEqual = new DelegatingMethod(otherMethod); 31 assertFalse(delegatingMethod.equals(notEqual)); 32 } 33 34 @Test 35 public void equals_should_return_true_when_equal() throws Exception { 36 DelegatingMethod equal = new DelegatingMethod(someMethod); 37 assertTrue(delegatingMethod.equals(equal)); 38 } 39 40 @Test 41 public void equals_should_return_true_when_self() throws Exception { 42 assertTrue(delegatingMethod.equals(delegatingMethod)); 43 } 44 45 @Test 46 public void equals_should_return_false_when_not_equal_to_method() throws Exception { 47 assertFalse(delegatingMethod.equals(otherMethod)); 48 } 49 50 @Test 51 public void equals_should_return_true_when_equal_to_method() throws Exception { 52 assertTrue(delegatingMethod.equals(someMethod)); 53 } 54 55 private interface Something { 56 57 Object someMethod(Object param); 58 59 Object otherMethod(Object param); 60 } 61 } 62