If you just want to set the private
field, Spring (not Sprint) provides support for that in the spring-test
module. See the setField()
variants in ReflectionTestUtils.
Regards,
Sam
Pregunta
Given the following class:
public class ClassToBeTest{
${property.utility}
private String property;
private Utility utility;
public ClassToBeTested(Utility utility){
this.utility = utility;
}
public void doSomething(){
utility.doSomething(property);
}
}
We want to Mock Utility (we are using Mockito for instance) and verify that utility.doSomething is called passing the property parameter.
We don't really care about the config value (we have other tests for that). But we don't want to open the class with a method like (or passing the property by constructor).
public void setPropertyForTest(String property){
this.property = property;
}
Is there other ways to check that this private property (with no value) is passed to Utility?
Thanks a lot.
Solución
If you just want to set the private
field, Spring (not Sprint) provides support for that in the spring-test
module. See the setField()
variants in ReflectionTestUtils.
Regards,
Sam