@Test public void product_identifiers_containing_non_alphaebtic_digit_and_no_underscore_are_not_accepted() { assertNotNull(validatorToTest.createValidationErrorMessage("$")); assertNotNull(validatorToTest.createValidationErrorMessage("x$")); assertNotNull(validatorToTest.createValidationErrorMessage("x-")); assertNotNull(validatorToTest.createValidationErrorMessage("-")); assertNotNull(validatorToTest.createValidationErrorMessage("!")); }
public String createValidationErrorMessage(String productId) { if (productId == null || productId.trim().isEmpty()) { return "product identifier not set!"; } if (productId.length() > 30) { return "product identifier length too big:" + productId.length() + ", allowed is only 30"; } for (char c : productId.toCharArray()) { if (Character.isAlphabetic(c)) { continue; } if (Character.isDigit(c)) { continue; } if (c == '_') { continue; } return "unexpected char inside product identifier found:" + c + ", allowed is only [a-zA-Z0-9_]"; } return null; }
PDSProductIdentifierValidator { public String createValidationErrorMessage(String productId) { if (productId == null || productId.trim().isEmpty()) { return "product identifier not set!"; } if (productId.length() > 30) { return "product identifier length too big:" + productId.length() + ", allowed is only 30"; } for (char c : productId.toCharArray()) { if (Character.isAlphabetic(c)) { continue; } if (Character.isDigit(c)) { continue; } if (c == '_') { continue; } return "unexpected char inside product identifier found:" + c + ", allowed is only [a-zA-Z0-9_]"; } return null; } }
PDSProductIdentifierValidator { public String createValidationErrorMessage(String productId) { if (productId == null || productId.trim().isEmpty()) { return "product identifier not set!"; } if (productId.length() > 30) { return "product identifier length too big:" + productId.length() + ", allowed is only 30"; } for (char c : productId.toCharArray()) { if (Character.isAlphabetic(c)) { continue; } if (Character.isDigit(c)) { continue; } if (c == '_') { continue; } return "unexpected char inside product identifier found:" + c + ", allowed is only [a-zA-Z0-9_]"; } return null; }  }
PDSProductIdentifierValidator { public String createValidationErrorMessage(String productId) { if (productId == null || productId.trim().isEmpty()) { return "product identifier not set!"; } if (productId.length() > 30) { return "product identifier length too big:" + productId.length() + ", allowed is only 30"; } for (char c : productId.toCharArray()) { if (Character.isAlphabetic(c)) { continue; } if (Character.isDigit(c)) { continue; } if (c == '_') { continue; } return "unexpected char inside product identifier found:" + c + ", allowed is only [a-zA-Z0-9_]"; } return null; }  String createValidationErrorMessage(String productId); }
PDSProductIdentifierValidator { public String createValidationErrorMessage(String productId) { if (productId == null || productId.trim().isEmpty()) { return "product identifier not set!"; } if (productId.length() > 30) { return "product identifier length too big:" + productId.length() + ", allowed is only 30"; } for (char c : productId.toCharArray()) { if (Character.isAlphabetic(c)) { continue; } if (Character.isDigit(c)) { continue; } if (c == '_') { continue; } return "unexpected char inside product identifier found:" + c + ", allowed is only [a-zA-Z0-9_]"; } return null; }  String createValidationErrorMessage(String productId);  }