1 package junit.tests.framework;
2
3 import junit.framework.ComparisonFailure;
4 import junit.framework.TestCase;
5
6 public class ComparisonFailureTest extends TestCase {
7
8
9 public void testConnection() {
10 ComparisonFailure failure = new ComparisonFailure("warning", "Mary had a little lamb", "Mary had the little lamb");
11 assertEquals("warning expected:<Mary had [a] little lamb> but was:<Mary had [the] little lamb>", failure.getMessage());
12 }
13
14
15 public void testThrowing() {
16 try {
17 assertEquals("a", "b");
18 } catch (ComparisonFailure e) {
19 return;
20 }
21 fail();
22 }
23
24 public void testExceptionToStringWithMessage() {
25 try {
26 assertEquals("woops!", "a", "b");
27 } catch (ComparisonFailure e) {
28 if (!e.toString().startsWith("junit.framework.ComparisonFailure: woops! expected:<")) {
29 fail("Unexpected message: " + e);
30 }
31 return;
32 }
33 fail();
34 }
35
36 public void testExceptionToStringWithoutMessage() {
37 try {
38 assertEquals("a", "b");
39 } catch (ComparisonFailure e) {
40 if (!e.toString().startsWith("junit.framework.ComparisonFailure: expected:<")) {
41 fail("Unexpected message: " + e);
42 }
43 return;
44 }
45 fail();
46 }
47 }