MouseInputHelper extends MouseInputAdapter { @Override public final void mouseClicked(MouseEvent e) { int keyState = e.getModifiers() & ALL_KEY_MASK; if (e.getButton()==MouseEvent.BUTTON1) { if (e.getClickCount()==1 && keyState==NO_KEYS_DOWN) { mouseLeftClicked(e); } else if (e.getClickCount()>1 && keyState == NO_KEYS_DOWN) { mouseLeftDoubleClicked(e); } else if (e.getClickCount()==1 && keyState==SHIFT_MASK) { mouseLeftClickedWithShift(e); } else if (e.getClickCount()==1 && keyState==META_MASK) { mouseLeftClickedWithMeta(e); } } else if (e.getButton() == MouseEvent.BUTTON3) { if (e.getClickCount()==1 && keyState==NO_KEYS_DOWN) { mouseRightClicked(e); } } }  @Override final void mouseClicked(MouseEvent e); void mouseLeftClicked(MouseEvent e); void mouseLeftDoubleClicked(MouseEvent e); void mouseLeftClickedWithShift(MouseEvent e); void mouseLeftClickedWithMeta(MouseEvent e); void mouseRightClicked(MouseEvent e);  }
@Test(dataProvider="mouseClickTests") public void testMouseInput(String desiredResult, int button, int clickCount, int modifiers) { MouseEvent e = createMouseEvent(button, clickCount, modifiers); helper.mouseClicked(e); assertEquals(helper.getResult(), desiredResult); }
@Test(dataProvider="ignoredClickTests") public void testIgnoredClicks(int button, int clickCount) { MouseEvent e; e = createMouseEvent(button, clickCount, 0); helper.mouseClicked(e); assertEquals(helper.getResult(), "no result"); e = createMouseEvent(button, clickCount, ALT_MASK); helper.mouseClicked(e); assertEquals(helper.getResult(), "no result"); e = createMouseEvent(button, clickCount, CTRL_MASK); helper.mouseClicked(e); assertEquals(helper.getResult(), "no result"); e = createMouseEvent(button, clickCount, META_MASK); helper.mouseClicked(e); assertEquals(helper.getResult(), "no result"); e = createMouseEvent(button, clickCount, SHIFT_MASK); helper.mouseClicked(e); assertEquals(helper.getResult(), "no result"); }