]> source.dussan.org Git - poi.git/commitdiff
[github-176] Remove limit on number of rules in XSSFSheetConditionalFormatting.
authorPJ Fanning <fanningpj@apache.org>
Wed, 29 Apr 2020 21:18:18 +0000 (21:18 +0000)
committerPJ Fanning <fanningpj@apache.org>
Wed, 29 Apr 2020 21:18:18 +0000 (21:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1877177 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java

index f6e2a48876519aef17190c59e4d9cf2a13c87f4c..04f922713ef9139998c7c4a080b766d8a82c9c8b 100644 (file)
@@ -42,10 +42,12 @@ import org.junit.Test;
 public abstract class BaseTestConditionalFormatting {
     private final ITestDataProvider _testDataProvider;
 
-    protected BaseTestConditionalFormatting(ITestDataProvider testDataProvider){
+    protected BaseTestConditionalFormatting(ITestDataProvider testDataProvider) {
         _testDataProvider = testDataProvider;
     }
 
+    protected boolean applyLimitOf3 = true;
+
     protected abstract void assertColour(String hexExpected, Color actual);
 
     @Test
@@ -97,10 +99,20 @@ public abstract class BaseTestConditionalFormatting {
                 assertTrue(e.getMessage().startsWith("cfRules must not be empty"));
             }
 
-            //this is now allowed
-            sheetCF.addConditionalFormatting(
-                    new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
-                    new ConditionalFormattingRule[]{rule1, rule2, rule3, rule4});
+            if (applyLimitOf3) {
+                try {
+                    sheetCF.addConditionalFormatting(
+                            new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
+                            new ConditionalFormattingRule[]{rule1, rule2, rule3, rule4});
+                    fail("expected exception");
+                } catch (IllegalArgumentException e) {
+                    assertTrue(e.getMessage().startsWith("Number of rules must not exceed 3"));
+                }
+            } else {
+                sheetCF.addConditionalFormatting(
+                        new CellRangeAddress[]{CellRangeAddress.valueOf("A1:A3")},
+                        new ConditionalFormattingRule[]{rule1, rule2, rule3, rule4});
+            }
         }
     }