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.FileOption; 39 import edu.rice.cs.drjava.config.OptionConstants; 40 import edu.rice.cs.util.swing.Utilities; 41 42 import javax.swing.*; 43 import java.awt.*; 44 import java.io.File ; 45 46 49 public final class FileOptionComponentTest extends DrJavaTestCase { 50 51 private static FileOptionComponent _option; 52 53 public FileOptionComponentTest(String name) { 54 super(name); 55 } 56 57 protected void setUp() throws Exception { 58 super.setUp(); 59 _option = new FileOptionComponent(OptionConstants.JAVAC_LOCATION, 60 "Javac Location", new Frame(), 61 new JFileChooser()); 62 DrJava.getConfig().resetToDefaults(); 63 64 } 65 66 public void testCancelDoesNotChangeConfig() { 67 68 File testFile = FileOption.NULL_FILE; 69 70 _option.setValue(testFile); 71 _option.resetToCurrent(); Utilities.clearEventQueue(); 73 _option.updateConfig(); Utilities.clearEventQueue(); 75 assertEquals("Cancel (resetToCurrent) should not change the config", 76 OptionConstants.JAVAC_LOCATION.getDefault(), 77 DrJava.getConfig().getSetting(OptionConstants.JAVAC_LOCATION)); 78 79 } 80 81 public void testApplyDoesChangeConfig() { 82 File testFile = FileOption.NULL_FILE; 83 84 _option.setValue(testFile); 85 _option.updateConfig(); 86 Utilities.clearEventQueue(); 87 assertEquals("Apply (updateConfig) should write change to file", 88 testFile, 89 DrJava.getConfig().getSetting(OptionConstants.JAVAC_LOCATION)); 90 } 91 92 public void testApplyThenResetDefault() { 93 File testFile = FileOption.NULL_FILE; 94 95 _option.setValue(testFile); 96 _option.updateConfig(); 97 Utilities.clearEventQueue(); 98 _option.resetToDefault(); Utilities.clearEventQueue(); 100 _option.updateConfig(); 101 Utilities.clearEventQueue(); 102 103 assertEquals("Apply (updateConfig) should write change to file", 104 OptionConstants.JAVAC_LOCATION.getDefault(), 105 DrJava.getConfig().getSetting(OptionConstants.JAVAC_LOCATION)); 106 } 107 } | Popular Tags |