KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > core > matcher > ArgumentsMatcher


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

3 package org.jmock.core.matcher;
4
5 import java.util.List JavaDoc;
6 import org.jmock.core.Constraint;
7 import org.jmock.core.Invocation;
8
9
10 public class ArgumentsMatcher
11         extends StatelessInvocationMatcher
12 {
13     private Constraint[] constraints;
14
15     public ArgumentsMatcher( Constraint[] constraints ) {
16         ArgumentsMatcher.this.constraints = (Constraint[])constraints.clone();
17     }
18
19     public boolean matches( Invocation invocation ) {
20         return constraints.length == invocation.parameterValues.size()
21                && matchesValues(invocation.parameterValues);
22     }
23
24     private boolean matchesValues( List JavaDoc list ) {
25         for (int i = 0; i < constraints.length; ++i) {
26             if (!constraints[i].eval(list.get(i))) {
27                 return false;
28             }
29         }
30         return true;
31     }
32
33     public StringBuffer JavaDoc describeTo( StringBuffer JavaDoc buffer ) {
34         buffer.append("( ");
35         for (int i = 0; i < constraints.length; i++) {
36             if (i > 0) buffer.append(", ");
37             constraints[i].describeTo(buffer);
38         }
39         buffer.append(" )");
40
41         return buffer;
42     }
43 }
44
Popular Tags