1 11 package org.jboss.portal.common.junit; 12 13 import junit.framework.Assert; 14 15 import java.util.Arrays ; 16 17 23 public class ExtendedAssert extends Assert 24 { 25 26 29 public static void assertEquals(Object [] expected, Object [] actual) 30 { 31 assertEquals(null, (Object [])expected, (Object [])actual); 32 } 33 34 37 public static void assertEquals(String message, Object [] expected, Object [] actual) 38 { 39 if (Arrays.equals(expected, actual)) 40 { 41 return; 42 } 43 fail(format(message, expected, actual)); 44 } 45 46 private static String format(String message, Object expected, Object actual) { 47 String formatted= ""; 48 if (message != null) 49 { 50 formatted = message + " "; 51 } 52 return formatted + "expected:<" + format(expected) + "> but was:<" + format(actual) + ">"; 53 } 54 55 private static String format(Object o) 56 { 57 if (o instanceof Object []) 58 { 59 Object [] array = (Object [])o; 60 StringBuffer buffer = new StringBuffer ("["); 61 for (int i = 0; i < array.length; i++) 62 { 63 buffer.append(i == 0 ? "" : ",").append(String.valueOf(array[i])); 64 } 65 buffer.append("]"); 66 return buffer.toString(); 67 } 68 else 69 { 70 return String.valueOf(o); 71 } 72 } 73 74 } 75 | Popular Tags |