lundi 9 août 2021

ReflectionTestUtils.setField - TypeMismatchException

I am trying to test a Spring service method, setting a private variable annotated with @Value via 'ReflectionTestUtils.setField' method.

Code: @Value("${temp-files-delete-time}") private int deleteTime;

Test: ReflectionTestUtils.setField(someService, "deleteTime", 1);

When it try to run it I get: java.lang.IllegalStateException: Failed to load ApplicationContext

org.springframework.beans.**TypeMismatchException**: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "${temp-files-delete-time}".

The variable I am trying to set is an int as well as the value I am using in the reflection method. Am I missing something ?





Aucun commentaire:

Enregistrer un commentaire