MouseZoomTranslate extends MouseAdapter { @Override public void mouseWheelMoved(final MouseWheelEvent event) { if (event.getWheelRotation() < 0) { this.awt.zoomIn(); } else { this.awt.zoomOut(); } this.awt.repaint(); } MouseZoomTranslate(final AwtDrawableSurface awt); @Override void mousePressed(final MouseEvent event); @Override void mouseDragged(final MouseEvent event); @Override void mouseWheelMoved(final MouseWheelEvent event);  }
@Test public void zoomsInAndOut() { final AwtDrawableSurface surface = new AwtDrawableSurface(); final MouseZoomTranslate mouse = new MouseZoomTranslate(surface); final MouseWheelEvent wheel = Mockito.mock(MouseWheelEvent.class); Mockito.when(wheel.getWheelRotation()).thenReturn(-1); final double scale = surface.context().scale(); mouse.mouseWheelMoved(wheel); MatcherAssert.assertThat( surface.context().scale(), Matchers.greaterThan(scale) ); Mockito.when(wheel.getWheelRotation()).thenReturn(1); mouse.mouseWheelMoved(wheel); mouse.mouseWheelMoved(wheel); MatcherAssert.assertThat( surface.context().scale(), Matchers.lessThan(scale) ); }