**I am doing comparision between the two list that is between the csv and db data but I am returning void so my assert is not working.What should be the change that assert will work. I have tried by putting the return below match found and changing the return type to boolean but it does not work.
public static boolean compareTwoLists(List<Map<String, String>> csvData, List<Map<String, String>> sqlData) {
// Comparator on basis of product Code
Comparator<Map<String, String>> comp = (o1, o2) -> {
return o1.get("productcode").compareTo(o2.get("productcode"));
};
System.out.println("Test");
Collections.sort(csvData, comp);
Collections.sort(sqlData, comp);
System.out.println("testdef");
for (Map<String, String> i : sqlData) {
if (csvData.contains(i)) {
System.out.println("Match Found " + i);
return true;
}else{
System.out.println(" No Match Found ");
}
}
return false;
}
public static List<Map<String, String>> convertToMapFromCsv(String filePath)
throws FileNotFoundException, IOException {
BufferedReader in = new BufferedReader(new FileReader(filePath));
List<Map<String, String>> namefreq = in.lines().skip(1).map(line -> line.split(COMMA)) // splitting csv
.map(line -> {
Map<String, String> map = new HashMap<>();
map.put("productcode", line[0]);
map.put("store", line[1]);
map.put("itemavailabilityscore", line[2]);
map.put("salesunitscore", line[3]);
map.put("totalscore", line[4]);
map.put("pdp_views", line[5]);
return map;
}).collect(Collectors.toList());
System.out.println("testabc");
return namefreq;
}
}
**//junit assertion**
In this new generic is of type List<Map<String,String>> newGeneric which return the db data.FileComparatorUtility is class and the method compareTwoLists is declared above
assertFalse(!FileComparatorUtility.compareTwoLists(csvData,newGeneric));
Its not working when I put the following assertion as a junit what should I change in the code that when I do assertion in junit such that when there is match between csv and db data then it return true else it returns false