NameValidationUtils { public static void validateApplicationName(String name) { String message = "Application name <" + name + "> contains forbidden character."; validate("applicationName", name, APPLICATION_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 validateApplicationNameTest() { NameValidationUtils.validateApplicationName("app"); NameValidationUtils.validateApplicationName("app_2"); NameValidationUtils.validateApplicationName("app 2"); NameValidationUtils.validateApplicationName("app é 2"); List<String> invalids = Lists.newArrayList("app/hehe", "app\\dqdv", "app\\/dqdv"); invalids.forEach(invalid -> { expectException(new Callable() { @Override public Object call() throws Exception { NameValidationUtils.validateApplicationName(invalid); return null; } }, InvalidNameException.class); }); }