How to make spring boot @Value fields inject the values from properties?

@ExtendWith(MockitoExtension.class)
@TestPropertySource("classpath:application-test.properties")
class AuthServiceTests {

    @Mock
    private UserService userService;

    @InjectMocks
    private AuthService authService;

    @Test
    void testRegisterUser() {
        when(userService.existsByEmail("non.existing@example.com")).thenReturn(false);
        when(userService.existsByEmail("existing@example.com")).thenReturn(true);

        assertThat(authService.register("username", "non.existing@example.com", "Password1"))
                .isNotNull();
        assertThatThrownBy(() -> authService.register("username", "existing@example.com", "Password1"))
                .isInstanceOf(UserAlreadyExistsException.class);
    }
}

authService contains 2 fields:
@Value("${notecz.auth.jwt.expire}")
    private Long validFor;
    @Value("${notecz.auth.jwt.secret}")
    private String secret;

both of them are set to null for some reason. any idea why? applicaiton test properties indeed contains the 2 pairs
wDeC7aH.png
Was this page helpful?