From 8534efdf6031a2e99047bb881c8a554cb238c6bc Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 15 Nov 2018 01:34:59 +0100 Subject: [PATCH] Move ALPHABET from tests to InputValidator --- .../java/de/vanitasvitae/imi/codes/InputValidator.java | 7 ++++--- .../java/de/vanitasvitae/imi/codes/InputValidatorTest.java | 5 ++--- .../java/de/vanitasvitae/imi/codes/SampleTypeTest.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/vanitasvitae/imi/codes/InputValidator.java b/src/main/java/de/vanitasvitae/imi/codes/InputValidator.java index c9641b9..9dba898 100644 --- a/src/main/java/de/vanitasvitae/imi/codes/InputValidator.java +++ b/src/main/java/de/vanitasvitae/imi/codes/InputValidator.java @@ -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]. diff --git a/src/test/java/de/vanitasvitae/imi/codes/InputValidatorTest.java b/src/test/java/de/vanitasvitae/imi/codes/InputValidatorTest.java index 47275cc..261615d 100644 --- a/src/test/java/de/vanitasvitae/imi/codes/InputValidatorTest.java +++ b/src/test/java/de/vanitasvitae/imi/codes/InputValidatorTest.java @@ -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(); diff --git a/src/test/java/de/vanitasvitae/imi/codes/SampleTypeTest.java b/src/test/java/de/vanitasvitae/imi/codes/SampleTypeTest.java index 8580842..4ef5d84 100644 --- a/src/test/java/de/vanitasvitae/imi/codes/SampleTypeTest.java +++ b/src/test/java/de/vanitasvitae/imi/codes/SampleTypeTest.java @@ -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].