diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java index ec6ab23745..0ea3f55811 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java @@ -528,4 +528,50 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { } System.out.println("Done"); } + + public void testBug47090a() { + Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx"); + assertSheetOrder(workbook, "Sheet1", "Sheet2"); + workbook.removeSheetAt(0); + assertSheetOrder(workbook, "Sheet2"); + workbook.createSheet(); + assertSheetOrder(workbook, "Sheet2", "Sheet1"); + Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook); + assertSheetOrder(read, "Sheet2", "Sheet1"); + } + + public void testBug47090b() { + Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx"); + assertSheetOrder(workbook, "Sheet1", "Sheet2"); + workbook.removeSheetAt(1); + assertSheetOrder(workbook, "Sheet1"); + workbook.createSheet(); + assertSheetOrder(workbook, "Sheet1", "Sheet0"); // Sheet0 because it uses "Sheet" + sheets.size() as starting point! + Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook); + assertSheetOrder(read, "Sheet1", "Sheet0"); + } + + public void testBug47090c() { + Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx"); + assertSheetOrder(workbook, "Sheet1", "Sheet2"); + workbook.removeSheetAt(0); + assertSheetOrder(workbook, "Sheet2"); + workbook.cloneSheet(0); + assertSheetOrder(workbook, "Sheet2", "Sheet2 (2)"); + Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook); + assertSheetOrder(read, "Sheet2", "Sheet2 (2)"); + } + + public void testBug47090d() { + Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("47090.xlsx"); + assertSheetOrder(workbook, "Sheet1", "Sheet2"); + workbook.createSheet(); + assertSheetOrder(workbook, "Sheet1", "Sheet2", "Sheet0"); + workbook.removeSheetAt(0); + assertSheetOrder(workbook, "Sheet2", "Sheet0"); + workbook.createSheet(); + assertSheetOrder(workbook, "Sheet2", "Sheet0", "Sheet1"); + Workbook read = XSSFTestDataSamples.writeOutAndReadBack(workbook); + assertSheetOrder(read, "Sheet2", "Sheet0", "Sheet1"); + } } diff --git a/test-data/spreadsheet/47090.xlsx b/test-data/spreadsheet/47090.xlsx new file mode 100644 index 0000000000..c52ed666ab Binary files /dev/null and b/test-data/spreadsheet/47090.xlsx differ