ResultUtils { public static <S extends AnnotatedSpace<CalibratedAxis>> String getUnitHeader( final S space, final UnitService unitService, final char exponent) { final Optional<String> unit = AxisUtils.getSpatialUnit(space, unitService); if (!unit.isPresent()) { return ""; } final String unitHeader = unit.get(); if (unitHeader.isEmpty()) { return ""; } return "(" + unitHeader + exponent + ")"; } private  ResultUtils(); static char getExponent(final S space); static String getSizeDescription(final S space); static String getUnitHeader(
		final S space, final UnitService unitService, final char exponent); static String getUnitHeader(final ImagePlus imagePlus); static long toConventionalIndex(final AxisType type,
		final long index);  }
@Test public void testGetUnitHeader() { final String unit = "mm"; final char exponent = '³'; final DefaultLinearAxis axis = new DefaultLinearAxis(Axes.X, unit); final Img<DoubleType> img = ArrayImgs.doubles(10); final ImgPlus<DoubleType> imgPlus = new ImgPlus<>(img, "Test image", axis); final String result = ResultUtils.getUnitHeader(imgPlus, unitService, exponent); assertEquals("Unexpected unit header", "(" + unit + exponent + ")", result); }
@Test public void testGetUnitHeaderEmptyIfNoUnit() { final DefaultLinearAxis axis = new DefaultLinearAxis(Axes.X); final Img<DoubleType> img = ArrayImgs.doubles(10); final ImgPlus<DoubleType> imgPlus = new ImgPlus<>(img, "Test image", axis); final String result = ResultUtils.getUnitHeader(imgPlus, unitService, '³'); assertTrue("Unit header should be empty", result.isEmpty()); }
@Test(expected = NullPointerException.class) public void testGetUnitHeaderThrowsNPEIfSpaceNull() { ResultUtils.getUnitHeader(null, unitService, '³'); }
@Test(expected = NullPointerException.class) public void testGetUnitHeaderThrowsNPEIfUnitServiceNull() { final Img<DoubleType> img = ArrayImgs.doubles(10); final ImgPlus<DoubleType> imgPlus = new ImgPlus<>(img, "Test image", new DefaultLinearAxis(Axes.X, "mm")); ResultUtils.getUnitHeader(imgPlus, null, '³'); }
@Test public void testGetUnitHeaderImagePlus() { final ImagePlus imagePlus = new ImagePlus(); final Calibration calibration = new Calibration(); final String unit = "mm"; calibration.setUnit(unit); imagePlus.setCalibration(calibration); final String unitHeader = ResultUtils.getUnitHeader(imagePlus); assertEquals("(" + unit + ")", unitHeader); }
@Test public void testGetUnitHeaderImagePlusDefaultUnit() { final ImagePlus imagePlus = new ImagePlus(); final Calibration calibration = new Calibration(); imagePlus.setCalibration(calibration); final String unitHeader = ResultUtils.getUnitHeader(imagePlus); assertEquals("(pixel)", unitHeader); }
@Test(expected = NullPointerException.class) public void testGetUnitHeaderThrowsNPEIfImagePlusNull() { ResultUtils.getUnitHeader(null); }
@Test public void testGetUnitHeaderReturnPixelIfDefaultUnitPixel() { final String unit = "pixel"; final String expected = "(" + unit + "³)"; final DefaultLinearAxis axis = new DefaultLinearAxis(Axes.X, unit); final Img<DoubleType> img = ArrayImgs.doubles(10); final ImgPlus<DoubleType> imgPlus = new ImgPlus<>(img, "Test image", axis); final String result = ResultUtils.getUnitHeader(imgPlus, unitService, '³'); assertEquals(expected, result); }
@Test public void testGetUnitHeaderReturnUnitIfDefaultUnit() { final String unit = "unit"; final String expected = "(" + unit + "³)"; final DefaultLinearAxis axis = new DefaultLinearAxis(Axes.X, unit); final Img<DoubleType> img = ArrayImgs.doubles(10); final ImgPlus<DoubleType> imgPlus = new ImgPlus<>(img, "Test image", axis); final String result = ResultUtils.getUnitHeader(imgPlus, unitService, '³'); assertEquals(expected, result); }