1 /* Copyright (c) 2000-2003, jMock.org. See bundled LICENSE.txt */
2 package org.jmock.expectation;
3
4 import junit.framework.AssertionFailedError;
5 import org.jmock.AbstractTestCase;
6
7 import java.util.Vector;
8
9 public class TestAssertMo extends AbstractTestCase {
10
11 public void testAssertExcludes() {
12 AssertMo.assertExcludes(
13 "Should not include substring",
14 "dog",
15 "The quick brown fox");
16 }
17
18 public void testAssertExcludesFails() {
19 Throwable result = null;
20 try {
21 AssertMo.assertExcludes(
22 "Should fail on exclude",
23 "fox",
24 "The quick brown fox");
25 } catch (AssertionFailedError ex) {
26 result = ex;
27 }
28
29 assertTrue("Should get an exception", result != null);
30
31 }
32
33 public void testAssertIncludes() {
34 AssertMo.assertIncludes(
35 "Should include a substring",
36 "fox",
37 "The quick brown fox");
38 }
39
40 public void testAssertIncludesFails() {
41 Throwable result = null;
42 try {
43 AssertMo.assertIncludes(
44 "Should fail if no include",
45 "dog",
46 "The quick brown fox");
47 } catch (AssertionFailedError ex) {
48 result = ex;
49 }
50
51 assertTrue("Should get an exception", result != null);
52
53 }
54
55 public void testAssertStartsWith() {
56 AssertMo.assertStartsWith(
57 "Should start with fox",
58 "fox",
59 "fox quick brown");
60 }
61
62 public void testAssertStartsWithFails() {
63 Throwable result = null;
64 try {
65 AssertMo.assertStartsWith(
66 "Should fail if it doesn't start with fox",
67 "fox",
68 "The quick brown fox");
69 } catch (AssertionFailedError ex) {
70 result = ex;
71 }
72
73 assertTrue("Should get an exception", result != null);
74
75 }
76
77 public void testDifferentArrays() {
78 Object[] anExpectedArray = new Object[]{"one", new Integer(2)};
79 Object[] anActualArray = new Object[]{"two", new Integer(2)};
80
81 boolean threwException = false;
82 try {
83 AssertMo.assertEquals(
84 "Should be expected value",
85 anExpectedArray,
86 anActualArray);
87 } catch (AssertionFailedError ignoredException) {
88 threwException = true;
89 }
90 assertTrue("should have thrown assertion failure", threwException);
91 }
92
93 public void testDifferentLengthArrays() {
94 Object[] anExpectedArray = new Object[]{"one", new Integer(2)};
95 Object[] anActualArray = new Object[]{"one"};
96
97 boolean threwException = false;
98 try {
99 AssertMo.assertEquals(
100 "Should be expected value",
101 anExpectedArray,
102 anActualArray);
103 } catch (AssertionFailedError ignoredException) {
104 threwException = true;
105 }
106 assertTrue("should have thrown assertion failure", threwException);
107 }
108
109 public void testDifferentObjectArrays() {
110 Object[] anExpectedArray = new Object[]{"one", new Integer(2)};
111 Object[] anActualArray = new Object[]{new Integer(2), new Vector()};
112
113 boolean threwException = false;
114 try {
115 AssertMo.assertEquals(
116 "Should be expected value",
117 anExpectedArray,
118 anActualArray);
119 } catch (AssertionFailedError ignoredException) {
120 threwException = true;
121 }
122 assertTrue("should have thrown assertion failure", threwException);
123 }
124
125 public void testEqualArrays() {
126 Object[] anExpectedArray = new Object[]{"one", new Integer(2)};
127 Object[] anActualArray = new Object[]{"one", new Integer(2)};
128
129 AssertMo.assertEquals(
130 "Should be expected value",
131 anExpectedArray,
132 anActualArray);
133 }
134
135 public void testEqualEmptyArrays() {
136 Object[] anExpectedArray = new Object[0];
137 Object[] anActualArray = new Object[0];
138
139 AssertMo.assertEquals(
140 "Should be expected value",
141 anExpectedArray,
142 anActualArray);
143 }
144
145 public void testFailureCheckerWithFailure() {
146 AssertMo.assertFails("Test Description",
147 new Runnable() {
148 public void run() {
149 fail("Should not be propagated");
150 }
151 });
152 }
153
154 public void testFailureCheckerWithoutFailure() {
155 final String TEST_MESSAGE = "Test Description";
156 try {
157 AssertMo.assertFails(TEST_MESSAGE, new Runnable() {
158 public void run() {
159 }
160 });
161 } catch (AssertionFailedError expected) {
162 assertEquals(TEST_MESSAGE, expected.getMessage());
163 return;
164 }
165 fail("Should have thrown an exception");
166 }
167
168 }
This page was automatically generated by Maven