summaryrefslogtreecommitdiffstats
path: root/junit4/src/test/java/junit/tests/framework/ComparisonFailureTest.java
blob: 8a1e5f2084375011da5aaa6e07cf037e9b805bf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package junit.tests.framework;

import junit.framework.ComparisonFailure;
import junit.framework.TestCase;

public class ComparisonFailureTest extends TestCase {
	
	// Most of the tests are in ComparisonCompactorTest
	public void testConnection() {
		ComparisonFailure failure= new ComparisonFailure("warning", "Mary had a little lamb", "Mary had the little lamb");
		assertEquals("warning expected:<Mary had [a] little lamb> but was:<Mary had [the] little lamb>", failure.getMessage());
	}
	
	// This is like an instanceof test.
	public void testThrowing() {
		try {
			assertEquals("a", "b");
		} catch (ComparisonFailure e) {
			return;
		}
		fail();
	}

	public void testExceptionToStringWithMessage() {
		try {
			assertEquals("woops!", "a", "b");
		} catch (ComparisonFailure e) {
			if (!e.toString().startsWith("junit.framework.ComparisonFailure: woops! expected:<")) {
				fail("Unexpected message: " + e);
			}
			return;
		}
		fail();
	}

	public void testExceptionToStringWithoutMessage() {
		try {
			assertEquals("a", "b");
		} catch (ComparisonFailure e) {
			if (!e.toString().startsWith("junit.framework.ComparisonFailure: expected:<")) {
				fail("Unexpected message: " + e);
			}
			return;
		}
		fail();
	}
}