KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > codegen > FeaturesListTest


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.jmi.javamodel.codegen;
20
21 import junit.textui.TestRunner;
22 import org.netbeans.jmi.javamodel.JavaClass;
23 import org.netbeans.jmi.javamodel.JavaModelPackage;
24 import org.netbeans.jmi.javamodel.Method;
25 import org.netbeans.junit.NbTestCase;
26 import org.netbeans.junit.NbTestSuite;
27 import org.openide.filesystems.FileStateInvalidException;
28 import java.util.ArrayList JavaDoc;
29 import java.util.ListIterator JavaDoc;
30
31 /**
32  *
33  * @author Martin Matula
34  */

35 public class FeaturesListTest extends NbTestCase {
36
37     /** Need to be defined because of JUnit */
38     public FeaturesListTest() {
39         super("FeaturesListTest");
40     }
41     
42     public static NbTestSuite suite() {
43         NbTestSuite suite = new NbTestSuite(FeaturesListTest.class);
44         return suite;
45     }
46     
47     JavaClass clazz;
48     JavaModelPackage pkg;
49     
50     protected void setUp() {
51         clazz = Utility.findClass("org.netbeans.test.codegen.FeatureListTestClass");
52         pkg = (JavaModelPackage) clazz.refImmediatePackage();
53     }
54
55     public void testRemoveAfterNext() throws java.io.IOException JavaDoc, FileStateInvalidException {
56         Utility.beginTrans(true);
57         try {
58             ArrayList JavaDoc featuresCopy = new ArrayList JavaDoc(clazz.getFeatures());
59             ListIterator JavaDoc it1 = featuresCopy.listIterator(2), it2 = clazz.getFeatures().listIterator(2);
60             it1.next(); it2.next();
61             it1.remove(); it2.remove();
62             assertCollection(featuresCopy);
63         } finally {
64             Utility.endTrans(true);
65         }
66     }
67
68     public void testRemoveAfterPrevious() throws java.io.IOException JavaDoc, FileStateInvalidException {
69         Utility.beginTrans(true);
70         try {
71             ArrayList JavaDoc featuresCopy = new ArrayList JavaDoc(clazz.getFeatures());
72             ListIterator JavaDoc it1 = featuresCopy.listIterator(2), it2 = clazz.getFeatures().listIterator(2);
73             it1.previous(); it2.previous();
74             it1.remove(); it2.remove();
75             assertCollection(featuresCopy);
76         } finally {
77             Utility.endTrans(true);
78         }
79     }
80
81     public void testAdd() throws java.io.IOException JavaDoc, FileStateInvalidException {
82         Utility.beginTrans(true);
83         try {
84             ArrayList JavaDoc featuresCopy = new ArrayList JavaDoc(clazz.getFeatures());
85             ListIterator JavaDoc it1 = featuresCopy.listIterator(2), it2 = clazz.getFeatures().listIterator(2);
86             Method m = pkg.getMethod().createMethod();
87             it1.add(m); it2.add(m);
88             assertCollection(featuresCopy);
89         } finally {
90             Utility.endTrans(true);
91         }
92     }
93
94     public void testSetAfterNext() throws java.io.IOException JavaDoc, FileStateInvalidException {
95         Utility.beginTrans(true);
96         try {
97             ArrayList JavaDoc featuresCopy = new ArrayList JavaDoc(clazz.getFeatures());
98             ListIterator JavaDoc it1 = featuresCopy.listIterator(2), it2 = clazz.getFeatures().listIterator(2);
99             it1.next(); it2.next();
100             Method m = pkg.getMethod().createMethod();
101             it1.set(m); it2.set(m);
102             assertCollection(featuresCopy);
103         } finally {
104             Utility.endTrans(true);
105         }
106     }
107
108     public void testSetAfterPrevious() throws java.io.IOException JavaDoc, FileStateInvalidException {
109         Utility.beginTrans(true);
110         try {
111             ArrayList JavaDoc featuresCopy = new ArrayList JavaDoc(clazz.getFeatures());
112             ListIterator JavaDoc it1 = featuresCopy.listIterator(2), it2 = clazz.getFeatures().listIterator(2);
113             it1.previous(); it2.previous();
114             Method m = pkg.getMethod().createMethod();
115             it1.set(m); it2.set(m);
116             assertCollection(featuresCopy);
117         } finally {
118             Utility.endTrans(true);
119         }
120     }
121
122     private void assertCollection(ArrayList JavaDoc featuresCopy) {
123         assertEquals("Incorrect collection state", featuresCopy, clazz.getFeatures());
124     }
125
126
127     /**
128      * @param args the command line arguments
129      */

130     public static void main(String JavaDoc[] args) {
131         TestRunner.run(suite());
132     }
133     
134 }
135
Popular Tags