I have four classes like below:
public class A(){
public void getOne(){
B objB = new B();
String x = objB.getTwo();
}
}
public class B(){
public String getTwo(){
C objC = new C();
return objC.getThree();
}
}
public class C(){
D objD;
public String getThree(){
return objD.getFour();
}
}
public class D(){
public String getFour(){
return "hi";
}
}
In the above code, class C
has objD
which is being injected by Spring. When I try to test the getOne()
method of class A
, I get a null pointer exception because when the method call reaches class C
, it has no objD
instantiated (hence the exception). How can I test such methods where the sub-sub class has a method where that sub-sub class is dependency-injected by Spring?