I have a Spring Boot application in which a specific bean (MyClass) gets a @Value annotated property whose value is defined in application.properties file:
@Component
public class MyClass {
private String type;
public MyClass(@Value("${type}") String type) {
this.type=type;
}
public String doSomething () {...}
}
application.properties file includes the following: type=typeA
The testing is done using Cucumber, and I would like to test the behavior of the method MyClass.doSomthing when the value of type is not typeA but typeB ,
so I thought about doing the following:
The scenario in the *.feature file will start like this:
Scenario: Validating doSomething when type is B
Given The value of type is typeB
Then Validate doSomething
in the *StepDef file - the implementation of the Given step should somehow change the value of type to typeB, so that the flow of MyClass.doSomthing will process typeB:
@Given("The value of type is typeB")
public void changeTypeToB() {
...
}
My question is: How do I set the value of type to typeB (in the method changeTypeToB) considering the fact the during the test the Spring profile is the default one, hence the initial value of type is typeA ?
Thanks!
Dino