1 package org.junit.tests.assertion;
2
3 import static org.junit.Assert.assertEquals;
4
5 import java.util.Arrays;
6 import java.util.Collection;
7
8 import org.junit.ComparisonFailure;
9 import org.junit.Test;
10 import org.junit.runner.RunWith;
11 import org.junit.runners.Parameterized;
12 import org.junit.runners.Parameterized.Parameters;
13
14 @RunWith(Parameterized.class)
15 public class ComparisonFailureTest {
16
17 private String expected, actual, message;
18
19 public ComparisonFailureTest(String e, String a, String m) {
20 expected = e;
21 actual = a;
22 message = m;
23 }
24
25 @Parameters(name = "compact-msg-{index}, exp=\"{1}\"")
26 public static Collection<Object[]> data() {
27 return Arrays.asList(new Object[][] {
28
29 { "a", "b", "expected:<[a]> but was:<[b]>" },
30
31
32 { "ba", "bc", "expected:<b[a]> but was:<b[c]>" },
33
34
35 { "ab", "cb", "expected:<[a]b> but was:<[c]b>" },
36
37
38 { "abc", "adc", "expected:<a[b]c> but was:<a[d]c>" },
39
40
41 { "ab", "abc", "expected:<ab[]> but was:<ab[c]>" },
42
43
44 { "abc", "ab", "expected:<ab[c]> but was:<ab[]>" },
45
46
47 { "abc", "abbc", "expected:<ab[]c> but was:<ab[b]c>" },
48
49
50 { "01234567890123456789PRE:hello:POST",
51 "01234567890123456789PRE:world:POST",
52 "expected:<...4567890123456789PRE:[hello]:POST> but was:<...4567890123456789PRE:[world]:POST>" },
53
54
55 { "PRE:hello:01234567890123456789POST",
56 "PRE:world:01234567890123456789POST",
57 "expected:<PRE:[hello]:0123456789012345678...> but was:<PRE:[world]:0123456789012345678...>"
58 },
59
60
61 { "S&P500", "0", "expected:<[S&P50]0> but was:<[]0>" },
62
63
64 { "", "a", "expected:<[]> but was:<[a]>" },
65
66
67 { "a", "", "expected:<[a]> but was:<[]>" }
68
69 });
70 }
71
72 @Test
73 public void compactFailureMessage() {
74 ComparisonFailure failure = new ComparisonFailure("", expected, actual);
75 assertEquals(message, failure.getMessage());
76 }
77
78 }