1 3 package org.jmock.core.matcher; 4 5 import junit.framework.AssertionFailedError; 6 import org.jmock.core.Invocation; 7 8 9 public class InvokedAfterMatcher 10 extends StatelessInvocationMatcher 11 { 12 private InvokedRecorder priorCallRecorder; 13 private String priorCallDescription; 14 15 public InvokedAfterMatcher( InvokedRecorder priorCallRecorder, 16 String priorCallDescription ) { 17 this.priorCallRecorder = priorCallRecorder; 18 this.priorCallDescription = priorCallDescription; 19 } 20 21 public boolean matches( Invocation invocation ) { 22 return priorCallRecorder.hasBeenInvoked(); 23 } 24 25 public void invoked( Invocation invocation ) { 26 if (!matches(invocation)) { 27 throw new AssertionFailedError("called out of order; should be called after " + priorCallDescription); 28 } 29 } 30 31 public StringBuffer describeTo( StringBuffer buffer ) { 32 buffer.append("after ").append(priorCallDescription); 33 if( priorCallRecorder.hasBeenInvoked() ) { 34 buffer.append(" (invoked)"); 35 } else { 36 buffer.append(" (not invoked)"); 37 } 38 return buffer; 39 } 40 } 41 | Popular Tags |