@pralay the problem seems to come from the logic where you iterate the datasets. It assumes that they will always have data which is not always true. That is why you get a NoSuchElementException on trying to call iterator.next() when iterator.hasNext would have returned false.
You can confirm it by replacing that section of code with:
Iterator<Entry<String, DataSet>> iterator = results.getDataSets().entrySet().iterator();
while (iterator.hasNext()) {
dataSet = iterator.next().getValue();
if (dataSet.iterator().hasNext()) {
dsr = dataSet.iterator().next();
dsrlist = new ArrayList( dsr.getColumnValues().values() );
break;
}
}
Thanks @dkayiwa for looking into it and giving the solution.
Yes, This will solve the testing issue partially but refines the API. I will have to check the method when there are Datasets and when there are no Datasets.
The above mentioned solution answers to the later part. How can I test the method when there is a dataset , i.e. What should be get done to those Datasets?
@pralay i do not know how the business logic of that method is supposed to be. I was simply saying that iterator.next() will throw an exception if iterator.hasNext returns false.
If that method expects a dataset and it does not exist, then you should get out of it by throwing an exception. Then your unit test can test the behavior of having to throw an exception when an expected dataset does not exist.