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