1 package com.mockobjects.util; 2 3 4 import junit.framework.Assert; 5 import junit.framework.AssertionFailedError; 6 import com.mockobjects.Verifiable; 7 8 public class AssertMo extends Assert { 9 10 protected AssertMo() { 11 super(); 12 } 13 14 public static void assertEquals( 15 String description, 16 Object [] expectedArray, 17 Object [] actualArray) { 18 assertEquals( 19 description + " (different lengths)", 20 expectedArray.length, 21 actualArray.length); 22 for (int i = 0; i < expectedArray.length; i++) { 23 assertEquals( 24 description + " (element " + i + ")", 25 expectedArray[i], 26 actualArray[i]); 27 } 28 } 29 30 public static void assertExcludes( 31 String description, 32 String excludeString, 33 String targetString) { 34 assertTrue( 35 description 36 + "\nExclude String: " 37 + excludeString 38 + "\n Target String: " 39 + targetString, 40 targetString.indexOf(excludeString) == -1); 41 } 42 43 public static void assertIncludes( 44 String description, 45 String includeString, 46 String targetString) { 47 assertTrue( 48 description 49 + "\nInclude String: " 50 + includeString 51 + "\n Target String: " 52 + targetString, 53 targetString.indexOf(includeString) != -1); 54 } 55 56 public static void assertStartsWith( 57 String description, 58 String startString, 59 String targetString) { 60 assertTrue( 61 description 62 + "\n Start String: " 63 + startString 64 + "\nTarget String: " 65 + targetString, 66 targetString.startsWith(startString)); 67 } 68 69 public static void assertVerifyFails(Verifiable aVerifiable) { 70 boolean threwException = false; 71 try { 72 aVerifiable.verify(); 73 } catch (AssertionFailedError ex) { 74 threwException = true; 75 } 76 77 assertTrue("Should not have verified", threwException); 78 } 79 80 static protected void failNotEquals( 81 String message, 82 Object expected, 83 Object actual) { 84 String formatted = ""; 85 if (message != null) 86 formatted = message + " "; 87 fail( 88 formatted + "\nExpected:<" + expected + ">\nReceived:<" + actual + ">"); 89 } 90 91 public static void notImplemented(String mockName) { 92 throw new NotImplementedException("Not Implemented in " + mockName); 93 } 94 95 public static void assertFails(String message, Runnable runnable) { 96 try { 97 runnable.run(); 98 } catch (AssertionFailedError expected) { 99 return; 100 } 101 fail(message); 102 } 103 } 104 | Popular Tags |