1 package com.mockobjects.dynamic; 2 3 import junit.framework.*; 4 5 public class CallOnceExpectation implements Callable { 6 private Callable delegate; 7 private boolean wasCalled = false; 8 9 public CallOnceExpectation( Callable delegate ) { 10 this.delegate = delegate; 11 } 12 13 public String getDescription() { 14 return delegate.getDescription() + " [" + (wasCalled ? "" : "not ") + "called]"; 15 } 16 17 public Object call(Mock mock, String methodName, Object [] args) throws Throwable { 18 wasCalled = true; 19 return delegate.call( mock, methodName, args ); 20 } 21 22 public boolean matches(String methodName, Object [] args) { 23 return (!wasCalled) && delegate.matches( methodName, args ); 24 } 25 26 public void verify() { 27 if( !wasCalled ) { 28 throw new AssertionFailedError( delegate.getDescription() + " was expected but not called" ); 29 } 30 31 delegate.verify(); 32 } 33 34 public String toString() { 36 return Mock.className(this.getClass()) + "(" + this.getDescription() + ")"; 37 } 38 } 39 | Popular Tags |