Skip to content

Commit

Permalink
HV-901 Changing ModUtil to return values in the range of 0 to 9 in ca…
Browse files Browse the repository at this point in the history
…se of mod 10
  • Loading branch information
hferentschik committed Jul 24, 2014
1 parent 04fc9a3 commit e3a1bb5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
Expand Up @@ -57,7 +57,7 @@ public boolean isCheckDigitValid(List<Integer> digits, char checkDigit) {
int modResult = ModUtil.calculateLuhnMod10Check( digits );
int checkValue = extractDigit( checkDigit );

return modResult == checkValue;
return checkValue == modResult;
}

}
Expand Up @@ -81,7 +81,7 @@ public boolean isCheckDigitValid(List<Integer> digits, char checkDigit) {
int modResult = ModUtil.calculateMod10Check( digits, this.multiplier, this.weight );
int checkValue = extractDigit( checkDigit );

return modResult < 10 ? checkValue == modResult : checkValue == 0;
return checkValue == modResult;
}

}
Expand Up @@ -49,7 +49,7 @@ public static int calculateLuhnMod10Check(final List<Integer> digits) {
sum += digit;
even = !even;
}
return 10 - ( sum % 10 );
return ( 10 - ( sum % 10 ) ) % 10;
}

/**
Expand Down Expand Up @@ -77,19 +77,7 @@ public static int calculateMod10Check(final List<Integer> digits, int multiplier
sum += digit;
even = !even;
}
return 10 - ( sum % 10 );
}

/**
* Calculate Generic Modulo 10 checksum
*
* @param digits The digits over which to calculate the checksum
* @param multiplier Multiplier used in the algorithm
*
* @return the result of the mod10 checksum calculation assuming weight = 1
*/
public static int calculateMod10Check(final List<Integer> digits, int multiplier) {
return calculateMod10Check( digits, multiplier, 1 );
return ( 10 - ( sum % 10 ) ) % 10;
}

/**
Expand Down
Expand Up @@ -74,6 +74,15 @@ public void testValidCreditCardNumberAsCharSequence() throws Exception {
assertNumberOfViolations( constraintViolations, 0 );
}

@Test
@TestForIssue(jiraKey = "HV-901")
public void testValidCreditCardNumberWithZeroCheckDigit() throws Exception {
CreditCard card = new CreditCard();
card.setCreditCardNumber( "5105105105105100" );
Set<ConstraintViolation<CreditCard>> constraintViolations = validator.validate( card );
assertNumberOfViolations( constraintViolations, 0 );
}

@Test
public void testNullValue() throws Exception {
Set<ConstraintViolation<CreditCard>> constraintViolations = validator.validate( new CreditCard() );
Expand Down

0 comments on commit e3a1bb5

Please sign in to comment.