I am trying to write a unit test for the following method in my controller.
@Autowired
private ApplicationContext context;
private String getProperty() {
try {
Properties props = context.getBean("myProperties", Properties.class);
String val = props.getProperty("myProperty");
......
The Bean is declared like this in my applicationContext:
<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 val variable?
I thought about creating a test properties file and mocking it like 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 was an easier way to do this?
Thanks