ErrorNamespaceValidator { public static void validate(ErrorNamespace name) { Preconditions.checkArgument( UPPER_CAMEL_CASE.matcher(name.get()).matches(), "Namespace for errors must match pattern %s: %s", UPPER_CAMEL_CASE, name); } private  ErrorNamespaceValidator(); static void validate(ErrorNamespace name);  }
@Test public void testValidErrorNamespaces() throws Exception { ErrorNamespaceValidator.validate(ErrorNamespace.of("Conjure")); ErrorNamespaceValidator.validate(ErrorNamespace.of("PalantirFoo")); ErrorNamespaceValidator.validate(ErrorNamespace.of("PalantirFooBar")); }
@Test public void testInvalidErrorNamespaces() { for (String invalid : new String[] {"conjure", "palantirFoo", "palantir-foo", "PALANTIR-FOO", "palantir_foo", "PALANTIR_FOO" }) { assertThatThrownBy(() -> ErrorNamespaceValidator.validate(ErrorNamespace.of(invalid))) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("Namespace for errors must match pattern") .hasMessageContaining(invalid); } }