ContrastChecker { public static boolean isContrastValid(final Color fgColor, final Color bgColor, Float coefficientLevel) { return getConstrastRatio(fgColor, bgColor) > coefficientLevel; } private  ContrastChecker(); static double distanceColor(final Color fgColor, final Color bgColor); static boolean isContrastValid(final Color fgColor, final Color bgColor, Float coefficientLevel); static double getConstrastRatio(final Color fgColor, final Color bgColor); static double getConstrastRatio5DigitRound(final Color fgColor, final Color bgColor); static double getConstrastRatio2DigitRound(final Color fgColor, final Color bgColor); static double getLuminosity(Color color);  }
@Test public void testisContrastValidWhiteBlack() { Color colorA = Color.WHITE; Color colorB = Color.BLACK; float coef = (float) 3.5; System.out.println("ContrastChecker - isContrastValid WhiteBlack : [WHITE] and [BLACK] for ["+ coef +"] = TRUE"); boolean result = ContrastChecker.isContrastValid(colorA, colorB, coef); assertTrue(result); }
@Test public void testisContrastValidTwoGreenFail() { Color colorA = new Color(70, 136, 71); Color colorB = new Color(223, 240, 216); float coef = (float) 4; System.out.println("ContrastChecker - isContrastValid TwoGreenFail : [#468847] and [#DFF0D8] for ["+ coef +"] = FALSE"); boolean result = ContrastChecker.isContrastValid(colorA, colorB, coef); assertFalse(result); }
@Test public void testisContrastValidTwoGreenPass() { Color colorA = new Color(70, 136, 71); Color colorB = new Color(223, 240, 216); float coef = (float) 3.5; System.out.println("ContrastChecker - isContrastValid TwoGreenPass : [#468847] and [#DFF0D8] for ["+ coef +"] = TRUE"); boolean result = ContrastChecker.isContrastValid(colorA, colorB, coef); assertTrue(result); }