I am trying to write unit test for the next method in my controller.
@Autowired
private ApplicationContext context;
private String getProperty() {
try {
Properties props = context.getBean("myProperties", Properties.class);
String val = props.getProperty("myProperty");
......
Bean is declared like this in my context application:
<util:properties id="myProperties" scope="prototype" location="file:${catalina.base}/webapps/myProperties.properties"/>
How can I mock this so that I can test different values โโof the variable val?
I was thinking of creating a test properties file and taunting this:
context = Mockito.mock(ApplicationContext.class);
Mocikto.when(context.getBean("myProperties", Properties.class)).thenReturn(some test file)
but then I would have to declare the test file as a Bean somewhere.
I was wondering if there is an easier way to do this?
thank
source
share