SecondScreen implements GazeMotionListener { public void light(final Point2D rawCoordinates) { final int x = (int) (rawCoordinates.getX() / pixelWidth); final int y = (int) (rawCoordinates.getY() / pixelWidth); if ((x < 0 || x >= lightingArray.length) || (y < 0 || y >= lightingArray[x].length)) { return; } lightingArray[x][y].enter(); } SecondScreen(final Stage stage2, final Lighting[][] lightingArray); void close(); void light(final Point2D rawCoordinates); @Override void gazeMoved(final Point2D position);  }
@Test void shouldNotLightCoordinatesOutOfBounds() { List<Point2D> answerList = List.of( new Point2D(-1, 1), new Point2D(1, -1), new Point2D(lightingArray.length * 20 + 1, 0), new Point2D(0, lightingArray[0].length * 20 + 1) ); for (Point2D point2D : answerList) { SecondScreen secondScreen = new SecondScreen(mockStage, lightingArray); assertDoesNotThrow(() -> secondScreen.light(point2D)); } }
@Test void shouldLightCoordinates() { List<Point2D> answerList = List.of( new Point2D(1, 1), new Point2D(lightingArray.length * 20 - 1, 0), new Point2D(0, lightingArray[0].length * 20 - 1) ); Lighting[][] mockLighting = lightingArray; for (int i = 0; i < mockLighting.length; i++) { for (int j = 0; j < mockLighting[i].length; j++) { mockLighting[i][j] = mock(Lighting.class); } } SecondScreen secondScreen = new SecondScreen(mockStage, mockLighting); for (Point2D point2D : answerList) { secondScreen.light(point2D); verify(mockLighting[(int) point2D.getX() / 20][(int) point2D.getY() / 20]).enter(); } }