TypeNameValidator { public static void validate(TypeName typeName) { Preconditions.checkArgument( CUSTOM_TYPE_PATTERN.matcher(typeName.getName()).matches() || PRIMITIVE_TYPES.contains(typeName.getName()), "TypeNames must be a primitive type %s or match pattern %s: %s", PRIMITIVE_TYPES, CUSTOM_TYPE_PATTERN, typeName.getName()); } private  TypeNameValidator(); static void validate(TypeName typeName);  }
@Test public void testValidNames() { TypeNameValidator.validate(TypeName.of("Camel", PACKAGE)); TypeNameValidator.validate(TypeName.of("CamelCase", PACKAGE)); TypeNameValidator.validate(TypeName.of("CamelCase1", PACKAGE)); TypeNameValidator.validate(TypeName.of("Camel1Case2", PACKAGE)); }
@Test public void testInvalidNames() { for (String invalid : new String[] {"a", "IFoo", "ABC", "$Special", "snake_case", "kebab-case", "Camel1B"}) { assertThatThrownBy(() -> TypeNameValidator.validate(TypeName.of(invalid, PACKAGE))) .isInstanceOf(IllegalArgumentException.class) .hasMessage( "TypeNames must be a primitive type" + " [STRING, DATETIME, INTEGER, DOUBLE, SAFELONG, BINARY, ANY, BOOLEAN, UUID, RID," + " BEARERTOKEN, UNKNOWN] or match pattern ^[A-Z][a-z0-9]+([A-Z][a-z0-9]+)*$: %s", invalid); } }