I have a class with a field entered from a property with @Value
:
public class MyClass {
@Value(${property.key})
private String filePath;
...
My integration tests should change filePath
to point to several different files.
I tried using reflection to set it before calling the method:
public class MyClassIT {
@Autowired MyClass myClass;
@Test
public void testMyClassWithTestFile1 {
ReflectionTestUtils.setField(myClass, "filePath", "/tests/testfile1.csv");
myClass.invokeMethod1();
...
But when the first method is called, the injection @Value
starts and changes the value from the just set. Can anyone suggest how to solve this or an alternative approach?
Note: I need Spring to manage the class (so other dependencies are introduced), and other tests are needed for the same class using different test files.