1 33 34 package edu.rice.cs.drjava.ui.config; 35 36 import edu.rice.cs.drjava.DrJava; 37 import edu.rice.cs.drjava.DrJavaTestCase; 38 import edu.rice.cs.drjava.config.OptionConstants; 39 import edu.rice.cs.util.swing.Utilities; 40 41 import java.awt.*; 42 import java.io.File ; 43 import java.util.Vector ; 44 45 46 public final class VectorFileOptionComponentTest extends DrJavaTestCase { 47 private static VectorFileOptionComponent _option; 48 49 protected void setUp() throws Exception { 50 super.setUp(); 51 _option = new VectorFileOptionComponent(OptionConstants.EXTRA_CLASSPATH, "Extra Classpath", new Frame()); 52 DrJava.getConfig().resetToDefaults(); 53 } 54 55 public void testCancelDoesNotChangeConfig() { 56 Vector <File > testVector = new Vector <File >(); 57 testVector.addElement(new File ("test")); 58 59 _option.setValue(testVector); 60 _option.resetToCurrent(); _option.updateConfig(); 63 Utilities.clearEventQueue(); 64 65 assertTrue("Cancel (resetToCurrent) should not change the config", 66 vectorEquals(OptionConstants.EXTRA_CLASSPATH.getDefault(), 67 DrJava.getConfig().getSetting(OptionConstants.EXTRA_CLASSPATH))); 68 } 69 70 public void testApplyDoesChangeConfig() { 71 Vector <File > testVector = new Vector <File >(); 72 testVector.addElement(new File ("blah")); 73 74 _option.setValue(testVector); 75 _option.updateConfig(); 76 77 Utilities.clearEventQueue(); 78 assertTrue("Apply (updateConfig) should write change to file", 79 vectorEquals(testVector, 80 DrJava.getConfig().getSetting(OptionConstants.EXTRA_CLASSPATH))); 81 } 82 83 public void testApplyThenResetDefault() { 84 Vector <File > testVector = new Vector <File >(); 85 testVector.addElement(new File ("blah")); 86 87 _option.setValue(testVector); 88 _option.updateConfig(); 89 Utilities.clearEventQueue(); 90 91 _option.resetToDefault(); _option.updateConfig(); 93 Utilities.clearEventQueue(); 94 95 assertTrue("Apply (updateConfig) should write change to file", 96 vectorEquals(OptionConstants.EXTRA_CLASSPATH.getDefault(), 97 DrJava.getConfig().getSetting(OptionConstants.EXTRA_CLASSPATH))); 98 } 99 100 107 public boolean vectorEquals(Vector <File > v1, Vector <File > v2) { 108 if (v1.size() == v2.size()) { 109 for (int i = 0; i < v1.size(); i++) { 110 if (!v1.elementAt(i).equals(v2.elementAt(i))) { 111 return false; 112 } 113 } 114 return true; 115 } 116 else { return false; 118 } 119 } 120 } 121 | Popular Tags |