Move ALPHABET from tests to InputValidator

This commit is contained in:
Paul Schaub 2018-11-15 01:34:59 +01:00
parent fa3b665047
commit 8534efdf60
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 7 additions and 7 deletions

View file

@ -5,17 +5,18 @@ import java.util.regex.Pattern;
public class InputValidator { public class InputValidator {
// Allowed characters // 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]. 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]. 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]. * Validate a given study number. Valid study numbers are 3-letter codes from the alphabet [a-zA-Z0-9].

View file

@ -10,8 +10,6 @@ public class InputValidatorTest {
private static final Random RAND = new Random(); 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. * 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) { private static String generateTestStringOfLength(int len) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) { 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(); return sb.toString();

View file

@ -12,7 +12,7 @@ import org.junit.Test;
*/ */
public class SampleTypeTest { 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]. * Test, whether all {@link SampleType} names are of length 1 and from the alphabet [a-zA-Z0-9].