From 57fa4c18698ddb41a1a72052136ded595e8999bf Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 7 Nov 2016 21:32:18 +0000 Subject: [PATCH] Pull up one more test into BaseTestConditionalFormatting git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1768590 13f79535-47bb-0310-9956-ffa450edef68 --- .../TestHSSFConditionalFormatting.java | 95 ---------------- .../BaseTestConditionalFormatting.java | 104 ++++++++++++++++-- 2 files changed, 97 insertions(+), 102 deletions(-) diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java index 48d07466c..63ba22c93 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java @@ -23,10 +23,8 @@ import static org.junit.Assert.*; import java.io.IOException; import org.apache.poi.hssf.HSSFITestDataProvider; -import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.*; -import org.apache.poi.ss.util.CellRangeAddress; import org.junit.Test; /** @@ -121,97 +119,4 @@ public final class TestHSSFConditionalFormatting extends BaseTestConditionalForm assertNotNull(wbBack); wbBack.close(); } - - - @SuppressWarnings("deprecation") - @Test - public void test52122() throws Exception { - Workbook workbook = new HSSFWorkbook(); - Sheet sheet = workbook.createSheet("Conditional Formatting Test"); - sheet.setColumnWidth(0, 256 * 10); - sheet.setColumnWidth(1, 256 * 10); - sheet.setColumnWidth(2, 256 * 10); - - // Create some content. - // row 0 - Row row = sheet.createRow(0); - - Cell cell0 = row.createCell(0); - cell0.setCellType(CellType.NUMERIC); - cell0.setCellValue(100); - - Cell cell1 = row.createCell(1); - cell1.setCellType(CellType.NUMERIC); - cell1.setCellValue(120); - - Cell cell2 = row.createCell(2); - cell2.setCellType(CellType.NUMERIC); - cell2.setCellValue(130); - - // row 1 - row = sheet.createRow(1); - - cell0 = row.createCell(0); - cell0.setCellType(CellType.NUMERIC); - cell0.setCellValue(200); - - cell1 = row.createCell(1); - cell1.setCellType(CellType.NUMERIC); - cell1.setCellValue(220); - - cell2 = row.createCell(2); - cell2.setCellType(CellType.NUMERIC); - cell2.setCellValue(230); - - // row 2 - row = sheet.createRow(2); - - cell0 = row.createCell(0); - cell0.setCellType(CellType.NUMERIC); - cell0.setCellValue(300); - - cell1 = row.createCell(1); - cell1.setCellType(CellType.NUMERIC); - cell1.setCellValue(320); - - cell2 = row.createCell(2); - cell2.setCellType(CellType.NUMERIC); - cell2.setCellValue(330); - - // Create conditional formatting, CELL1 should be yellow if CELL0 is not blank. - SheetConditionalFormatting formatting = sheet.getSheetConditionalFormatting(); - - ConditionalFormattingRule rule = formatting.createConditionalFormattingRule("$A$1>75"); - - PatternFormatting pattern = rule.createPatternFormatting(); - pattern.setFillBackgroundColor(IndexedColors.BLUE.index); - pattern.setFillPattern(PatternFormatting.SOLID_FOREGROUND); - - CellRangeAddress[] range = {CellRangeAddress.valueOf("B2:C2")}; - CellRangeAddress[] range2 = {CellRangeAddress.valueOf("B1:C1")}; - - formatting.addConditionalFormatting(range, rule); - formatting.addConditionalFormatting(range2, rule); - - // Write file. - /*FileOutputStream fos = new FileOutputStream("c:\\temp\\52122_conditional-sheet.xls"); - try { - workbook.write(fos); - } finally { - fos.close(); - }*/ - - Workbook wbBack = HSSFTestDataSamples.writeOutAndReadBack((HSSFWorkbook)workbook); - Sheet sheetBack = wbBack.getSheetAt(0); - final SheetConditionalFormatting sheetConditionalFormattingBack = sheetBack.getSheetConditionalFormatting(); - assertNotNull(sheetConditionalFormattingBack); - final ConditionalFormatting formattingBack = sheetConditionalFormattingBack.getConditionalFormattingAt(0); - assertNotNull(formattingBack); - final ConditionalFormattingRule ruleBack = formattingBack.getRule(0); - assertNotNull(ruleBack); - final PatternFormatting patternFormattingBack1 = ruleBack.getPatternFormatting(); - assertNotNull(patternFormattingBack1); - assertEquals(IndexedColors.BLUE.index, patternFormattingBack1.getFillBackgroundColor()); - assertEquals(PatternFormatting.SOLID_FOREGROUND, patternFormattingBack1.getFillPattern()); - } } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java index d5a8124df..1111960f8 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java @@ -409,7 +409,7 @@ public abstract class BaseTestConditionalFormatting { assertEquals(2, wb.getNumberOfSheets()); } catch (RuntimeException e) { if (e.getMessage().indexOf("needs to define a clone method") > 0) { - fail("Indentified bug 45682"); + fail("Identified bug 45682"); } throw e; } finally { @@ -561,10 +561,7 @@ public abstract class BaseTestConditionalFormatting { public void testReadOffice2007(String filename) throws IOException { Workbook wb = _testDataProvider.openSampleWorkbook(filename); Sheet s = wb.getSheet("CF"); - ConditionalFormatting cf = null; - ConditionalFormattingRule cr = null; - // Sanity check data assertEquals("Values", s.getRow(0).getCell(0).toString()); assertEquals("10.0", s.getRow(2).getCell(0).toString()); @@ -578,7 +575,7 @@ public abstract class BaseTestConditionalFormatting { int fCF = 0, fCF12 = 0, fCFEX = 0; for (int i=0; i75"); + + PatternFormatting pattern = rule.createPatternFormatting(); + pattern.setFillBackgroundColor(IndexedColors.BLUE.index); + pattern.setFillPattern(PatternFormatting.SOLID_FOREGROUND); + + CellRangeAddress[] range = {CellRangeAddress.valueOf("B2:C2")}; + CellRangeAddress[] range2 = {CellRangeAddress.valueOf("B1:C1")}; + + formatting.addConditionalFormatting(range, rule); + formatting.addConditionalFormatting(range2, rule); + + // Write file. + /*FileOutputStream fos = new FileOutputStream("c:\\temp\\52122_conditional-sheet.xls"); + try { + workbook.write(fos); + } finally { + fos.close(); + }*/ + + Workbook wbBack = _testDataProvider.writeOutAndReadBack(workbook); + Sheet sheetBack = wbBack.getSheetAt(0); + final SheetConditionalFormatting sheetConditionalFormattingBack = sheetBack.getSheetConditionalFormatting(); + assertNotNull(sheetConditionalFormattingBack); + final ConditionalFormatting formattingBack = sheetConditionalFormattingBack.getConditionalFormattingAt(0); + assertNotNull(formattingBack); + final ConditionalFormattingRule ruleBack = formattingBack.getRule(0); + assertNotNull(ruleBack); + final PatternFormatting patternFormattingBack1 = ruleBack.getPatternFormatting(); + assertNotNull(patternFormattingBack1); + assertEquals(IndexedColors.BLUE.index, patternFormattingBack1.getFillBackgroundColor()); + assertEquals(PatternFormatting.SOLID_FOREGROUND, patternFormattingBack1.getFillPattern()); + } } \ No newline at end of file