Move ALPHABET from tests to InputValidator
This commit is contained in:
parent
fa3b665047
commit
8534efdf60
3 changed files with 7 additions and 7 deletions
|
@ -5,17 +5,18 @@ import java.util.regex.Pattern;
|
|||
public class InputValidator {
|
||||
|
||||
// Allowed characters
|
||||
public static final String ALPHABET = "[a-zA-Z0-9]";
|
||||
public static final String REGEX_ALPHABET = "[a-zA-Z0-9]";
|
||||
public static final String ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
|
||||
/*
|
||||
REGEX pattern for study numbers. Allowed are all 3-letter numbers from the alphabet [a-zA-Z0-9].
|
||||
*/
|
||||
private static final Pattern STUDY_NUMBER_MATCHER = Pattern.compile(ALPHABET+"{3}");
|
||||
private static final Pattern STUDY_NUMBER_MATCHER = Pattern.compile(REGEX_ALPHABET +"{3}");
|
||||
|
||||
/*
|
||||
REGEX pattern for sample numbers. Allowed are four-letter numbers from the alphabet [a-zA-Z0-9].
|
||||
*/
|
||||
private static final Pattern SAMPLE_NUMBER_MATCHER = Pattern.compile(ALPHABET+"{4}");
|
||||
private static final Pattern SAMPLE_NUMBER_MATCHER = Pattern.compile(REGEX_ALPHABET +"{4}");
|
||||
|
||||
/**
|
||||
* Validate a given study number. Valid study numbers are 3-letter codes from the alphabet [a-zA-Z0-9].
|
||||
|
|
|
@ -10,8 +10,6 @@ public class InputValidatorTest {
|
|||
|
||||
private static final Random RAND = new Random();
|
||||
|
||||
private static final String ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
|
||||
/**
|
||||
* Test, whether {@link InputValidator#validateStudyNumber(String)} accepts 3 digit inputs from the allowed alphabet.
|
||||
*
|
||||
|
@ -71,7 +69,8 @@ public class InputValidatorTest {
|
|||
private static String generateTestStringOfLength(int len) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < len; i++) {
|
||||
sb.append(ALPHABET.charAt(RAND.nextInt(ALPHABET.length())));
|
||||
sb.append(InputValidator.ALPHABET.charAt(
|
||||
RAND.nextInt(InputValidator.ALPHABET.length())));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.junit.Test;
|
|||
*/
|
||||
public class SampleTypeTest {
|
||||
|
||||
private static final Pattern SAMPLE_TYPE_VALUE_PATTERN = Pattern.compile(InputValidator.ALPHABET);
|
||||
private static final Pattern SAMPLE_TYPE_VALUE_PATTERN = Pattern.compile(InputValidator.REGEX_ALPHABET);
|
||||
|
||||
/**
|
||||
* Test, whether all {@link SampleType} names are of length 1 and from the alphabet [a-zA-Z0-9].
|
||||
|
|
Loading…
Reference in a new issue