I want to set the value 'ignore' to both true and false. Currently already able to set it to true at @Before. But how could I also test by setting it to false. Note that I need this to be a constructor initialization.
Setting the value via ReflectionTestUtils not going to work due to the value being set in constructor. I could call the constructor again and set the value to false but that would involve a lot of setups in this test class with all the relevant mocks and so on which would get messy. Is there a way around this?
I have the following constructor
// many other variables not relevant for this question
private final boolean ignore;
public Client(@Value("${a.error}") boolean ignore) {
// setting many other variables not relevant for this question
this.ignore = ignore;
}
When testing:
@Before
public void setUp() {
client = new Client(true);
//many other setups
}
// tests correctly fine cos I set the ignore to true
@Test
public void testing(){
// someMethod uses the ignore value to do some actions and return true / false
assertTrue(client.someMethod());
}
@Test
public void howToTestIgnoreSetToFalse(){
// ?
}