// verify that offsets and limits are ignored during export
Field field1 = when(mock(Field.class).getName()).thenReturn("col1").getMock();
Field field2 = when(mock(Field.class).getName()).thenReturn("col2").getMock();
Field field3 = when(mock(Field.class).getName()).thenReturn("col3").getMock();
when(tableModel.getColumns()).thenReturn(Arrays.asList(field1, field2, field3));
WritableTuple row1 = new KeyValueTuple();
row1.set("col1", "val1.1");
row1.set("col2", "val1.2");
row1.set("col3", "val1.3");
WritableTuple row2 = new KeyValueTuple();
row2.set("col1", "val2.1");
row2.set("col2", "val2.2");
row2.set("col3", "val2.3");
when(tableModel.iterator()).thenReturn(Arrays.<Tuple> asList(row1, row2).iterator());
ExcelExporter excelExporter = new ExcelExporter(tableModel);
File xlsFile = File.createTempFile("table", ".xls");
try
{
excelExporter.export(new FileOutputStream(xlsFile));
// check output
ExcelReader excelReader = new ExcelReader(xlsFile);
ExcelSheetReader sheetReader = excelReader.getSheet("Sheet1");
try
{
Iterator<Tuple> it = sheetReader.iterator();
assertTrue(it.hasNext());
Tuple tuple1 = it.next();
assertEquals(tuple1.getString("col1"), row1.getString("col1"));
assertEquals(tuple1.getString("col2"), row1.getString("col2"));
assertEquals(tuple1.getString("col3"), row1.getString("col3"));
assertTrue(it.hasNext());
Tuple tuple2 = it.next();
assertEquals(tuple2.getString("col1"), row2.getString("col1"));
assertEquals(tuple2.getString("col2"), row2.getString("col2"));
assertEquals(tuple2.getString("col3"), row2.getString("col3"));
assertFalse(it.hasNext());
}
finally
{
IOUtils.closeQuietly(sheetReader);