MediaButton extends StackPaneButton { void setupImage() { if (mediaFile != null && mediaFile.getImagepath() != null) { final File f = new File(mediaFile.getImagepath()); final ImageView iv = new ImageView(new Image(f.toURI().toString())); iv.setPreserveRatio(true); iv.fitHeightProperty().bind(this.getButton().heightProperty().multiply(9.0 / 10.0)); iv.fitWidthProperty().bind(this.getButton().widthProperty().multiply(9.0 / 10.0)); this.getButton().setGraphic(iv); } else { this.getButton().setGraphic(null); } } MediaButton(double width, double height);  static final EventHandler<Event> emptyEvent; }
@Test void shouldNotSetUpGraphicForMediaButtonWithNoMediaFileSet() { MediaButton mediaButton = new MediaButton(500, 500); mediaButton.setupImage(); Assertions.assertNull(mediaButton.getButton().getGraphic()); }
@Test void shouldSetUpNullGraphicForMediaButtonWithMediaFileSetUpWithNoImagePath() { MediaButton mediaButton = new MediaButton(500, 500); MediaFile mediaFile = new MediaFile("URL", "https: mediaButton.setMediaFile(mediaFile); mediaButton.setupImage(); Assertions.assertNull(mediaButton.getButton().getGraphic()); }
@Test void shouldSetUpGraphicForMediaButtonWithMediaFileSetUpWithImagePath() { MediaButton mediaButton = new MediaButton(500, 500); MediaFile mediaFile = new MediaFile("URL", "https: mediaButton.setMediaFile(mediaFile); mediaButton.setupImage(); ImageView graphicImageView = (ImageView) mediaButton.getButton().getGraphic(); Assertions.assertTrue(graphicImageView.getImage().getUrl().contains("blue.jpg")); }