KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > java > source > gen > ListMatcherTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.api.java.source.gen;
20
21 import org.netbeans.junit.NbTestCase;
22 import org.netbeans.junit.NbTestSuite;
23 import org.netbeans.modules.java.source.save.ListMatcher;
24
25 /**
26  * Test ListMatcher.
27  *
28  * @author Pavel Flaska
29  */

30 public class ListMatcherTest extends NbTestCase {
31     
32     /** Creates a new instance of ListMatcherTest */
33     public ListMatcherTest(String JavaDoc testName) {
34         super(testName);
35     }
36     
37     public static NbTestSuite suite() {
38         NbTestSuite suite = new NbTestSuite();
39         suite.addTestSuite(ListMatcherTest.class);
40         return suite;
41     }
42     
43     public void testAddToEmpty() {
44         String JavaDoc[] oldL = { };
45         String JavaDoc[] newL = { "A", "B", "C" };
46         String JavaDoc golden =
47                 "{insert} A\n" +
48                 "{insert} B\n" +
49                 "{insert} C\n";
50         ListMatcher matcher = ListMatcher.instance(oldL, newL);
51         if (matcher.match()) {
52             String JavaDoc result = matcher.printResult(false);
53             System.err.println("-------------");
54             System.err.println("testAddToEmpty");
55             System.err.println("-------------");
56             System.err.println(result);
57             assertEquals(golden, result);
58         } else {
59             assertTrue("No match!", false);
60         }
61     }
62
63     public void testRemoveAll() {
64         String JavaDoc[] oldL= { "A", "B", "C" };
65         String JavaDoc[] newL = { };
66         String JavaDoc golden =
67                 "{delete} A\n" +
68                 "{delete} B\n" +
69                 "{delete} C\n";
70         ListMatcher matcher = ListMatcher.instance(oldL, newL);
71         if (matcher.match()) {
72             String JavaDoc result = matcher.printResult(false);
73             System.err.println("-------------");
74             System.err.println("testRemoveAll");
75             System.err.println("-------------");
76             System.err.println(result);
77             assertEquals(golden, result);
78         } else {
79             assertTrue("No match!", false);
80         }
81     }
82     
83     public void testAddToIndex0() {
84         String JavaDoc[] oldL= { "B" };
85         String JavaDoc[] newL = { "A", "B" };
86         String JavaDoc golden =
87                 "{insert} A\n" +
88                 "{nochange} B\n";
89         ListMatcher matcher = ListMatcher.instance(oldL, newL);
90         if (matcher.match()) {
91             String JavaDoc result = matcher.printResult(false);
92             System.err.println("---------------");
93             System.err.println("testAddToIndex0");
94             System.err.println("---------------");
95             System.err.println(result);
96             assertEquals(golden, result);
97         } else {
98             assertTrue("No match!", false);
99         }
100     }
101     
102     public void testRemoveAtIndex0() {
103         String JavaDoc[] oldL = { "A", "B" };
104         String JavaDoc[] newL = { "B" };
105         String JavaDoc golden =
106                 "{delete} A\n" +
107                 "{nochange} B\n";
108         ListMatcher matcher = ListMatcher.instance(oldL, newL);
109         if (matcher.match()) {
110             String JavaDoc result = matcher.printResult(false);
111             System.err.println("------------------");
112             System.err.println("testRemoveAtIndex0");
113             System.err.println("------------------");
114             System.err.println(result);
115             assertEquals(golden, result);
116         } else {
117             assertTrue("No match!", false);
118         }
119     }
120     
121     public void testComplex() {
122         String JavaDoc[] oldL = { "A", "B", "C", "D", "E", "F", "G" };
123         String JavaDoc[] newL = { "B", "C", "C1", "D", "E", "G", "H" };
124         String JavaDoc golden =
125                 "{delete} A\n" +
126                 "{nochange} B\n" +
127                 "{nochange} C\n" +
128                 "{insert} C1\n" +
129                 "{nochange} D\n" +
130                 "{nochange} E\n" +
131                 "{delete} F\n" +
132                 "{nochange} G\n" +
133                 "{insert} H\n";
134         ListMatcher matcher = ListMatcher.instance(oldL, newL);
135         if (matcher.match()) {
136             String JavaDoc result = matcher.printResult(false);
137             System.err.println("-----------");
138             System.err.println("testComplex");
139             System.err.println("-----------");
140             System.err.println(result);
141             assertEquals(golden, result);
142         } else {
143             assertTrue("No match!", false);
144         }
145     }
146 }
147
Popular Tags