JAL-2326 added setup method for JvOptionPane in all Jalveiw test classes to enable...
[jalview.git] / test / jalview / util / PlatformTest.java
1 package jalview.util;
2
3 import static org.testng.Assert.assertFalse;
4 import static org.testng.Assert.assertTrue;
5
6 import jalview.gui.JvOptionPane;
7
8 import java.awt.Button;
9 import java.awt.Event;
10 import java.awt.event.MouseEvent;
11
12 import org.testng.annotations.BeforeClass;
13 import org.testng.annotations.Test;
14
15 public class PlatformTest
16 {
17
18   @BeforeClass(alwaysRun = true)
19   public void setUpJvOptionPane()
20   {
21     JvOptionPane.setInteractiveMode(false);
22     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
23   }
24
25   Button b = new Button();
26
27   /**
28    * isControlDown for Mac should answer true for Meta-down, but not for right
29    * mouse (popup trigger)
30    */
31   @Test(groups = "Functional")
32   public void testIsControlDown_mac()
33   {
34     int clickCount = 1;
35     boolean isPopupTrigger = false;
36     int buttonNo = MouseEvent.BUTTON1;
37     boolean mac = true;
38
39     int mods = 0;
40     // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
41     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
42             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
43
44     mods = Event.CTRL_MASK;
45     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
46             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
47
48     mods = Event.META_MASK;
49     assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
50             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
51
52     isPopupTrigger = true;
53     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
54             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
55
56     isPopupTrigger = false;
57     buttonNo = MouseEvent.BUTTON2;
58     mods = 0;
59     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
60             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
61   }
62
63   /**
64    * If not a Mac, we only care whether CTRL_MASK modifier is set on the mouse
65    * event
66    */
67   @Test(groups = "Functional")
68   public void testIsControlDown_notMac()
69   {
70     int clickCount = 1;
71     boolean isPopupTrigger = false;
72     int buttonNo = MouseEvent.BUTTON1;
73     boolean mac = false;
74
75     int mods = 0;
76     // not concerned with MouseEvent id, when, x, y, xAbs, yAbs values
77     assertFalse(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
78             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
79
80     mods = Event.CTRL_MASK;
81     assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
82             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
83
84     mods = Event.CTRL_MASK | Event.SHIFT_MASK | Event.ALT_MASK;
85     clickCount = 2;
86     buttonNo = 2;
87     isPopupTrigger = true;
88     assertTrue(Platform.isControlDown(new MouseEvent(b, 0, 0L, mods, 0, 0,
89             0, 0, clickCount, isPopupTrigger, buttonNo), mac));
90   }
91 }