1/* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5package org.mockito.internal.util; 6 7import org.mockito.internal.creation.DelegatingMethod; 8import org.mockito.internal.invocation.MockitoMethod; 9 10import java.io.Serializable; 11import java.lang.reflect.Method; 12 13public class ObjectMethodsGuru implements Serializable { 14 15 private static final long serialVersionUID = -1286718569065470494L; 16 17 public boolean isToString(Method method) { 18 return isToString(new DelegatingMethod(method)); 19 } 20 21 public boolean isToString(MockitoMethod method) { 22 return method.getReturnType() == String.class 23 && method.getParameterTypes().length == 0 24 && method.getName().equals("toString"); 25 } 26 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 33 public boolean isHashCodeMethod(Method method) { 34 return method.getName().equals("hashCode") 35 && method.getParameterTypes().length == 0; 36 } 37 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}