I am trying to use mockito to mock the return value of method3() in class3 when i run the method try() in class1 from the testclass. I have restriction as to not being able to make any edition to the codes that i have. So, i cannot add in constructors to make the mock as per some solutions that i have seen given on the internet. I am using MockMVC with WebApplicationContextSetup. Please guide me if it is possible to mock the value of method3() only using mockito and if it is not possible what is the other solution that i can use to mock the value?
class1
{
Class2 c2 = new Class2();
public String try()
{
Something temp1 = c2.method1();
}
}
class2
{
Class3 c3 = new Class3();
public String method1()
{
return c3.method3();
}
}
class3
{
//Will like to mock the return value of this method
public String method3()
{
return "asd";
}
}
testclass
{
class1 c1 = new class1();
c1.try();
}
Thanks Alot :D