1 3 package test.jmock.examples.timedcache; 4 5 import java.util.ArrayList ; 6 import java.util.Iterator ; 7 import java.util.List ; 8 import junit.framework.AssertionFailedError; 9 import org.jmock.core.Invocation; 10 import org.jmock.core.Stub; 11 12 13 public class StubsSequence 14 implements Stub 15 { 16 List stubs; 17 Iterator iterator; 18 19 static public List asList( Stub stub1, Stub stub2 ) { 20 ArrayList list = new ArrayList (); 21 list.add(stub1); 22 list.add(stub2); 23 return list; 24 } 25 26 static public List asList( Stub stub1, Stub stub2, Stub stub3 ) { 27 ArrayList list = new ArrayList (); 28 list.add(stub1); 29 list.add(stub2); 30 list.add(stub3); 31 return list; 32 } 33 34 public StubsSequence( List stubs ) { 35 this.stubs = stubs; 36 iterator = this.stubs.iterator(); 37 } 38 39 public Object invoke( Invocation invocation ) throws Throwable { 40 if (iterator.hasNext()) { 41 return ((Stub)iterator.next()).invoke(invocation); 42 } 43 throw new AssertionFailedError("No more stubs available."); 44 } 45 46 public StringBuffer describeTo( StringBuffer buffer ) { 47 Iterator sequence = stubs.iterator(); 48 String filler = ""; 49 while (sequence.hasNext()) { 50 buffer.append(filler); 51 ((Stub)sequence.next()).describeTo(buffer); 52 filler = ", then "; 53 } 54 return buffer; 55 } 56 57 } 58 | Popular Tags |