Author: fanningpj Date: Mon Sep 5 14:38:55 2022 New Revision: 1903883 URL: http://svn.apache.org/viewvc?rev=1903883&view=rev Log: extend tests
Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/util/TestXSSFCellUtil.java Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/util/TestXSSFCellUtil.java URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/util/TestXSSFCellUtil.java?rev=1903883&r1=1903882&r2=1903883&view=diff ============================================================================== --- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/util/TestXSSFCellUtil.java (original) +++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/ss/tests/util/TestXSSFCellUtil.java Mon Sep 5 14:38:55 2022 @@ -123,4 +123,86 @@ class TestXSSFCellUtil extends BaseTestC assertEquals(FillPatternType.NO_FILL, cell.getCellStyle().getFillPattern()); } } + + @Test + public void testBug66052WithWorkaround() throws IOException, DecoderException { + + try (Workbook workbook = new XSSFWorkbook()) { + + final Sheet sheet = workbook.createSheet("Sheet"); + final Row row = sheet.createRow(0); + final Cell cell = row.createCell(0); + final XSSFColor color = new XSSFColor(Hex.decodeHex("FFAAAA")); + + assertNull(cell.getCellStyle().getFillForegroundColorColor()); + assertNull(cell.getCellStyle().getFillBackgroundColorColor()); + + { + Map<String, Object> properties = new LinkedHashMap<>(); + + properties.put(CellUtil.FILL_FOREGROUND_COLOR_COLOR, color); + properties.put(CellUtil.FILL_BACKGROUND_COLOR_COLOR, null); // WORKAROUND + properties.put(CellUtil.FILL_PATTERN, FillPatternType.SOLID_FOREGROUND); + + CellUtil.setCellStyleProperties(cell, properties); + } + + assertNotNull(cell.getCellStyle().getFillForegroundColorColor()); + assertNull(cell.getCellStyle().getFillBackgroundColorColor()); + + { + Map<String, Object> properties = new LinkedHashMap<>(); + + properties.put(CellUtil.FILL_FOREGROUND_COLOR_COLOR, null); + properties.put(CellUtil.FILL_BACKGROUND_COLOR_COLOR, null); // WORKAROUND + properties.put(CellUtil.FILL_PATTERN, FillPatternType.NO_FILL); + + CellUtil.setCellStyleProperties(cell, properties); + } + + assertNull(cell.getCellStyle().getFillForegroundColorColor()); + assertNull(cell.getCellStyle().getFillBackgroundColorColor()); + } + } + + @Test + public void testBug66052WithoutWorkaround() throws IOException, DecoderException { + + try (Workbook workbook = new XSSFWorkbook()) { + + final Sheet sheet = workbook.createSheet("Sheet"); + final Row row = sheet.createRow(0); + final Cell cell = row.createCell(0); + final XSSFColor color = new XSSFColor(Hex.decodeHex("FFAAAA")); + + assertNull(cell.getCellStyle().getFillForegroundColorColor()); + assertNull(cell.getCellStyle().getFillBackgroundColorColor()); + + { + Map<String, Object> properties = new LinkedHashMap<>(); + + properties.put(CellUtil.FILL_FOREGROUND_COLOR_COLOR, color); + properties.put(CellUtil.FILL_PATTERN, FillPatternType.SOLID_FOREGROUND); + + CellUtil.setCellStyleProperties(cell, properties); + } + + assertEquals(color, cell.getCellStyle().getFillForegroundColorColor()); + assertEquals(IndexedColors.AUTOMATIC.getIndex(), + ((XSSFColor) cell.getCellStyle().getFillBackgroundColorColor()).getIndex()); + + { + Map<String, Object> properties = new LinkedHashMap<>(); + + properties.put(CellUtil.FILL_FOREGROUND_COLOR_COLOR, null); + properties.put(CellUtil.FILL_PATTERN, FillPatternType.NO_FILL); + + CellUtil.setCellStyleProperties(cell, properties); + } + + assertNull(cell.getCellStyle().getFillForegroundColorColor()); + assertEquals(IndexedColors.AUTOMATIC.getIndex(), + ((XSSFColor) cell.getCellStyle().getFillBackgroundColorColor()).getIndex()); + } + } } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org