Skip to content
Advertisement

Spring unit test issue with Validator

I am trying to write unit test for a validator class that I have. So within my UniqueEmailValidator class, I injected a @Service component to check if it exist.

JavaScript

And I tried to write unit test for this constraint validator.

JavaScript

How do I initialize the AccountService within the Validator class? It seem like it wasn’t injected, hence, the null exception. Here’s the trace.

JavaScript

Thanks.

Advertisement

Answer

The actual problem is deep down in the stack-trace that you’ve provided:

JavaScript

This error message is thrown because there is some code that is trying to instantiate the UniqueEmailValidator class constructor without any parameters. The problem will be resolved by adding a default constructor to this class:

JavaScript

Hope this helps!

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement