Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

HV-901 Changing ModUtil to return values in the range of 0 to 9 in ca…

…se of mod 10
  • Loading branch information...
commit 01463c506fca77cf5dc48af54591a94202e59684 1 parent 2248d0e
@hferentschik hferentschik authored gunnarmorling committed
View
2  ...ain/java/org/hibernate/validator/internal/constraintvalidators/hv/LuhnCheckValidator.java
@@ -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;
}
}
View
2  ...in/java/org/hibernate/validator/internal/constraintvalidators/hv/Mod10CheckValidator.java
@@ -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;
}
}
View
16 engine/src/main/java/org/hibernate/validator/internal/util/ModUtil.java
@@ -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;
}
/**
@@ -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;
}
/**
View
9 ...ernate/validator/test/internal/constraintvalidators/hv/CreditCardNumberValidatorTest.java
@@ -76,6 +76,15 @@ public void testValidCreditCardNumberAsCharSequence() throws Exception {
}
@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() );
assertNumberOfViolations( constraintViolations, 0 );
Please sign in to comment.
Something went wrong with that request. Please try again.