1 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 ; 29 import java.util.ListIterator ; 30 31 35 public class FeaturesListTest extends NbTestCase { 36 37 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 , FileStateInvalidException { 56 Utility.beginTrans(true); 57 try { 58 ArrayList featuresCopy = new ArrayList (clazz.getFeatures()); 59 ListIterator 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 , FileStateInvalidException { 69 Utility.beginTrans(true); 70 try { 71 ArrayList featuresCopy = new ArrayList (clazz.getFeatures()); 72 ListIterator 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 , FileStateInvalidException { 82 Utility.beginTrans(true); 83 try { 84 ArrayList featuresCopy = new ArrayList (clazz.getFeatures()); 85 ListIterator 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 , FileStateInvalidException { 95 Utility.beginTrans(true); 96 try { 97 ArrayList featuresCopy = new ArrayList (clazz.getFeatures()); 98 ListIterator 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 , FileStateInvalidException { 109 Utility.beginTrans(true); 110 try { 111 ArrayList featuresCopy = new ArrayList (clazz.getFeatures()); 112 ListIterator 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 featuresCopy) { 123 assertEquals("Incorrect collection state", featuresCopy, clazz.getFeatures()); 124 } 125 126 127 130 public static void main(String [] args) { 131 TestRunner.run(suite()); 132 } 133 134 } 135 | Popular Tags |