View Javadoc
1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */ 2 package org.jmock.dynamic; 3 4 import org.jmock.InvocationMatcher; 5 import org.jmock.Stub; 6 import org.jmock.matcher.MethodNameMatcher; 7 8 import java.util.ArrayList; 9 import java.util.Iterator; 10 import java.util.List; 11 12 public class InvocationMocker implements Invokable { 13 14 private List matchers = new ArrayList(); 15 private Stub stub; 16 17 public InvocationMocker(String methodName, InvocationMatcher arguments, Stub stub) { 18 this(stub); 19 addMatcher(new MethodNameMatcher(methodName)); 20 addMatcher(arguments); 21 } 22 23 public InvocationMocker(InvocationMatcher[] matchers, Stub stub) { 24 this(stub); 25 for (int i = 0; i < matchers.length; i++) addMatcher(matchers[i]); 26 } 27 28 public InvocationMocker(Stub stub) { 29 this.stub = stub; 30 } 31 32 public String getDescription() { 33 return null; // TODO 34 } 35 36 public boolean matches(Invocation invocation) { 37 Iterator i = matchers.iterator(); 38 while (i.hasNext()) { 39 if (!((InvocationMatcher) i.next()).matches(invocation)) { 40 return false; 41 } 42 } 43 return true; 44 } 45 46 public Object invoke(Invocation invocation) throws Throwable { 47 Iterator i = matchers.iterator(); 48 while (i.hasNext()) { 49 ((InvocationMatcher) i.next()).invoked(invocation); 50 } 51 return stub.invoke(invocation); 52 } 53 54 public void verify() { 55 Iterator i = matchers.iterator(); 56 while (i.hasNext()) { 57 ((InvocationMatcher) i.next()).verify(); 58 } 59 } 60 61 public InvocationMocker addMatcher(InvocationMatcher matcher) { 62 matchers.add(matcher); 63 return this; 64 } 65 66 public void setStub(Stub stub) { 67 this.stub = stub; 68 } 69 }

This page was automatically generated by Maven