Clover coverage report - EasyMock 1.2_Java1.5
Coverage timestamp: So Aug 7 2005 17:48:15 CEST
file stats: LOC: 89   Methods: 9
NCLOC: 70   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MethodCall.java 100% 100% 100% 100%
coverage
 1    /*
 2    * Copyright (c) 2001-2005 OFFIS. This program is made available under the terms of
 3    * the MIT License.
 4    */
 5    package org.easymock.internal;
 6   
 7    import java.lang.reflect.Method;
 8   
 9    import org.easymock.ArgumentsMatcher;
 10   
 11    public class MethodCall {
 12    private final Method method;
 13   
 14    private final Object[] arguments;
 15   
 16  1180 public MethodCall(Method method, Object[] args) {
 17  1180 this.method = method;
 18  1180 this.arguments = expandVarArgs(method.isVarArgs(), args);
 19    }
 20   
 21  1180 private static Object[] expandVarArgs(final boolean isVarArgs,
 22    final Object[] args) {
 23  1180 if (!isVarArgs || isVarArgs && args[args.length - 1] != null && !args[args.length - 1].getClass().isArray()) {
 24  1140 return args;
 25    }
 26  40 Object[] varArgs = ArrayMatcher
 27    .createObjectArray(args[args.length - 1]);
 28  40 final int nonVarArgsCount = args.length - 1;
 29  40 final int varArgsCount = varArgs.length;
 30  40 Object[] newArgs = new Object[nonVarArgsCount + varArgsCount];
 31  40 System.arraycopy(args, 0, newArgs, 0, nonVarArgsCount);
 32  40 System.arraycopy(varArgs, 0, newArgs, nonVarArgsCount, varArgsCount);
 33  40 return newArgs;
 34    }
 35   
 36  1042 public Method getMethod() {
 37  1042 return method;
 38    }
 39   
 40  477 public Object[] getArguments() {
 41  477 return arguments;
 42    }
 43   
 44  97 public boolean equals(Object o) {
 45  97 if (o == null || !o.getClass().equals(this.getClass()))
 46  2 return false;
 47   
 48  95 MethodCall other = (MethodCall) o;
 49  95 return this.method.equals(other.method)
 50    && this.equalArguments(other.arguments);
 51    }
 52   
 53  2 public int hashCode() {
 54  2 throw new UnsupportedOperationException("hashCode() is not implemented");
 55    }
 56   
 57  83 private boolean equalArguments(Object[] arguments) {
 58  83 if (this.arguments == null && arguments == null) {
 59  7 return true;
 60    }
 61   
 62  76 if (this.arguments.length != arguments.length) {
 63  11 return false;
 64    }
 65  65 for (int i = 0; i < this.arguments.length; i++) {
 66  66 Object myArgument = this.arguments[i];
 67  66 Object otherArgument = arguments[i];
 68  66 if (method.getParameterTypes()[i].isPrimitive()) {
 69  43 if (!myArgument.equals(otherArgument)) {
 70  24 return false;
 71    }
 72    } else {
 73  23 if (myArgument != otherArgument) {
 74  21 return false;
 75    }
 76    }
 77    }
 78  20 return true;
 79    }
 80   
 81  397 public boolean matches(MethodCall actual, ArgumentsMatcher matcher) {
 82  397 return this.method.equals(actual.method)
 83    && matcher.matches(this.arguments, actual.arguments);
 84    }
 85   
 86  157 public String toString(ArgumentsMatcher matcher) {
 87  157 return method.getName() + "(" + matcher.toString(arguments) + ")";
 88    }
 89    }