1 package test.com.sun.javafx.scene.control.inputmap;
   2 
   3 import com.sun.javafx.scene.control.inputmap.KeyBinding;
   4 import javafx.scene.input.KeyCode;
   5 import javafx.scene.input.KeyEvent;
   6 import org.junit.Test;
   7 import static org.junit.Assert.*;
   8 
   9 public class KeyBindingTest {
  10 
  11     @Test public void getSpecificity() {
  12         final KeyCode code = KeyCode.ENTER;
  13 
  14         // Expected answer:
  15         // 1 pt for matching key code
  16         // 1 pt for matching key event type
  17         // 1 pt for matching no alt
  18         // 1 pt for matching no meta
  19         // 1 pt for matching shift or control
  20         // 0 pt for the other optional value of control/shift
  21         //
  22         // Total = 5.
  23         //
  24         int expect = 5;
  25 
  26         KeyBinding uut = new KeyBinding(code).shift().ctrl(KeyBinding.OptionalBoolean.ANY);
  27 
  28         KeyEvent event = new KeyEvent(KeyEvent.KEY_PRESSED, null,
  29                 null, code, true, false, false, false);
  30 
  31         assertEquals(expect, uut.getSpecificity(event)); // Gets 6 (fx 2.2, fx 8)
  32 
  33         uut = new KeyBinding(code).shift(KeyBinding.OptionalBoolean.ANY).ctrl();
  34 
  35         event = new KeyEvent(KeyEvent.KEY_PRESSED, null,
  36                 null, code, false, true, false, false);
  37 
  38         assertEquals(expect, uut.getSpecificity(event)); // Gets 2 (fx 2.2, fx 8)
  39     }
  40 }