1

In our project we are testing jpa database access with the weld-junit5 framework. The EntityManager is injected into the test class. The entity to be saved is annotated with a custom validator.

https://github.com/duschata/testingIssues/blob/ce5c6d0bd8b778e75d69246f39d78da16305caaa/src/main/java/com/foo/bar/entity/TestEntity.java#L21-L22

The problem is that the custom validator itself needs an instance, which in this case is not injected.

https://github.com/duschata/testingIssues/blob/ce5c6d0bd8b778e75d69246f39d78da16305caaa/src/main/java/com/foo/bar/validation/MyValidator.java#L10-L28

A nullpointer exception is thrown here because myDao was not instantiated.

For more clarity you can browse throw this essential project on github (branch validation)

https://github.com/duschata/testingIssues/tree/validation

Kind regards Tom

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58
duschata
  • 33
  • 5
  • Entry point for the test is here: https://github.com/duschata/testingIssues/blob/validation/src/test/java/com/foo/bar/WeldSEHibernateValidationTest.java – duschata Sep 03 '21 at 05:28

0 Answers0