Colors { @ColorInt public static int blend(@ColorInt final int first, @ColorInt final int second) { return blend(first, second, RATIO_DEFAULT); } private  Colors(); @ColorInt static int withAlpha(@ColorInt final int color, @FloatRange(from = 0, to = 1) final float alphaRatio); @ColorInt static int withAlpha(@ColorInt final int color, @IntRange(from = COMPONENT_VALUE_MIN, to = COMPONENT_VALUE_MAX) final int alpha); @ColorInt static int blend(@ColorInt final int first, @ColorInt final int second); @SuppressWarnings("UnnecessaryLocalVariable") @ColorInt static int blend(@ColorInt final int first, @ColorInt final int second, @FloatRange(from = 0, to = 1) final float blendingRatio); @ColorInt static int brighter(@ColorInt final int color, @FloatRange(from = 0, to = 1) final float fraction); @ColorInt static int darker(@ColorInt final int color, @FloatRange(from = 0, to = 1) final float fraction); @ColorInt static int random(final boolean randomAlpha); @NonNull static String hexName(@ColorInt final int color); @NonNull static String hexName(@ColorInt final int color, final boolean withAlpha);  }
@Test public void testBlendWithDefaultRatio() { final int firstColor = Color.parseColor("#FF2196F3"); final int secondColor = Color.parseColor("#FF4CAF50"); assertThat(Colors.blend(firstColor, secondColor), is(Colors.blend(firstColor, secondColor, 0.5f))); }
@Test public void testBlendWithRatio() { final int firstColor = Color.parseColor("#FF2196F3"); final int secondColor = Color.parseColor("#FF4CAF50"); assertThat(Colors.blend(firstColor, secondColor, 0f), is(secondColor)); assertThat(Colors.blend(firstColor, secondColor, 1f), is(firstColor)); assertThat(Colors.blend(firstColor, secondColor, 0.5f), is(not(firstColor))); assertThat(Colors.blend(firstColor, secondColor, 0.5f), is(not(secondColor))); }
@Test(expected = IllegalArgumentException.class) public void testBlendWithRatioOutOfRangeOver() { Colors.blend(0, 0, 1.1f); }
@Test(expected = IllegalArgumentException.class) public void testBlendWithRatioOutOfRangeUnder() { Colors.blend(0, 0, -0.1f); }