Thank you. I made the following changes:-
test-beans.xml
...
<bean id="a"
class="com.example.A" init-method="init">
<property name="file" value="sample.properties"/>
</bean>
<bean id="cm"
class="com.example.CommonMethods">
<property name="a" ref="a"/>
</bean>
....
CommonMethods.java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/test-beans.xml")
public class CommonMethods {
@Autowired
private A a;
public A geta() {
return(a);
}
public void seta(A a) {
this.a=a;
}
public String getFileName() {
if(a==null)
System.out.println("a is null");
else
System.out.println("a is null");
String s=a.getFile().getName();
return(s);
}
@Test // JUnit test case
public void testmethod() {
getFileName();
}
}
test.java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "/test-beans.xml")
public class test {
CommonMethods cm;
@Test
public void testSomething() {
cm.getFileName();
}
Still getting the same issue. Help me!! What am I doing wrong?