@Test public void testInvalidNames() throws Exception { for (String invalid : new String[] { "UpperCamelCase", "Upper-Kebab-Case", "Upper_Snake_Case", "ABC", "$special", "special%", "snake_123_case", "kebab-123-case", "mixed-kebab_snake-case", "defaultDNSName" }) { assertThatThrownBy(() -> FieldNameValidator.validate(FieldName.of(invalid))) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining( String.format("FieldName \"%s\" must follow one of the following patterns", invalid)); } }
@SuppressWarnings("Slf4jLogsafeArgs") public static void validate(FieldName fieldName) { Preconditions.checkArgument( CaseConverter.CAMEL_CASE_PATTERN.matcher(fieldName.get()).matches() || CaseConverter.KEBAB_CASE_PATTERN .matcher(fieldName.get()) .matches() || CaseConverter.SNAKE_CASE_PATTERN .matcher(fieldName.get()) .matches(), "FieldName \"%s\" must follow one of the following patterns: %s", fieldName, Arrays.toString(CaseConverter.Case.values())); if (!CaseConverter.CAMEL_CASE_PATTERN.matcher(fieldName.get()).matches()) { log.warn( "{} should be specified in lowerCamelCase. kebab-case and snake_case are supported for " + "legacy endpoints only: {}", FieldName.class, fieldName.get()); } }
FieldNameValidator { @SuppressWarnings("Slf4jLogsafeArgs") public static void validate(FieldName fieldName) { Preconditions.checkArgument( CaseConverter.CAMEL_CASE_PATTERN.matcher(fieldName.get()).matches() || CaseConverter.KEBAB_CASE_PATTERN .matcher(fieldName.get()) .matches() || CaseConverter.SNAKE_CASE_PATTERN .matcher(fieldName.get()) .matches(), "FieldName \"%s\" must follow one of the following patterns: %s", fieldName, Arrays.toString(CaseConverter.Case.values())); if (!CaseConverter.CAMEL_CASE_PATTERN.matcher(fieldName.get()).matches()) { log.warn( "{} should be specified in lowerCamelCase. kebab-case and snake_case are supported for " + "legacy endpoints only: {}", FieldName.class, fieldName.get()); } } }
FieldNameValidator { @SuppressWarnings("Slf4jLogsafeArgs") public static void validate(FieldName fieldName) { Preconditions.checkArgument( CaseConverter.CAMEL_CASE_PATTERN.matcher(fieldName.get()).matches() || CaseConverter.KEBAB_CASE_PATTERN .matcher(fieldName.get()) .matches() || CaseConverter.SNAKE_CASE_PATTERN .matcher(fieldName.get()) .matches(), "FieldName \"%s\" must follow one of the following patterns: %s", fieldName, Arrays.toString(CaseConverter.Case.values())); if (!CaseConverter.CAMEL_CASE_PATTERN.matcher(fieldName.get()).matches()) { log.warn( "{} should be specified in lowerCamelCase. kebab-case and snake_case are supported for " + "legacy endpoints only: {}", FieldName.class, fieldName.get()); } } private  FieldNameValidator(); }
FieldNameValidator { @SuppressWarnings("Slf4jLogsafeArgs") public static void validate(FieldName fieldName) { Preconditions.checkArgument( CaseConverter.CAMEL_CASE_PATTERN.matcher(fieldName.get()).matches() || CaseConverter.KEBAB_CASE_PATTERN .matcher(fieldName.get()) .matches() || CaseConverter.SNAKE_CASE_PATTERN .matcher(fieldName.get()) .matches(), "FieldName \"%s\" must follow one of the following patterns: %s", fieldName, Arrays.toString(CaseConverter.Case.values())); if (!CaseConverter.CAMEL_CASE_PATTERN.matcher(fieldName.get()).matches()) { log.warn( "{} should be specified in lowerCamelCase. kebab-case and snake_case are supported for " + "legacy endpoints only: {}", FieldName.class, fieldName.get()); } } private  FieldNameValidator(); static String capitalize(FieldName fieldName); static FieldName toCase(FieldName fieldName, CaseConverter.Case targetCase); @SuppressWarnings("Slf4jLogsafeArgs") static void validate(FieldName fieldName); }
FieldNameValidator { @SuppressWarnings("Slf4jLogsafeArgs") public static void validate(FieldName fieldName) { Preconditions.checkArgument( CaseConverter.CAMEL_CASE_PATTERN.matcher(fieldName.get()).matches() || CaseConverter.KEBAB_CASE_PATTERN .matcher(fieldName.get()) .matches() || CaseConverter.SNAKE_CASE_PATTERN .matcher(fieldName.get()) .matches(), "FieldName \"%s\" must follow one of the following patterns: %s", fieldName, Arrays.toString(CaseConverter.Case.values())); if (!CaseConverter.CAMEL_CASE_PATTERN.matcher(fieldName.get()).matches()) { log.warn( "{} should be specified in lowerCamelCase. kebab-case and snake_case are supported for " + "legacy endpoints only: {}", FieldName.class, fieldName.get()); } } private  FieldNameValidator(); static String capitalize(FieldName fieldName); static FieldName toCase(FieldName fieldName, CaseConverter.Case targetCase); @SuppressWarnings("Slf4jLogsafeArgs") static void validate(FieldName fieldName);  }