diff options
author | Dominik Stadler <centic@apache.org> | 2016-11-07 21:32:18 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2016-11-07 21:32:18 +0000 |
commit | f9f7fe97403bdbca14b15d9827272c4b69bd29d0 (patch) | |
tree | 49a10bc66c127e14b615e1b368c7b37903dbde9d | |
parent | 851a171915eb421c65ab30fadf891fb4c693adef (diff) | |
download | poi-f9f7fe97403bdbca14b15d9827272c4b69bd29d0.tar.gz poi-f9f7fe97403bdbca14b15d9827272c4b69bd29d0.zip |
Pull up one more test into BaseTestConditionalFormatting
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1768590 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java | 95 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/ss/usermodel/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 48d07466cb..63ba22c935 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 d5a8124df9..1111960f8c 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; i<sheetCF.getNumConditionalFormattings(); i++) {
- cf = sheetCF.getConditionalFormattingAt(i);
+ ConditionalFormatting cf = sheetCF.getConditionalFormattingAt(i);
if (cf instanceof HSSFConditionalFormatting) {
String str = cf.toString();
if (str.contains("[CF]")) fCF++;
@@ -604,12 +601,12 @@ public abstract class BaseTestConditionalFormatting { // Highlight Positive values - Column C
- cf = sheetCF.getConditionalFormattingAt(0);
+ ConditionalFormatting cf = sheetCF.getConditionalFormattingAt(0);
assertEquals(1, cf.getFormattingRanges().length);
assertEquals("C2:C17", cf.getFormattingRanges()[0].formatAsString());
assertEquals(1, cf.getNumberOfRules());
- cr = cf.getRule(0);
+ ConditionalFormattingRule cr = cf.getRule(0);
assertEquals(ConditionType.CELL_VALUE_IS, cr.getConditionType());
assertEquals(ComparisonOperator.GT, cr.getComparisonOperation());
assertEquals("0", cr.getFormula1());
@@ -1343,4 +1340,97 @@ public abstract class BaseTestConditionalFormatting { ConditionalFormatting readCf = cf.getConditionalFormattingAt(0);
readCf.setFormattingRanges(null);
}
+
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void test52122() throws Exception {
+ Workbook workbook = _testDataProvider.createWorkbook();
+ 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 = _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 |