Home | History | Annotate | Download | only in util
      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 
     13     private ObjectMethodsGuru() {
     14     }
     15 
     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                m.getName().equals("toString");
     21     }
     22 
     23     public static boolean isCompareToMethod(Method method) {
     24         return Comparable.class.isAssignableFrom(method.getDeclaringClass())
     25                 && method.getName().equals("compareTo")
     26                 && method.getParameterTypes().length == 1
     27                 && method.getParameterTypes()[0] == method.getDeclaringClass();
     28     }
     29 }
     30