rahul saxenau wrote:Can anybody please write the JUnit test case for the above method.
We will help you, but not write it for you. CodeRanch is NotACodeMill.
The first thing to decide is whether this is a unit test or an integration test. In a unit test, you use a mock framework like jMock or Mockito. That lets you return anything you want from clientDataService.findAllClients();. Which simplifies testing. In an integration test, you actually have the code call the data service.
Regardless, your first steps will be the same. In programming, it is helpful to start small. Can you:
1) Write a JUnit test with one @Test method that has an empty body?
2) Write a @Before method that constructs an instance of your class and stores it in an instance variable?
3) Have your JUnit test call clientDataService.findAllClients method and store the results in a variable called actual (the test may fail, but that is ok for now)?
4) Have your JUnit test mock out clientDataService?
5) Have your JUnit test assert the size of actual?
6) Have your JUnit test assert the values in actual?
Once you can do this, you can proceed to other tests.
Give it a try and post what you are up to when you get stuck. And welcome to CodeRanch!