Reputation:
I am trying to read in a .xls file in an effort to interrogate its contents. I keep getting an AssertionError. Also I want to delete this file from the directory after the test.
@Test public void testSpreadsheetCont() throws Exception {
FileInputStream fileInputStream = new FileInputStream("C:/var/fedex/pricingbackfillmonitor/data/Backfill Message Monitor.xls");
HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
HSSFSheet worksheet = workbook.getSheetAt(0);
HSSFRow row1 = worksheet.getRow(2);
HSSFCell cell1 = row1.getCell(1);
boolean success = false;
if (cell1.getStringCellValue() == "L")
{
success = true;
}else{
success = false;
}
Assert.assertTrue(success);
}
Upvotes: 0
Views: 159
Reputation: 2937
When testing Strings for equality, use the equals() method. So, change
if (cell1.getStringCellValue() == "L")
to
if ("L".equals(cell1.getStringCellValue()))
Upvotes: 1