• 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.mockito.internal.creation.DelegatingMethod;
8 import org.mockito.internal.invocation.MockitoMethod;
9 
10 import java.io.Serializable;
11 import java.lang.reflect.Method;
12 
13 public class ObjectMethodsGuru implements Serializable {
14 
15     private static final long serialVersionUID = -1286718569065470494L;
16 
isToString(Method method)17     public boolean isToString(Method method) {
18         return isToString(new DelegatingMethod(method));
19     }
20 
isToString(MockitoMethod method)21     public boolean isToString(MockitoMethod method) {
22         return method.getReturnType() == String.class
23                 && method.getParameterTypes().length == 0
24                 && method.getName().equals("toString");
25     }
26 
isEqualsMethod(Method method)27     public boolean isEqualsMethod(Method method) {
28         return method.getName().equals("equals")
29                 && method.getParameterTypes().length == 1
30                 && method.getParameterTypes()[0] == Object.class;
31     }
32 
isHashCodeMethod(Method method)33     public boolean isHashCodeMethod(Method method) {
34         return method.getName().equals("hashCode")
35                 && method.getParameterTypes().length == 0;
36     }
37 
isCompareToMethod(Method method)38     public boolean isCompareToMethod(Method method) {
39         return Comparable.class.isAssignableFrom(method.getDeclaringClass())
40                 && method.getName().equals("compareTo")
41                 && method.getParameterTypes().length == 1
42                 && method.getParameterTypes()[0] == method.getDeclaringClass();
43     }
44 }