poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1768590 - in /poi/trunk/src/testcases/org/apache/poi: hssf/usermodel/TestHSSFConditionalFormatting.java ss/usermodel/BaseTestConditionalFormatting.java
Date Mon, 07 Nov 2016 21:32:18 GMT
Author: centic
Date: Mon Nov  7 21:32:18 2016
New Revision: 1768590

URL: http://svn.apache.org/viewvc?rev=1768590&view=rev
Log:
Pull up one more test into BaseTestConditionalFormatting

Modified:
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java?rev=1768590&r1=1768589&r2=1768590&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
Mon Nov  7 21:32:18 2016
@@ -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 TestHSSFConditionalFo
         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());
-    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java?rev=1768590&r1=1768589&r2=1768590&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
Mon Nov  7 21:32:18 2016
@@ -409,7 +409,7 @@ public abstract class BaseTestConditiona
             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 BaseTestConditiona
     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 BaseTestConditiona
         
         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 BaseTestConditiona
         
         
         // 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 BaseTestConditiona
         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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message