1 5 package org.easymock.samples; 6 7 import org.easymock.AbstractMatcher; 8 9 public class FirstCharMatcher extends AbstractMatcher { 10 protected boolean argumentMatches(Object expected, Object actual) { 11 if (expected instanceof String ) { 12 expected = firstCharacterIfString(expected); 13 } 14 if (actual instanceof String ) { 15 actual = firstCharacterIfString(actual); 16 } 17 return super.argumentMatches(expected, actual); 18 } 19 20 protected String argumentToString(Object argument) { 21 if (argument instanceof String ) { 22 argument = firstCharacterIfString(argument) + "..."; 23 } 24 return super.argumentToString(argument); 25 } 26 27 private Object firstCharacterIfString(Object object) { 28 if (!(object instanceof String )) { 29 return object; 30 } 31 String string = (String ) object; 32 return string.length() > 0 ? string.substring(0, 1) : string; 33 } 34 } 35 | Popular Tags |