KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > core > Invocation


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package org.jmock.core;
4
5 import java.lang.reflect.Method JavaDoc;
6 import java.util.Arrays JavaDoc;
7 import java.util.Collections JavaDoc;
8 import java.util.List JavaDoc;
9
10
11 /**
12  * A "dumb struct" that holds information about an invocation dispatched to a Mock object.
13  */

14 public class Invocation implements SelfDescribing
15 {
16     public final Object JavaDoc invokedObject;
17     public final Method JavaDoc invokedMethod;
18     public final List JavaDoc parameterValues;
19
20     public Invocation( Object JavaDoc invoked, Method JavaDoc method, Object JavaDoc[] parameterValues ) {
21         this.invokedObject = invoked;
22         this.invokedMethod = method;
23         this.parameterValues = parameterValues == null ?
24                                Collections.EMPTY_LIST
25                                : Collections.unmodifiableList(Arrays.asList(parameterValues));
26     }
27
28     public String JavaDoc toString() {
29         return describeTo(new StringBuffer JavaDoc()).toString();
30     }
31
32     public boolean equals( Object JavaDoc other ) {
33         return (other instanceof Invocation) && this.equals((Invocation)other);
34     }
35
36     public boolean equals( Invocation other ) {
37         return other != null
38                && invokedObject == other.invokedObject
39                && invokedMethod.equals(other.invokedMethod)
40                && parameterValues.equals(other.parameterValues);
41     }
42
43     public int hashCode() {
44         return invokedObject.hashCode() ^
45                invokedMethod.hashCode() ^
46                parameterValues.hashCode();
47     }
48
49     public StringBuffer JavaDoc describeTo( StringBuffer JavaDoc buffer ) {
50         buffer.append(invokedMethod.getDeclaringClass().getName());
51         buffer.append(".");
52         buffer.append(invokedMethod.getName());
53         Formatting.join(parameterValues, buffer, "(", ")");
54         return buffer;
55     }
56 }
57
Popular Tags