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 java.lang.reflect.Method; 8 import org.mockito.internal.creation.DelegatingMethod; 9 import org.mockito.internal.invocation.MockitoMethod; 10 11 public class ObjectMethodsGuru{ 12 ObjectMethodsGuru()13 private ObjectMethodsGuru() { 14 } 15 isToStringMethod(Method method)16 public static boolean isToStringMethod(Method method) { 17 MockitoMethod m = new DelegatingMethod(method); 18 return m.getReturnType() == String.class && 19 m.getParameterTypes().length == 0 && 20 "toString".equals(m.getName()); 21 } 22 isCompareToMethod(Method method)23 public static boolean isCompareToMethod(Method method) { 24 return Comparable.class.isAssignableFrom(method.getDeclaringClass()) 25 && "compareTo".equals(method.getName()) 26 && method.getParameterTypes().length == 1 27 && method.getParameterTypes()[0] == method.getDeclaringClass(); 28 } 29 } 30