Hi,
I am working on a java web application using Spring MVC framework. The application is running fine. I am writing some JUnit test cases for some of the pojo classes inside the webapp. I created a separate source folder 'test' which is in parallel to the src folder. I am writing a simple test case that gets a list of locations from the database using the DAO object. The problem is when i run the Testcase, it fails with a Null Pointer exception. And after some debugging i found that it does not even enter the method inside the DAO class. Any pointers as to where i could go wrong?
public class TestLocationService {
LocationService locationService = new LocationService();
@Resource(name="locationDAO")
private ILocationDAO locationDAO;
// Test to get Locations
@Test
public void testGetLocations() {
List<Location> list = locationDAO.getList();
Assert.assertNotNull(list);
}
}
public class TestRunner {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(TestLocationService.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
}
public class LocationService
{
...
public List<LocationForm> getLocation()
{
List<Location> locations=locationDAO.getList();
List<LocationForm> list = new ArrayList<LocationForm>();
for(Location location:locations)
{
LocationForm locationForm = new LocationForm();
locationForm.setLocID(location.getLocID());
locationForm.setLocName(location.getLocName());
locationForm.setCoords(location.getCoords());
list.add(locationForm);
}
return list;
}
...
}
Any suggestions would be of great help.
Thanks,
YogeshP