void (@NotNull Icon icon, @NotNull UserScaleContext iconUserContext) { //((ScaleContextAware)icon).updateScaleContext(iconUserContext); ScaleContext iconContext = ScaleContext.Companion.create(iconUserContext); /* * (A) normal conditions */ //noinspection UnnecessaryLocalVariable Icon iconA = icon; double usrSize2D = iconContext.apply(ICON_BASE_SIZE, EFF_USR_SCALE); int usrSize = (int)Math.round(usrSize2D); int devSize = (int)Math.round(iconContext.apply(usrSize2D, DEV_SCALE)); assertIcon(iconA, iconContext, usrSize, devSize, "Test (A) normal conditions"); /* * (C) scale icon */ Function<ScaleContext, Pair<Integer /*scaled user size*/, Integer /*scaled dev size*/>> calcScales = (ctx) -> { double scaledUsrSize2D = ctx.apply(ICON_BASE_SIZE, EFF_USR_SCALE); int scaledUsrSize = (int)Math.round(scaledUsrSize2D); int scaledDevSize = (int)Math.round(iconContext.apply(scaledUsrSize2D, DEV_SCALE)); return new Pair<>(scaledUsrSize, scaledDevSize); }; Icon iconC = IconUtil.scale(icon, null, ICON_OBJ_SCALE); assertThat(iconC).isNotSameAs(icon); //assertThat(((ScaleContextAware)icon).getScaleContext()).isEqualTo(iconContext); ScaleContext contextC = ScaleContext.create(OBJ_SCALE.of(ICON_OBJ_SCALE)); Pair<Integer, Integer> scales = calcScales.apply(contextC); assertIcon(iconC, contextC, scales.first, scales.second, "Test (C) scale icon"); // Additionally, check that the original image hasn't changed after scaling var pair = createImageAndGraphics(iconContext.getScale(DEV_SCALE), icon.getIconWidth(), icon.getIconHeight()); BufferedImage iconImage = pair.first; Graphics2D g2d = pair.second; icon.paintIcon(null, g2d, 0, 0); BufferedImage goldImage = loadImage(getIconPath(), iconContext); ImageComparator.compareAndAssert( new ImageComparator.AASmootherComparator(0.1, 0.1, new Color(0, 0, 0, 0)), goldImage, iconImage, null); /* * (D) scale icon in iconContext */ Consumer<Float> scaleInContext = scale -> { ScaleContext contextD = ScaleContext.create(OBJ_SCALE.of(scale)); Icon iconD = IconUtil.scale(icon, contextD); // the new instance is returned assertThat(iconD).isNotSameAs(icon); // the original icon's iconContext has not changed //assertThat(((ScaleContextAware)icon).getScaleContext()).isEqualTo(iconContext); Pair<Integer, Integer> _scales = calcScales.apply(contextD); assertIcon(iconD, contextD, _scales.first, _scales.second, "Test (D) scale icon in iconContext"); }; scaleInContext.accept(1f); scaleInContext.accept(1.5f); }