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