i Have a class "ComparisonService" with the following fn-
public HashMap <String, Map<String, Object>> fetchTableData(DataSource dataSource, List<Object> tableInfo){
table.setTableInfo(tableInfo);
HashMap<String, Map<String, Object>> records = table.fetchData(dataSource);
System.out.println(records.size());
return records;
}
Here table is an Object of other class Table
I am writing a spock test for this Method-
class ComparisonSpec extends spock.lang.Specification{
Table table=Mock()
def DataSource dataSource
def List<Object> tableInfo=[1]
def setup()
{
//def DataSource dataSource
}
def "first function"()
{
given:
def ComparisonService comparison= new ComparisonService()
when:
comparison.fetchTableData(dataSource,tableInfo)
then:
1*table.setTableInfo(_ as String)>>true
1*table.fetchData(_ as DataSource)
}
When I run it I get
null pointer Exception at comparison.fetchTableData(dataSource,tableInfo).
why is that so.