### Question:
ColorUtilities { public static Color opacitizeColor(Color startingColor, float alpha) { if (alpha < 0f || alpha > 1f) { throw new IllegalArgumentException("Alpha [" + alpha + "] cannot be less than 0 or greater than 1."); } if (startingColor == null || startingColor.getAlpha() == alpha) { return startingColor; } return new Color(startingColor.getRGB() & 0xffffff | (int)(alpha * 0xff + 0.5) << 24, true); } private  ColorUtilities(); static Color blendColors(Color color1, Color color2); static Color brighten(Color input, double factor); static Color convertFromColorString(String color); static Color convertFromHexString(String color, int redIndex, int greenIndex, int blueIndex); static Color convertFromHexString(String color, int redIndex, int greenIndex, int blueIndex, int alphaIndex); static String convertToHexString(Color color, int redIndex, int greenIndex, int blueIndex); static String convertToHexString(Color color, int redIndex, int greenIndex, int blueIndex, int alphaIndex); static String convertToRGBAColorString(Color aColor); static Color darken(Color input, double factor); static Color lighten(Color color); static int getBrightness(Color color); static Color getContrastingColor(Color color); static Color getAlternateColor(Color color, int shift); static boolean isEqual(Color c1, Color c2); static boolean isEqualIgnoreAlpha(Color c1, Color c2); static Color opacitizeColor(Color startingColor, float alpha); static Color opacitizeColor(Color startingColor, int alpha); static final int COLOR_COMPONENT_MAX_VALUE; }### Answer:
@Test public void testOpacitizeColorFloat() { Assert.assertNull(ColorUtilities.opacitizeColor(null, 1f)); Assert.assertEquals(new Color(.1f, .2f, .3f, .5f), ColorUtilities.opacitizeColor(new Color(.1f, .2f, .3f, .4f), .5f)); Assert.assertEquals(new Color(0f, 1f, 0f, 0f), ColorUtilities.opacitizeColor(new Color(0f, 1f, 0f, 1f), 0f)); Assert.assertEquals(new Color(0f, 1f, 0f, 1f), ColorUtilities.opacitizeColor(new Color(0f, 1f, 0f, 1f), 1f)); }
@Test(expected = IllegalArgumentException.class) public void testOpacitizeColorFloatBadInput1() { ColorUtilities.opacitizeColor(Color.RED, -Float.MIN_VALUE); }
@Test(expected = IllegalArgumentException.class) public void testOpacitizeColorFloatBadInput12() { ColorUtilities.opacitizeColor(Color.RED, 1.0000001f); }
@Test public void testOpacitizeColorInt() { Assert.assertNull(ColorUtilities.opacitizeColor(null, 1f)); Assert.assertEquals(new Color(1, 2, 3, 5), ColorUtilities.opacitizeColor(new Color(1, 2, 3, 4), 5)); Assert.assertEquals(new Color(0, 1, 0, 0), ColorUtilities.opacitizeColor(new Color(0, 1, 0, 1), 0)); Assert.assertEquals(new Color(0, 1, 0, 255), ColorUtilities.opacitizeColor(new Color(0, 1, 0, 255), 255)); }
@Test(expected = IllegalArgumentException.class) public void testOpacitizeColorIntBadInput1() { ColorUtilities.opacitizeColor(Color.RED, -1); }
@Test(expected = IllegalArgumentException.class) public void testOpacitizeColorIntBadInput12() { ColorUtilities.opacitizeColor(Color.RED, 256); }