Skip to content

Tag: junit

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. And I tried to write unit test for this constraint validator. How do I initialize the AccountService within the Validator class? It seem like it wasn’t injected, hence, the null exception.

JUnitParams with Mockito

This could be a XY problem but I want to ask: I am using JUnitParams to be able to run my test method 10 times with different objects. The problem is that the injections don’t work (@Mock and @InjectMocks). I can use to mock the PersonService in the @Test method. But how do mock the “main” object that is annotated