CheckDigitLuhnMod10Verifier implements CheckDigitVerifier { public boolean isValid(String id) { int currentDigit; int idSum = 0; int position = 0; for (int i = id.length() - 1; i >= 0; i--) { String idCurrentRightmostDigit = id.substring(i, i + 1); try { currentDigit = Integer.parseInt(idCurrentRightmostDigit); } catch (NumberFormatException e) { return false; } if (position % 2 != 0) { currentDigit *= 2; if (currentDigit > 9) currentDigit -= 9; } position++; idSum += currentDigit; } return (idSum % 10 == 0); } private  CheckDigitLuhnMod10Verifier(); static CheckDigitVerifier getInstance(); boolean isValid(String id);  }
@Test public void testIsValid() { CheckDigitVerifier verifier = CheckDigitVerifiers.getVerifier(LuhnMod10); assertTrue(verifier.isValid("79927398713")); assertTrue(verifier.isValid("49927398716")); assertFalse(verifier.isValid("49927398717")); assertTrue(verifier.isValid("1234567812345670")); assertFalse(verifier.isValid("1234567812345678")); assertFalse(verifier.isValid("294217778")); }