MediaButton extends StackPaneButton { void setupEvent(EventHandler<ActionEvent> newMediaEvent, GazeIndicator progressIndicator) { this.removeEventFilter(MouseEvent.MOUSE_CLICKED, clickEvent); this.removeEventFilter(GazeEvent.GAZE_ENTERED, enterEvent); this.removeEventFilter(GazeEvent.GAZE_EXITED, exitEvent); clickEvent = e -> { newMediaEvent.handle(null); }; this.addEventFilter(MouseEvent.MOUSE_CLICKED, clickEvent); enterEvent = eventEntered -> { if(!this.getChildren().contains(progressIndicator)) { this.getChildren().add(progressIndicator); } progressIndicator.setOnFinish(newMediaEvent); progressIndicator.start(); }; exitEvent = eventExited -> { progressIndicator.stop(); this.getChildren().remove(progressIndicator); }; this.addEventFilter(MouseEvent.MOUSE_ENTERED, enterEvent); this.addEventFilter(MouseEvent.MOUSE_EXITED, exitEvent); this.addEventFilter(GazeEvent.GAZE_ENTERED, enterEvent); this.addEventFilter(GazeEvent.GAZE_EXITED, exitEvent); } MediaButton(double width, double height);  static final EventHandler<Event> emptyEvent; }
@Test void shouldCreateEventsHandlersForMediaButtonWithSetUpEventMethodCall() { MediaButton mediaButton = new MediaButton(500, 500); EventHandler<ActionEvent> testEvent = e -> { String testString = "test"; }; mediaButton.setupEvent(testEvent, progressIndicator); Assertions.assertNotEquals(mediaButton.getClickEvent(), (MediaButton.emptyEvent)); Assertions.assertNotEquals(mediaButton.getEnterEvent(), (MediaButton.emptyEvent)); Assertions.assertNotEquals(mediaButton.getExitEvent(), (MediaButton.emptyEvent)); }