Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ public boolean isValid(final String code) {
if (!(cde instanceof String)) {
return false;
}
final String validated = (String) cde;
try {
final int modulusResult = INSTANCE.calculateModulus((String) cde, true);
return modulusResult == Character.getNumericValue(code.charAt(code.length() - 1));
final int modulusResult = INSTANCE.calculateModulus(validated, true);
return modulusResult == Character.getNumericValue(validated.charAt(validated.length() - 1));
} catch (final CheckDigitException ex) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ public boolean isValid(final String code) {
if (!(cde instanceof String)) {
return false;
}
final String validated = (String) cde;
try {
final int modulusResult = INSTANCE.calculateModulus((String) cde, true);
return modulusResult == Character.getNumericValue(code.charAt(code.length() - 1));
final int modulusResult = INSTANCE.calculateModulus(validated, true);
return modulusResult == Character.getNumericValue(validated.charAt(validated.length() - 1));
} catch (final CheckDigitException ex) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
*/
package org.apache.commons.validator.routines.checkdigit;

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* CAS Number Check Digit Tests.
Expand Down Expand Up @@ -55,4 +58,13 @@ protected void setUp() {
valid = new String[] {MIN, WATER, ETHANOL, ASPIRIN, COFFEIN, FORMALDEHYDE, DEXAMETHASONE, ARSENIC, ASBESTOS, MAX};
}

/**
* The format validator trims the input, so surrounding whitespace must not change the result.
*/
@Test
void testIsValidSurroundingWhitespace() {
assertTrue(routine.isValid(" " + WATER), "leading whitespace");
assertTrue(routine.isValid(WATER + " "), "trailing whitespace");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
*/
package org.apache.commons.validator.routines.checkdigit;

import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* EC Number Check Digit Tests.
Expand Down Expand Up @@ -51,4 +54,13 @@ protected void setUp() {
valid = new String[] {MIN, FORMALDEHYDE, DEXAMETHASONE, ARSENIC, ASBESTOS, MAX};
}

/**
* The format validator trims the input, so surrounding whitespace must not change the result.
*/
@Test
void testIsValidSurroundingWhitespace() {
assertTrue(routine.isValid(" " + DEXAMETHASONE), "leading whitespace");
assertTrue(routine.isValid(DEXAMETHASONE + " "), "trailing whitespace");
}

}
Loading