Hi my class looks like this.
public class Class1 { public void method1(Object obj) { // Class 2 makes the restApiCall and result as "SUCCESS" if the HTTP response is 202 Class2 class2 = new Class2(); String result = class2.callRestService(); System.out.println(result); } } public class Class2 { public String callRestService() { String url = fetchUrl(System.getProperty(COnstants.URL); String result = callRestServiceAPi(url); // Calling the RestApimethod. return result; } } I want to write unit test for the class1 and I want to do it by actually not calling RestAPi means I want to mock class2.callRestService() method to return as "success" or "failure". How can it be done.