1 5 package org.easymock; 6 7 12 public abstract class AbstractMatcher implements ArgumentsMatcher { 13 14 25 protected boolean argumentMatches(Object expected, Object actual) { 26 return expected.equals(actual); 27 } 28 29 37 protected String argumentToString(Object argument) { 38 if (argument instanceof String ) { 39 return "\"" + argument + "\""; 40 } 41 return "" + argument; 42 } 43 44 58 public boolean matches(Object [] expected, Object [] actual) { 59 if (expected == actual) { 60 return true; 61 } 62 if (expected == null || actual == null) { 63 return false; 64 } 65 if (expected.length != actual.length) { 66 return false; 67 } 68 for (int i = 0; i < expected.length; i++) { 69 Object expectedObject = expected[i]; 70 Object actualObject = actual[i]; 71 72 if (expectedObject == null && actualObject == null) { 73 continue; 74 } 75 76 if (expectedObject == null && actualObject != null) { 77 return false; 78 } 79 80 if (expectedObject != null && actualObject == null) { 81 return false; 82 } 83 84 if (!argumentMatches(expectedObject, actualObject)) { 85 return false; 86 } 87 } 88 return true; 89 } 90 91 101 public String toString(Object [] arguments) { 102 if (arguments == null) 103 arguments = new Object [0]; 104 105 StringBuffer result = new StringBuffer (); 106 107 for (int i = 0; i < arguments.length; i++) { 108 if (i > 0) 109 result.append(", "); 110 result.append(argumentToString(arguments[i])); 111 } 112 return result.toString(); 113 } 114 } 115 | Popular Tags |