I have below implementation of classes.. 'EmpAddress' is an interface & 'EmployeeInterfaceFactory' is a class which has static method 'getAddressImpl' that provides EmpAddress Implemented class Object... I have JUnit method as below where I am getting Null Pointer Exception... Need help/suggestion in implementing this JUnit...
***************************************************************************
public class Employee(){
private Address address = new Address();
public String getEmployeeDetails(){
String details = address.getDetails();
return details;
}
}
***************************************************************************
public Address address(){
private EmpAddress empAddress = EmployeeInterfaceFactory.getAddressImpl();
public String getDetails(){
String details = empAddress.getEmpDetails(); // Null pointer exception coming here
return details;
}
}
****************************************************
@RunWith(PowerMockRunner.class)
@PrepareForTest({EmployeeInterfaceFactory.class})
public class EmployeeTest(){
Employee emp;
EmpAddress empAddress;
@Before
public void setUp(){
emp = new Employee();
empAddress = createMock(EmpAddress.class);
mockStatic(EmployeeInterfaceFactory.class);
}
@Test
public void getEmployeeDetailsTest(){
expect(EmployeeInterfaceFactory.getAddressImpl()).andReturn(empAddress);
expect(empAddress.getEmpDetails()).adnReturn("testing data");
String result = emp.getEmployeeDetails();
}
}