1 19 20 package org.netbeans.modules.editor.settings; 21 22 import java.awt.event.KeyEvent ; 23 import java.io.IOException ; 24 import javax.swing.KeyStroke ; 25 import org.netbeans.api.editor.settings.MultiKeyBinding; 26 import org.netbeans.junit.NbTestCase; 27 28 32 public class EditorSettingsTest extends NbTestCase { 33 34 public EditorSettingsTest(String testName) { 35 super(testName); 36 } 37 38 public void testMultiKeyBindingsEquality() throws IOException { 39 MultiKeyBinding one = new MultiKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK), "actionCTRL+M"); 41 MultiKeyBinding two = new MultiKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK), "actionCTRL+M"); 42 testEquality(one, two, true); 43 44 KeyStroke ks [] = new KeyStroke []{KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK)}; 46 one = new MultiKeyBinding(ks, "actionCTRL+M"); 47 two = new MultiKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK), "actionCTRL+M"); 48 testEquality(one, two, true); 49 50 one = new MultiKeyBinding(ks, "actionCTRL+M"); 52 two = new MultiKeyBinding( 53 KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK), 54 "actionCTRL+M_differentAction"); 55 testEquality(one, two, false); 56 57 KeyStroke ks2 [] = new KeyStroke []{KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK), 59 KeyStroke.getKeyStroke(KeyEvent.VK_F, 0), 60 KeyStroke.getKeyStroke(KeyEvent.VK_2, 0), 61 KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.ALT_DOWN_MASK) 62 }; 63 KeyStroke ks3 [] = new KeyStroke []{KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK), 64 KeyStroke.getKeyStroke(KeyEvent.VK_F, 0), 65 KeyStroke.getKeyStroke(KeyEvent.VK_2, 0), 66 KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.ALT_DOWN_MASK) 67 }; 68 69 one = new MultiKeyBinding(ks2, "multiOne"); 70 two = new MultiKeyBinding(ks3, "multiOne"); 71 testEquality(one, two, true); 72 73 KeyStroke ks4 [] = new KeyStroke []{KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK), 75 KeyStroke.getKeyStroke(KeyEvent.VK_2, 0), 76 KeyStroke.getKeyStroke(KeyEvent.VK_F, 0), 77 KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.ALT_DOWN_MASK) 78 }; 79 one = new MultiKeyBinding(ks3, "multiOne"); 80 two = new MultiKeyBinding(ks4, "multiOne"); 81 testEquality(one, two, false); 82 83 KeyStroke ks5 [] = new KeyStroke []{KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK), 85 KeyStroke.getKeyStroke(KeyEvent.VK_2, 0), 86 KeyStroke.getKeyStroke(KeyEvent.VK_F, 0), 87 KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.SHIFT_DOWN_MASK) 88 }; 89 one = new MultiKeyBinding(ks4, "multiOne"); 90 two = new MultiKeyBinding(ks5, "multiOne"); 91 testEquality(one, two, false); 92 93 one = new MultiKeyBinding(ks5, "multiOne"); 95 two = new MultiKeyBinding(ks5, "multiOne_different"); 96 testEquality(one, two, false); 97 98 boolean failed = false; 100 try { 101 one = new MultiKeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_M, KeyEvent.CTRL_DOWN_MASK), null); 102 } catch (NullPointerException npe){ 103 failed = true; 104 } 105 assertTrue(failed); 106 107 failed = false; 109 try { 110 one = new MultiKeyBinding((KeyStroke ) null, "actionName"); 111 } catch (NullPointerException npe){ 112 failed = true; 113 } 114 assertTrue(failed); 115 116 failed = false; 118 try { 119 one = new MultiKeyBinding((KeyStroke []) null, "actionName"); 120 } catch (NullPointerException npe){ 121 failed = true; 122 } 123 assertTrue(failed); 124 125 } 126 127 private void testEquality(MultiKeyBinding m1, MultiKeyBinding m2, boolean equals){ 128 assertTrue(equals == m2.equals(m1)); 129 assertTrue(equals == m1.equals(m2)); 130 } 131 } 132 | Popular Tags |