Skip to content

Commit

Permalink
Sort members
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Dec 27, 2024
1 parent 02f543d commit 75cdd06
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,30 +346,6 @@ public boolean isValid(final String code) {
return validate(code) == IBANValidatorStatus.VALID;
}

/**
* Validate an IBAN Code
*
* @param code The value validation is being performed on
* @return {@link IBANValidatorStatus} for validation
* @since 1.10.0
*/
public IBANValidatorStatus validate(String code) {
final Validator formatValidator = getValidator(code);
if (formatValidator == null) {
return IBANValidatorStatus.UNKNOWN_COUNTRY;
}

if (code.length() != formatValidator.ibanLength) {
return IBANValidatorStatus.INVALID_LENGTH;
}

if (!formatValidator.regexValidator.isValid(code)) {
return IBANValidatorStatus.INVALID_PATTERN;
}

return IBANCheckDigit.IBAN_CHECK_DIGIT.isValid(code) ? IBANValidatorStatus.VALID : IBANValidatorStatus.INVALID_CHECKSUM;
}

/**
* Installs a validator.
* Will replace any existing entry which has the same countryCode.
Expand Down Expand Up @@ -406,4 +382,28 @@ public Validator setValidator(final Validator validator) {
}
return validatorMap.put(validator.countryCode, validator);
}

/**
* Validate an IBAN Code
*
* @param code The value validation is being performed on
* @return {@link IBANValidatorStatus} for validation
* @since 1.10.0
*/
public IBANValidatorStatus validate(String code) {
final Validator formatValidator = getValidator(code);
if (formatValidator == null) {
return IBANValidatorStatus.UNKNOWN_COUNTRY;
}

if (code.length() != formatValidator.ibanLength) {
return IBANValidatorStatus.INVALID_LENGTH;
}

if (!formatValidator.regexValidator.isValid(code)) {
return IBANValidatorStatus.INVALID_PATTERN;
}

return IBANCheckDigit.IBAN_CHECK_DIGIT.isValid(code) ? IBANValidatorStatus.VALID : IBANValidatorStatus.INVALID_CHECKSUM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@ static Collection<Arguments> ibanRegistrySourceExamples() throws Exception {
return result;
}

public static Stream<Arguments> validateIbanStatuses() {
return Stream.of(
Arguments.of("XX", IBANValidatorStatus.UNKNOWN_COUNTRY),
Arguments.of("AD0101", IBANValidatorStatus.INVALID_LENGTH),
Arguments.of("AD12XX012030200359100100", IBANValidatorStatus.INVALID_PATTERN),
Arguments.of("AD9900012030200359100100", IBANValidatorStatus.INVALID_CHECKSUM),
Arguments.of("AD1200012030200359100100", IBANValidatorStatus.VALID)
);
}

@ParameterizedTest
@MethodSource("ibanRegistrySourceExamples")
public void exampleAccountsShouldBeValid(final String countryName, final String example) {
Expand Down Expand Up @@ -461,6 +471,12 @@ public void testValid(final String iban) {
assertTrue(VALIDATOR.isValid(iban), iban);
}

@ParameterizedTest
@MethodSource
public void validateIbanStatuses(String iban, IBANValidatorStatus expectedStatus) {
assertEquals(expectedStatus, IBANValidator.getInstance().validate(iban));
}

@ParameterizedTest
@MethodSource("ibanRegistrySource")
public void validatorShouldExistWithProperConfiguration(final String countryName, final String countryCode, final List<String> acountyCode, final int ibanLength, final String structure) throws Exception {
Expand All @@ -480,20 +496,4 @@ public void validatorShouldExistWithProperConfiguration(final String countryName
}
assertTrue(allPatterns.isEmpty(), "Unrecognized patterns: " + allPatterns + " for" + countryInfo);
}

public static Stream<Arguments> validateIbanStatuses() {
return Stream.of(
Arguments.of("XX", IBANValidatorStatus.UNKNOWN_COUNTRY),
Arguments.of("AD0101", IBANValidatorStatus.INVALID_LENGTH),
Arguments.of("AD12XX012030200359100100", IBANValidatorStatus.INVALID_PATTERN),
Arguments.of("AD9900012030200359100100", IBANValidatorStatus.INVALID_CHECKSUM),
Arguments.of("AD1200012030200359100100", IBANValidatorStatus.VALID)
);
}

@ParameterizedTest
@MethodSource
public void validateIbanStatuses(String iban, IBANValidatorStatus expectedStatus) {
assertEquals(expectedStatus, IBANValidator.getInstance().validate(iban));
}
}

0 comments on commit 75cdd06

Please sign in to comment.