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.creation; 6 7import org.mockito.internal.invocation.MockitoMethod; 8 9import java.lang.reflect.Method; 10import java.lang.reflect.Modifier; 11 12public class DelegatingMethod implements MockitoMethod { 13 14 private final Method method; 15 16 public DelegatingMethod(Method method) { 17 assert method != null : "Method cannot be null"; 18 this.method = method; 19 } 20 21 public Class<?>[] getExceptionTypes() { 22 return method.getExceptionTypes(); 23 } 24 25 public Method getJavaMethod() { 26 return method; 27 } 28 29 public String getName() { 30 return method.getName(); 31 } 32 33 public Class<?>[] getParameterTypes() { 34 return method.getParameterTypes(); 35 } 36 37 public Class<?> getReturnType() { 38 return method.getReturnType(); 39 } 40 41 public boolean isVarArgs() { 42 return method.isVarArgs(); 43 } 44 45 public boolean isAbstract() { 46 return (method.getModifiers() & Modifier.ABSTRACT) != 0; 47 } 48 49 /** 50 * @return True if the input object is a DelegatingMethod which has an internal Method which is equal to the internal Method of this DelegatingMethod, 51 * or if the input object is a Method which is equal to the internal Method of this DelegatingMethod. 52 */ 53 @Override 54 public boolean equals(Object o) { 55 if (this == o) { 56 return true; 57 } 58 if (o instanceof DelegatingMethod) { 59 DelegatingMethod that = (DelegatingMethod) o; 60 return method.equals(that.method); 61 } else { 62 return method.equals(o); 63 } 64 } 65 66 @Override 67 public int hashCode() { 68 return method.hashCode(); 69 } 70} 71