Common { public static boolean warnAnisotropy(final ImagePlus image, final UIService uiService) { final double anisotropy = ImagePlusUtil.anisotropy(image); if (anisotropy < 1E-3) { return true; } final String anisotropyPercent = String.format("(%.1f %%)", anisotropy * 100.0); return uiService.showDialog("The image is anisotropic " + anisotropyPercent + ". Continue anyway?", WARNING_MESSAGE, OK_CANCEL_OPTION) == OK_OPTION; }  static LUT makeFire(); static ImgPlus<BitType> toBitTypeImgPlus(
		final OpEnvironment ops, final ImgPlus<C> imgPlus); static boolean warnAnisotropy(final ImagePlus image,
		final UIService uiService); static void cancelMacroSafe(final ContextCommand command, final String reason);  }
@Test @Category(org.bonej.wrapperPlugins.SlowWrapperTest.class) public void testWarnAnisotropyReturnsFalseIfAnisotropicImageAndUserCancels() { final ImagePlus imagePlus = mock(ImagePlus.class); final Calibration anisotropicCalibration = new Calibration(); anisotropicCalibration.pixelWidth = 0.5; when(imagePlus.getCalibration()).thenReturn(anisotropicCalibration); final UIService uiService = mock(UIService.class); when(uiService.showDialog(anyString(), any(MessageType.class), any())) .thenReturn(CANCEL_OPTION); assertFalse(Common.warnAnisotropy(imagePlus, uiService)); verify(uiService, timeout(1000)).showDialog(anyString(), any( MessageType.class), any()); }
@Test @Category(org.bonej.wrapperPlugins.SlowWrapperTest.class) public void testWarnAnisotropyReturnsFalseIfAnisotropicImageAndUserCloses() { final ImagePlus imagePlus = mock(ImagePlus.class); final Calibration anisotropicCalibration = new Calibration(); anisotropicCalibration.pixelWidth = 0.5; when(imagePlus.getCalibration()).thenReturn(anisotropicCalibration); final UIService uiService = mock(UIService.class); when(uiService.showDialog(anyString(), any(MessageType.class), any())) .thenReturn(CLOSED_OPTION); assertFalse(Common.warnAnisotropy(imagePlus, uiService)); verify(uiService, timeout(1000)).showDialog(anyString(), any( MessageType.class), any()); }
@Test @Category(org.bonej.wrapperPlugins.SlowWrapperTest.class) public void testWarnAnisotropyReturnsTrueIfAnisotropicImageAndUserOK() { final ImagePlus imagePlus = mock(ImagePlus.class); final Calibration anisotropicCalibration = new Calibration(); anisotropicCalibration.pixelWidth = 0.5; when(imagePlus.getCalibration()).thenReturn(anisotropicCalibration); final UIService uiService = mock(UIService.class); when(uiService.showDialog(anyString(), any(MessageType.class), any())) .thenReturn(OK_OPTION); assertTrue(Common.warnAnisotropy(imagePlus, uiService)); verify(uiService, timeout(1000)).showDialog(anyString(), any( MessageType.class), any()); }
@Test @Category(org.bonej.wrapperPlugins.SlowWrapperTest.class) public void testWarnAnisotropyReturnsTrueIfIsotropicImage() { final ImagePlus imagePlus = mock(ImagePlus.class); final Calibration isotropic = new Calibration(); when(imagePlus.getCalibration()).thenReturn(isotropic); final UIService uiService = mock(UIService.class); assertTrue(Common.warnAnisotropy(imagePlus, uiService)); }
@Test(expected = NullPointerException.class) public void testWarnAnisotropyThrowsNPEIfImageNull() { Common.warnAnisotropy(null, mock(UIService.class)); }
@Test(expected = NullPointerException.class) public void testWarnAnisotropyThrowsNPEIfUIServiceNull() { Common.warnAnisotropy(mock(ImagePlus.class), null); }