]> source.dussan.org Git - poi.git/commitdiff
[bug-66123] support gte attribute in XSSFConditionalFormattingThreshold
authorPJ Fanning <fanningpj@apache.org>
Wed, 15 Jun 2022 16:01:37 +0000 (16:01 +0000)
committerPJ Fanning <fanningpj@apache.org>
Wed, 15 Jun 2022 16:01:37 +0000 (16:01 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1901945 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormattingThreshold.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFConditionalFormatting.java
poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java

index b155a796540888f4ecba1c1253d58acbb94f52c8..4f8021b9734f401cc31b79b53d7771b47f2c5c1c 100644 (file)
@@ -72,6 +72,7 @@ public class XSSFConditionalFormattingThreshold implements org.apache.poi.ss.use
             return null;
         }
     }
+
     @Override
     public void setValue(Double value) {
         if (value == null) {
@@ -80,4 +81,20 @@ public class XSSFConditionalFormattingThreshold implements org.apache.poi.ss.use
             cfvo.setVal(value.toString());
         }
     }
+
+    /**
+     * @return true if 'gte' attribute is set to true (defaults to true)
+     * @since POI 5.2.3
+     */
+    public boolean isGte() {
+        return cfvo.getGte();
+    }
+
+    /**
+     * @param gte set 'gte' attribute (defaults to true)
+     * @since POI 5.2.3
+     */
+    public void setGte(boolean gte) {
+        cfvo.setGte(gte);
+    }
 }
index 50d11b8c5ca03c1135782aebc98d442df4a4f6cb..da4d9b9102b700b1fbb1a8bb431e3150c3027e5e 100644 (file)
 package org.apache.poi.xssf.usermodel;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.IOException;
 
@@ -27,6 +30,7 @@ import org.apache.poi.ss.usermodel.BaseTestConditionalFormatting;
 import org.apache.poi.ss.usermodel.Color;
 import org.apache.poi.ss.usermodel.ConditionalFormatting;
 import org.apache.poi.ss.usermodel.ConditionalFormattingRule;
+import org.apache.poi.ss.usermodel.ConditionalFormattingThreshold;
 import org.apache.poi.ss.usermodel.ExtendedColor;
 import org.apache.poi.ss.usermodel.FontFormatting;
 import org.apache.poi.ss.usermodel.PatternFormatting;
@@ -143,4 +147,18 @@ class TestXSSFConditionalFormatting extends BaseTestConditionalFormatting {
     protected boolean applyLimitOf3() {
         return false;
     }
+
+    @Override
+    protected void checkThreshold(ConditionalFormattingThreshold threshold) {
+        assertNull(threshold.getValue());
+        assertNull(threshold.getFormula());
+        assertTrue(threshold instanceof XSSFConditionalFormattingThreshold,
+                "threshold is a XSSFConditionalFormattingThreshold?");
+        XSSFConditionalFormattingThreshold xssfThreshold = (XSSFConditionalFormattingThreshold)threshold;
+        assertTrue(xssfThreshold.isGte(), "gte defaults to true?");
+        xssfThreshold.setGte(false);
+        assertFalse(xssfThreshold.isGte(), "gte changed to false?");
+        xssfThreshold.setGte(true);
+        assertTrue(xssfThreshold.isGte(), "gte changed to true?");
+    }
 }
index e58138c663350442f8f765334b439fda0dfc2e0d..49f944635b82183d0365a6283fd69796b4f82190 100644 (file)
@@ -550,8 +550,7 @@ public abstract class BaseTestConditionalFormatting {
                     if (str.contains("[CFEX]")) fCFEX++;
                 } else {
                     ConditionType type = cf.getRule(cf.getNumberOfRules() - 1).getConditionType();
-                    if (type == ConditionType.CELL_VALUE_IS ||
-                            type == ConditionType.FORMULA) {
+                    if (type == ConditionType.CELL_VALUE_IS || type == ConditionType.FORMULA) {
                         fCF++;
                     } else {
                         // TODO Properly detect Ext ones from the xml
@@ -772,15 +771,17 @@ public abstract class BaseTestConditionalFormatting {
 
         assertColor(color, databar.getColor());
 
-        ConditionalFormattingThreshold th;
-        th = databar.getMinThreshold();
-        assertEquals(RangeType.MIN, th.getRangeType());
-        assertNull(th.getValue());
-        assertNull(th.getFormula());
-        th = databar.getMaxThreshold();
-        assertEquals(RangeType.MAX, th.getRangeType());
-        assertNull(th.getValue());
-        assertNull(th.getFormula());
+        ConditionalFormattingThreshold th1 = databar.getMinThreshold();
+        assertEquals(RangeType.MIN, th1.getRangeType());
+        checkThreshold(th1);
+        ConditionalFormattingThreshold th2 = databar.getMaxThreshold();
+        assertEquals(RangeType.MAX, th2.getRangeType());
+        checkThreshold(th2);
+    }
+
+    protected void checkThreshold(ConditionalFormattingThreshold threshold) {
+        assertNull(threshold.getValue());
+        assertNull(threshold.getFormula());
     }
 
     private void assertIconSetPercentages(ConditionalFormatting cf, IconSet iconset, Double...vals) {