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.KeyStrokeOption; 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.awt.event.KeyEvent ; 45 46 47 public final class KeyStrokeOptionComponentTest extends DrJavaTestCase { 48 49 private static KeyStrokeOptionComponent _option; 50 51 protected void setUp() throws Exception { 52 super.setUp(); 53 _option = new KeyStrokeOptionComponent( OptionConstants.KEY_NEW_FILE, "Normal KeyStroke", new Frame()); 54 DrJava.getConfig().resetToDefaults(); 55 } 56 57 public void testCancelDoesNotChangeConfig() { 58 KeyStroke testKeyStroke = KeyStrokeOption.NULL_KEYSTROKE; 59 60 _option.setValue(testKeyStroke); 61 _option.resetToCurrent(); _option.updateConfig(); 64 Utilities.clearEventQueue(); 65 assertEquals("Cancel (resetToCurrent) should not change the config", 66 OptionConstants.KEY_NEW_FILE.getDefault(), 67 DrJava.getConfig().getSetting(OptionConstants.KEY_NEW_FILE)); 68 } 69 70 public void testApplyDoesChangeConfig() { 71 KeyStroke testKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0); 72 73 _option.setValue(testKeyStroke); 74 _option.updateConfig(); 75 76 Utilities.clearEventQueue(); 77 assertEquals("Apply (updateConfig) should write change to file", 78 testKeyStroke, 79 DrJava.getConfig().getSetting(OptionConstants.KEY_NEW_FILE)); 80 } 81 82 public void testApplyThenResetDefault() { 83 KeyStroke testKeyStroke = KeyStrokeOption.NULL_KEYSTROKE; 84 85 _option.setValue(testKeyStroke); 86 _option.updateConfig(); 87 Utilities.clearEventQueue(); 88 _option.resetToDefault(); _option.updateConfig(); 90 91 Utilities.clearEventQueue(); 92 assertEquals("Apply (updateConfig) should write change to file", 93 OptionConstants.KEY_NEW_FILE.getDefault(), 94 DrJava.getConfig().getSetting(OptionConstants.KEY_NEW_FILE)); 95 } 96 97 } | Popular Tags |