try to fix tests

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902633 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2022-07-10 13:54:09 +00:00
parent ec3e9218ef
commit e0ca0baebf
3 changed files with 37 additions and 28 deletions

View File

@ -19,20 +19,9 @@ package org.apache.poi.ss.tests.util;
import org.apache.poi.ss.util.BaseTestCellUtil; import org.apache.poi.ss.util.BaseTestCellUtil;
import org.apache.poi.xssf.SXSSFITestDataProvider; import org.apache.poi.xssf.SXSSFITestDataProvider;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.IOException;
class TestSXSSFCellUtil extends BaseTestCellUtil { class TestSXSSFCellUtil extends BaseTestCellUtil {
public TestSXSSFCellUtil() { public TestSXSSFCellUtil() {
super(SXSSFITestDataProvider.instance); super(SXSSFITestDataProvider.instance);
} }
@Override
@Test
@Disabled("need to investigate why the super class version fails for (S)XSSF")
protected void setFillForegroundColorBeforeFillBackgroundColorEnum() throws IOException {
}
} }

View File

@ -19,20 +19,9 @@ package org.apache.poi.ss.tests.util;
import org.apache.poi.ss.util.BaseTestCellUtil; import org.apache.poi.ss.util.BaseTestCellUtil;
import org.apache.poi.xssf.XSSFITestDataProvider; import org.apache.poi.xssf.XSSFITestDataProvider;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.IOException;
class TestXSSFCellUtil extends BaseTestCellUtil { class TestXSSFCellUtil extends BaseTestCellUtil {
public TestXSSFCellUtil() { public TestXSSFCellUtil() {
super(XSSFITestDataProvider.instance); super(XSSFITestDataProvider.instance);
} }
@Override
@Test
@Disabled("need to investigate why the super class version fails for (S)XSSF")
protected void setFillForegroundColorBeforeFillBackgroundColorEnum() throws IOException {
}
} }

View File

@ -401,7 +401,7 @@ public final class CellUtil {
Map<String, Object> wbStyleMap = getFormatProperties(wbStyle); Map<String, Object> wbStyleMap = getFormatProperties(wbStyle);
// the desired style already exists in the workbook. Use the existing style. // the desired style already exists in the workbook. Use the existing style.
if (wbStyleMap.equals(values)) { if (styleMapsMatch(wbStyleMap, values)) {
newStyle = wbStyle; newStyle = wbStyle;
break; break;
} }
@ -416,6 +416,21 @@ public final class CellUtil {
cell.setCellStyle(newStyle); cell.setCellStyle(newStyle);
} }
private static boolean styleMapsMatch(final Map<String, Object> map1, final Map<String, Object> map2) {
final Map<String, Object> map1Copy = new HashMap<>(map1);
final Map<String, Object> map2Copy = new HashMap<>(map2);
final Object backColor1 = map1Copy.remove(FILL_BACKGROUND_COLOR_COLOR);
final Object backColor2 = map2Copy.remove(FILL_BACKGROUND_COLOR_COLOR);
final Object foreColor1 = map1Copy.remove(FILL_FOREGROUND_COLOR_COLOR);
final Object foreColor2 = map2Copy.remove(FILL_FOREGROUND_COLOR_COLOR);
if (map1Copy.equals(map2Copy)) {
final boolean backColorsMatch = backColor1 == null || backColor2 == null || backColor1.equals(backColor2);
final boolean foreColorsMatch = foreColor1 == null || foreColor2 == null || foreColor1.equals(foreColor2);
return backColorsMatch && foreColorsMatch;
}
return false;
}
/** /**
* <p>This method attempts to find an existing CellStyle that matches the {@code cell}'s * <p>This method attempts to find an existing CellStyle that matches the {@code cell}'s
* current style plus a single style property {@code propertyName} with value * current style plus a single style property {@code propertyName} with value
@ -529,11 +544,27 @@ public final class CellUtil {
style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR)); style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
style.setDataFormat(getShort(properties, DATA_FORMAT)); style.setDataFormat(getShort(properties, DATA_FORMAT));
style.setFillPattern(getFillPattern(properties, FILL_PATTERN)); style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR)); Color foregroundFillColor = getColor(properties, FILL_FOREGROUND_COLOR_COLOR);
style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR)); Color backgroundFillColor = getColor(properties, FILL_BACKGROUND_COLOR_COLOR);
style.setFillForegroundColor(getColor(properties, FILL_FOREGROUND_COLOR_COLOR), true); if (foregroundFillColor != null) {
style.setFillBackgroundColor(getColor(properties, FILL_BACKGROUND_COLOR_COLOR), true); try {
style.setFillForegroundColor(foregroundFillColor);
} catch (IllegalArgumentException iae) {
style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
}
} else {
style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
}
if (backgroundFillColor != null) {
try {
style.setFillBackgroundColor(backgroundFillColor);
} catch (IllegalArgumentException iae) {
style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
}
} else {
style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
}
style.setFont(workbook.getFontAt(getInt(properties, FONT))); style.setFont(workbook.getFontAt(getInt(properties, FONT)));
style.setHidden(getBoolean(properties, HIDDEN)); style.setHidden(getBoolean(properties, HIDDEN));