HardwareMouseController implements MouseController { @Override public PeekingIterator<MouseState> events() { return new MouseIterator(); } HardwareMouseController(TimeProvider timeProvider, HardwareMouse hardwareMouse, MouseConfig mouseConfig); @Override PeekingIterator<MouseState> events(); @Override void grabbed(boolean grabbed); @Override boolean grabbed();  }
@Test public void mouseMoveYieldsEvent() { stubReturn(false).on(hardwareMouse).next(); final PeekingIterator<MouseState> events = hardwareMouseController.events(); assertEquals(false, events.hasNext()); final PeekingIterator<MouseState> events2 = hardwareMouseController.events(); setUpHardwareMouseStubReturn(0, 1, 2, 3, 4); assertEquals(true, events2.hasNext()); final MouseState mouseState = events2.next(); assertEquals(0, mouseState.getX()); assertEquals(1, mouseState.getY()); assertEquals(2, mouseState.getDX()); assertEquals(3, mouseState.getDY()); assertEquals(4, mouseState.getDWheel()); }
@Test public void mouseDownStateEvent() { final PeekingIterator<MouseState> events = hardwareMouseController.events(); setUpHardwareMouseStubReturn(0, 1, 2, 3, 4); stubReturn(1).on(hardwareMouse).buttonCount(); stubReturn(true).on(hardwareMouse).isButtonDown(MouseButton.LEFT); assertEquals(true, events.hasNext()); final MouseState mouseState = events.next(); assertEquals(MouseButton.values().length, mouseState.getButtonStates().size()); assertEquals(MouseButtonState.DOWN, mouseState.getButtonStates().get(MouseButton.LEFT)); assertEquals(MouseButtonState.UP, mouseState.getButtonStates().get(MouseButton.RIGHT)); final Multiset<MouseButton> clickCounts = mouseState.getClickCounts(); assertEquals(0, clickCounts.size()); }
@Test public void clickEvent() { setUpHardwareMouseStubReturn(0, 0, 0, 0, 0); stubReturn(1).on(hardwareMouse).buttonCount(); stubReturn(true).on(hardwareMouse).isButtonDown(MouseButton.LEFT); final PeekingIterator<MouseState> events = hardwareMouseController.events(); events.next(); stubReturn(false).on(hardwareMouse).isButtonDown(MouseButton.LEFT); final PeekingIterator<MouseState> events2 = hardwareMouseController.events(); final MouseState mouseState = events2.next(); assertEquals(MouseButton.values().length, mouseState.getButtonStates().size()); assertEquals(MouseButtonState.UP, mouseState.getButtonStates().get(MouseButton.LEFT)); final Multiset<MouseButton> clickCounts = mouseState.getClickCounts(); assertEquals(1, clickCounts.size()); }
@Test public void noClickEventWithMovingMouse() { setUpHardwareMouseStubReturn(0, 0, 1, 0, 0); stubReturn(1).on(hardwareMouse).buttonCount(); stubReturn(true).on(hardwareMouse).isButtonDown(MouseButton.LEFT); hardwareMouseController.events().next(); stubReturn(false).on(hardwareMouse).isButtonDown(MouseButton.LEFT); final PeekingIterator<MouseState> events = hardwareMouseController.events(); final Multiset<MouseButton> clickCounts = events.next().getClickCounts(); assertEquals(0, clickCounts.size()); }
@Test public void noClickEventWhenDelayIsGreaterThanLimit() { setUpHardwareMouseStubReturn(0, 0, 0, 0, 0); stubReturn(1).on(hardwareMouse).buttonCount(); stubReturn(true).on(hardwareMouse).isButtonDown(MouseButton.LEFT); hardwareMouseController.events().next(); stubReturn(100l).on(timeProvider).now(); stubReturn(false).on(hardwareMouse).isButtonDown(MouseButton.LEFT); final PeekingIterator<MouseState> events = hardwareMouseController.events(); final Multiset<MouseButton> clickCounts = events.next().getClickCounts(); assertEquals(0, clickCounts.size()); }