GroupUtil { public static void validateName(final String group) { if (!PROPERTY_ALLOWED_CHARACTERS.matcher(group).matches()) { throw new IllegalArgumentException("Group is invalid: " + group + ", it must match regex: " + PROPERTY_ALLOWED_CHARACTERS); } } private  GroupUtil(); static void validateName(final String group);  }
@Test public void shouldThrowExceptionWithInvalidStringName() { final Exception exception = assertThrows(IllegalArgumentException.class, () -> GroupUtil.validateName(INVALID_STRING)); final String expected = "Group is invalid: inv@l1dStr|ng&^, it must match regex: [a-zA-Z0-9|-]*"; assertEquals(expected, exception.getMessage()); }
@Test public void shouldPassValidationWithValidStringName() { assertDoesNotThrow(() -> GroupUtil.validateName(VALID_STRING)); }