1 3 package org.jmock.core.stub; 4 5 import java.util.ArrayList ; 6 import java.util.Arrays ; 7 import java.util.Iterator ; 8 import java.util.List ; 9 import junit.framework.AssertionFailedError; 10 import org.jmock.core.Invocation; 11 import org.jmock.core.Stub; 12 13 14 public class StubSequence 15 implements Stub 16 { 17 List stubs; 18 Iterator iterator; 19 20 21 public StubSequence( Stub[] stubs ) { 22 this(Arrays.asList(stubs)); 23 } 24 25 public StubSequence( List stubs ) { 26 this.stubs = new ArrayList (stubs); 27 this.iterator = this.stubs.iterator(); 28 } 29 30 public Object invoke( Invocation invocation ) throws Throwable { 31 if (iterator.hasNext()) { 32 return ((Stub)iterator.next()).invoke(invocation); 33 } 34 throw new AssertionFailedError("no more stubs available"); 35 } 36 37 public StringBuffer describeTo( StringBuffer buffer ) { 38 for (int i = 0; i < stubs.size(); i++) { 39 if (i > 0) buffer.append(", and then "); 40 ((Stub)stubs.get(i)).describeTo(buffer); 41 } 42 43 return buffer; 44 } 45 } 46 | Popular Tags |