Skip to content

Commit

Permalink
feat(impl): [#528] allow only BPNL
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmf committed May 7, 2024
1 parent bfb4998 commit 11ba40f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class BusinessPartnerNumberListValidator
/**
* Regex for BPN.
*/
public static final String BPN_REGEX = "(BPN)[LSA][\\w\\d]{10}[\\w\\d]{2}";
public static final String BPN_REGEX = "(BPNL)[\\w\\d]{10}[\\w\\d]{2}";

private static final Pattern PATTERN = Pattern.compile(BPN_REGEX);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import jakarta.validation.ConstraintValidatorContext;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
Expand Down Expand Up @@ -73,4 +75,19 @@ void withListContainingInvalidBPN() {
verify(contextMock).buildConstraintViolationWithTemplate(messageCaptor.capture());
assertThat(messageCaptor.getValue()).contains("BPN").contains(" index 1 ").contains("invalid");
}

@ParameterizedTest
@ValueSource(strings = { "BPN",
"BPNL",
"BPNACB",
"BPNA1234567890AB",
"BPNS1234567890AB",
"DELETE * FROM Table",
"ERRRES"
})
void withInvalidBPN(final String invalidBPN) {
assertThat(validator.isValid(Collections.singletonList(invalidBPN), contextMock)).isFalse();
verify(contextMock).buildConstraintViolationWithTemplate(messageCaptor.capture());
assertThat(messageCaptor.getValue()).contains("BPN").contains(" index 0 ").contains("invalid");
}
}

0 comments on commit 11ba40f

Please sign in to comment.