BeanClassValidator { public void validate(Class<?> beanClass) { boolean added = validatedBeanClasses.add(beanClass); if (!added) return; var validator = new JSONClassValidator(beanClass) { @Override public void visitClass(Class<?> objectClass, String path) { super.visitClass(objectClass, path); beanClassNameValidator.validate(objectClass); } @Override public void visitEnum(Class<?> enumClass) { super.visitEnum(enumClass); beanClassNameValidator.validate(enumClass); } }; validator.validate(); }  void validate(Class<?> beanClass); final BeanClassNameValidator beanClassNameValidator; }
@Test void validate() { validator.validate(TestBean.class); }
@Test void validateWithList() { assertThatThrownBy(() -> validator.validate(List.class)) .isInstanceOf(Error.class) .hasMessageContaining("class must be bean class"); }
@Test void validateWithDuplicateClassName() { validator.beanClassNameValidator.beanClasses.put(Classes.className(TestBean.class), Void.class); assertThatThrownBy(() -> validator.validate(TestBean.class)) .isInstanceOf(Error.class) .hasMessageContaining("found bean class with duplicate name which can be confusing"); }
@Test void validateWithDuplicateEnumName() { validator.beanClassNameValidator.beanClasses.put(Classes.className(TestBean.TestEnum.class), Void.class); assertThatThrownBy(() -> validator.validate(TestBean.class)) .isInstanceOf(Error.class) .hasMessageContaining("found bean class with duplicate name which can be confusing"); }