NameValidationUtils { public static void validateApplicationId(String id) { String message = "Application Id <" + id + "> contains forbidden characters. Only alphanumeric and _ characters are allowed here."; validate("applicationId", id, DEFAULT_NAME_REGEX, message); }  static boolean isValid(String name); static void validate(String ownerKey, String name); static void validateApplicationName(String name); static void validateApplicationId(String id); static void validateNodeName(String name); static final String DEFAULT_NAME_REGEX; static final Pattern DEFAULT_NAME_REPLACE_PATTERN; static final String APPLICATION_NAME_REGEX; static final String NODE_NAME_REGEX; }
@Test public void validateApplicationIdTest() { NameValidationUtils.validateApplicationId("app"); NameValidationUtils.validateApplicationId("app_2"); List<String> invalids = Lists.newArrayList("appè", "App-2", "App.unix", "App 2"); invalids.forEach(invalid -> { expectException(new Callable() { @Override public Object call() throws Exception { NameValidationUtils.validateApplicationId(invalid); return null; } }, InvalidNameException.class); }); }