KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junitx > framework > ComparisonFailureTest


1 package junitx.framework;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5
6 /**
7  * @version $Revision: 1.1 $ $Date: 2003/03/21 06:13:50 $
8  * @author <a HREF="mailto:vbossica@users.sourceforge.net">Vladimir R. Bossicard</a>
9  */

10 public class ComparisonFailureTest extends TestCase {
11
12     private String JavaDoc description;
13     private String JavaDoc message;
14     private String JavaDoc expected;
15     private String JavaDoc actual;
16     private String JavaDoc display;
17
18     public ComparisonFailureTest(String JavaDoc description,
19                                  String JavaDoc message,
20                                  String JavaDoc expected,
21                                  String JavaDoc actual,
22                                  String JavaDoc display) {
23         super("execute");
24
25         this.description = description;
26         this.message = message;
27         this.expected = expected;
28         this.actual = actual;
29         this.display = display;
30     }
31
32     public static Test suite() {
33         String JavaDoc expected = "12345678901234 12345678 12345678901234";
34
35         TestSuite suite = new TestSuite();
36         suite.addTest(new ComparisonFailureTest("StartSmall", null, expected, "aaaa5678901234 12345678 12345678901234", "expected:<1234567890...> but was:<aaaa567890...> ['aaaa']"));
37         suite.addTest(new ComparisonFailureTest("StartLong", null, expected, "aaaaaaaaaaaa34 12345678 12345678901234", "expected:<123456789012...> but was:<aaaaaaaaaaaa...>"));
38         suite.addTest(new ComparisonFailureTest("EndSmall", null, expected, "12345678901234 12345678 1234567890aaaa", "expected:<...5678901234> but was:<...567890aaaa> ['aaaa']"));
39         suite.addTest(new ComparisonFailureTest("EndLong", null, expected, "12345678901234 12345678 12aaaaaaaaaaaa", "expected:<...345678901234> but was:<...aaaaaaaaaaaa>"));
40
41         suite.addTest(new ComparisonFailureTest("SameStartSmall-1", null, expected, "12aaaa78901234 12345678 12345678901234", "expected:<1234567890...> but was:<12aaaa7890...> ['aaaa']"));
42         suite.addTest(new ComparisonFailureTest("SameStartLong", null, expected, "12aaaaaaaaaa34 12345678 12345678901234", "expected:<...3456789012...> but was:<...aaaaaaaaaa...>"));
43         suite.addTest(new ComparisonFailureTest("SameStartSmall-2", null, expected, "12345678aaaa34 12345678 12345678901234", "expected:<...3456789012...> but was:<...345678aaaa...> ['aaaa']"));
44     
45         suite.addTest(new ComparisonFailureTest("SameEndSmall-1", null, expected, "12345678901234 12345678 12345678aaaa34", "expected:<...3456789012...> but was:<...345678aaaa...> ['aaaa']"));
46         suite.addTest(new ComparisonFailureTest("SameEndLong", null, expected, "12345678901234 12345678 12aaaaaaaaaa34", "expected:<...3456789012...> but was:<...aaaaaaaaaa...>"));
47         suite.addTest(new ComparisonFailureTest("SameEndSmall-2", null, expected, "12345678901234 12345678 12aaaa78901234", "expected:<... 123456789...> but was:<... 12aaaa789...> ['aaaa']"));
48     
49         suite.addTest(new ComparisonFailureTest("MiddleSmall-1", null, expected, "12345678901234 1aaaa678 12345678901234", "expected:<... 12345678 ...> but was:<... 1aaaa678 ...> ['aaaa']"));
50         suite.addTest(new ComparisonFailureTest("MiddleLong", null, expected, "12345678901234 aaaaaaaaaa 12345678901234", "expected:<...12345678...> but was:<...aaaaaaaaaa...>"));
51         suite.addTest(new ComparisonFailureTest("MiddleSmall-2", null, expected, "12345678901234 123aaaa8 12345678901234", "expected:<... 12345678 ...> but was:<... 123aaaa8 ...> ['aaaa']"));
52
53         suite.addTest(new ComparisonFailureTest("ActualNull", null, expected, null, "expected:<12345678901234 12345678 12345678901234> but was:<null>"));
54         suite.addTest(new ComparisonFailureTest("ExpectedNull", null, null, expected, "expected:<null> but was:<12345678901234 12345678 12345678901234>"));
55
56         /* adding the JUnit tests just to verify */
57         suite.addTest(new ComparisonFailureTest("Message", "a", "b", "c", "a expected:<b> but was:<c>"));
58         suite.addTest(new ComparisonFailureTest("StartSame", null, "ba", "bc", "expected:<ba> but was:<bc> ['c']"));
59         suite.addTest(new ComparisonFailureTest("EndSame", null, "ab", "cb", "expected:<ab> but was:<cb> ['c']"));
60         suite.addTest(new ComparisonFailureTest("Same", null, "ab", "ab", "expected:<ab> but was:<ab>"));
61         suite.addTest(new ComparisonFailureTest("StartAndEndSame", null, "abc", "adc", "expected:<abc> but was:<adc> ['d']"));
62         suite.addTest(new ComparisonFailureTest("StartSameComplete", null, "ab", "abc", "expected:<ab> but was:<abc> ['c']"));
63         suite.addTest(new ComparisonFailureTest("EndSameComplete", null, "bc", "abc", "expected:<bc> but was:<abc> ['a']"));
64         suite.addTest(new ComparisonFailureTest("OverlapingMatches", null, "abc", "abbc", "expected:<abc> but was:<abbc> ['b']"));
65         suite.addTest(new ComparisonFailureTest("OverlapingMatches2", null, "abcdde", "abcde", "expected:<abcdde> but was:<abcde> ['d']"));
66         suite.addTest(new ComparisonFailureTest("OverlapingMatches3", null, "abcde", "abcdde", "expected:<abcde> but was:<abcdde> ['d']"));
67         
68         return suite;
69     }
70
71     public void execute() {
72         String JavaDoc msg = ComparisonFailure.createMessage(message, expected, actual);
73         assertEquals(display, msg);
74     }
75
76     public String JavaDoc getName() {
77         return this.description;
78     }
79
80 }
81
Popular Tags