KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmock > expectation > AssertMo


1 /* Copyright (c) 2000-2004 jMock.org
2  */

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 JavaDoc description,
19                                      Object JavaDoc[] expectedArray,
20                                      Object JavaDoc[] 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 JavaDoc description,
32                                        String JavaDoc excludeString,
33                                        String JavaDoc 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 JavaDoc description,
43                                        String JavaDoc includeString,
44                                        String JavaDoc 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 JavaDoc description,
54                                          String JavaDoc startString,
55                                          String JavaDoc 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 JavaDoc message,
77                                          Object JavaDoc expected,
78                                          Object JavaDoc actual ) {
79         String JavaDoc formatted = "";
80         if (message != null) {
81             formatted = message + " ";
82         }
83         fail(formatted + "\nExpected:<" + expected + ">\nReceived:<" + actual + ">");
84     }
85
86     public static void notImplemented( String JavaDoc mockName ) {
87         throw new NotImplementedException("Not Implemented in " + mockName);
88     }
89
90     public static void assertFails( String JavaDoc message, Runnable JavaDoc runnable ) {
91         try {
92             runnable.run();
93         }
94         catch (AssertionFailedError expected) {
95             return;
96         }
97         fail(message);
98     }
99 }
100
Popular Tags