• 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.mockito.internal.util;
6 
7 import org.junit.Test;
8 import org.mockitousage.IMethods;
9 import org.mockitoutil.TestBase;
10 
11 import java.util.Date;
12 
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertTrue;
15 
16 public class ObjectMethodsGuruTest extends TestBase {
17 
18 
19     private interface HasCompareToButDoesNotImplementComparable {
compareTo(HasCompareToButDoesNotImplementComparable other)20         int compareTo(HasCompareToButDoesNotImplementComparable other);
21     }
22 
23     private interface HasCompare extends Comparable<HasCompare> {
foo(HasCompare other)24         int foo(HasCompare other);
compareTo(HasCompare other, String redHerring)25         int compareTo(HasCompare other, String redHerring);
compareTo(String redHerring)26         int compareTo(String redHerring);
compareTo(HasCompare redHerring)27         int compareTo(HasCompare redHerring);
28     }
29 
30     @Test
shouldKnowToStringMethod()31     public void shouldKnowToStringMethod() throws Exception {
32         assertFalse(ObjectMethodsGuru.isToStringMethod(Object.class.getMethod("equals", Object.class)));
33         assertFalse(ObjectMethodsGuru.isToStringMethod(IMethods.class.getMethod("toString", String.class)));
34         assertTrue(ObjectMethodsGuru.isToStringMethod(IMethods.class.getMethod("toString")));
35     }
36 
37 
38     @Test
shouldKnowCompareToMethod()39     public void shouldKnowCompareToMethod() throws Exception {
40         assertFalse(ObjectMethodsGuru.isCompareToMethod(Date.class.getMethod("toString")));
41         assertFalse(ObjectMethodsGuru.isCompareToMethod(HasCompare.class.getMethod("foo", HasCompare.class)));
42         assertFalse(ObjectMethodsGuru.isCompareToMethod(HasCompare.class.getMethod("compareTo", HasCompare.class, String.class)));
43         assertFalse(ObjectMethodsGuru.isCompareToMethod(HasCompare.class.getMethod("compareTo", String.class)));
44         assertFalse(ObjectMethodsGuru.isCompareToMethod(HasCompareToButDoesNotImplementComparable.class.getDeclaredMethod("compareTo", HasCompareToButDoesNotImplementComparable.class)));
45 
46         assertTrue(ObjectMethodsGuru.isCompareToMethod(HasCompare.class.getMethod("compareTo", HasCompare.class)));
47     }
48 }
49