1 3 package org.jmock.builder; 4 5 import java.util.Iterator ; 6 import java.util.List ; 7 import org.jmock.core.InvocationMatcher; 8 import org.jmock.core.InvocationMocker.Describer; 9 import org.jmock.core.Stub; 10 import org.jmock.core.matcher.MethodNameMatcher; 11 import org.jmock.core.matcher.ArgumentsMatcher; 12 13 14 18 19 public class InvocationMockerDescriber implements Describer 20 { 21 private static final String SEP = ", "; 22 23 public boolean hasDescription() { 24 return true; 25 } 26 27 public void describeTo( StringBuffer buffer, 28 List matchers, Stub stub, String name ) { 29 Iterator i = matchers.iterator(); 30 boolean needSeparator = false; 31 boolean lastWasMethodName = false; 32 33 while (i.hasNext()) { 34 InvocationMatcher matcher = (InvocationMatcher)i.next(); 35 36 if (!matcher.hasDescription()) continue; 37 38 if (matcher instanceof MethodNameMatcher) { 39 if (!needSeparator) buffer.append("stub"); buffer.append(": "); 41 lastWasMethodName = true; 42 } else if( matcher instanceof ArgumentsMatcher ) { 43 if (needSeparator && !lastWasMethodName) buffer.append(SEP); 44 lastWasMethodName = false; 45 46 } else { 47 if (needSeparator) buffer.append(SEP); 48 lastWasMethodName = false; 49 } 50 51 matcher.describeTo(buffer); 52 needSeparator = true; 53 } 54 55 if (needSeparator) buffer.append(SEP); 56 stub.describeTo(buffer); 57 58 if (name != null) buffer.append(" [").append(name).append("]"); 59 } 60 } 61 | Popular Tags |