Coverage Report - biz.xsoftware.mock.CalledMethod
 
Classes in this File Line Coverage Branch Coverage Complexity
CalledMethod
75%
21/28
67%
2/3
0
 
 1  
 package biz.xsoftware.mock;
 2  
 
 3  
 import java.io.Serializable;
 4  
 import java.lang.reflect.Method;
 5  
 import java.util.Arrays;
 6  
 import java.util.List;
 7  
 
 8  
 /**
 9  
  * This object contains information about a MockObject method when it is called
 10  
  * 
 11  
  * @author Dean Hiller, Brian Freeman
 12  
  * @since Aug 12, 2004
 13  
  */
 14  
 public final class CalledMethod implements Serializable {
 15  
 
 16  
     private static final long serialVersionUID = -4453563617218618682L;
 17  
 
 18  
     private final String methodName;
 19  
     
 20  
     private final Method method;
 21  
 
 22  
     /**
 23  
      * Contains the actual attribute values that were passed in when the method
 24  
      * was called
 25  
      */
 26  
     private final Object[] params;
 27  
 
 28  
     private final Throwable howItWasCalled;
 29  
 
 30  5
     public CalledMethod(String methodName, Object[] params, Throwable howItWasCalled) {
 31  5
         this.methodName = methodName;
 32  5
         this.method = null;
 33  5
         if (params!=null) {
 34  0
             this.params = params.clone();
 35  0
         } else {
 36  5
             this.params = null;
 37  
         }
 38  5
         this.howItWasCalled = howItWasCalled;
 39  5
     }
 40  
     
 41  342
     public CalledMethod(String methodName, Method method, Object[] params, Throwable howItWasCalled) {
 42  342
         this.methodName = methodName;
 43  342
         this.method = method;
 44  342
         if (params!=null) {
 45  196
             this.params = params.clone();
 46  196
         } else {
 47  146
             this.params = null;
 48  
         }
 49  342
         this.howItWasCalled = howItWasCalled;
 50  342
     }
 51  
 
 52  
     /**
 53  
      * Gets the method name this CalledMethod object represents
 54  
      * 
 55  
      * @return  The method name
 56  
      */
 57  
     public String getMethodName() {
 58  472
         return methodName;
 59  
     }
 60  
     
 61  
     /**
 62  
      * Gets the method object this CalledMethod object represents
 63  
      * @return  The method object
 64  
      */
 65  
     public Method getMethod() {
 66  0
         return method;
 67  
     }
 68  
     
 69  
     /**
 70  
      * Gets the number of parameters passed into method
 71  
      * 
 72  
      * @return  The number of parameters
 73  
      */
 74  
     public int getParameterCount() {
 75  1
         return params.length;
 76  
     }
 77  
 
 78  
     /**
 79  
      * Gets the parameter at location=index
 80  
      * 
 81  
      * @param index The location of the parameter
 82  
      * @return The parameter that was passed into the method at location=index
 83  
      */
 84  
     public Object getParameter(int index) {
 85  20
         return params[index];
 86  
     }
 87  
 
 88  
     /**
 89  
      * Gets all the parameters that were passed into the method. For example, if
 90  
      * a method is called ... doSomethingCool("1234", 5, "eeee"), then the
 91  
      * following will be returned </br></br> new Object[] {"1234", new
 92  
      * Integer(5), "eeee")}
 93  
      * <p>
 94  
      * Note: The array returned is a clone of the internal array so changes
 95  
      * to the returned array will not change the internal array
 96  
      */
 97  
     public Object[] getAllParams() {
 98  17
         return params.clone();
 99  
     }
 100  
 
 101  
     /**
 102  
      * Returns a stacktrace of how the method was called. This is useful for
 103  
      * debugging when you didn't expect the method to be called.
 104  
      * 
 105  
      * @return Throwable of how the method was called.
 106  
      */
 107  
     public Throwable getHowItWasCalled() {
 108  12
         return howItWasCalled;
 109  
     }
 110  
 
 111  
     @Override
 112  
     public String toString() {
 113  0
         List<Object> paramList = null;
 114  0
         if (params != null)
 115  0
             paramList = Arrays.asList(params);
 116  
 
 117  0
         return "[method=" + method + " params=" + paramList + "]";
 118  
     }
 119  
 }