aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2021-03-24 09:32:12 +0000
committerDominik Stadler <centic@apache.org>2021-03-24 09:32:12 +0000
commit799dfc40f4b9acf94d2825e6ea3a9ff27680bb05 (patch)
tree4e1accc460bde3cd16a6bf451ffbc0040be21690 /src
parente8895c56b14b8a7f6c6006a92afd138aa2f44860 (diff)
downloadpoi-799dfc40f4b9acf94d2825e6ea3a9ff27680bb05.tar.gz
poi-799dfc40f4b9acf94d2825e6ea3a9ff27680bb05.zip
Don't use a hardcoded temporary file (and also not a hardcoded /tmp directory)
This could cause issues in CI or when multiple different users run tests of POI on one machine! git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1887998 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java
index 66196d375b..45ff5d7747 100644
--- a/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java
+++ b/src/ooxml/testcases/org/apache/poi/xddf/usermodel/chart/TestXDDFChart.java
@@ -20,16 +20,19 @@ package org.apache.poi.xddf.usermodel.chart;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.poi.ooxml.POIXMLFactory;
import org.apache.poi.ooxml.POIXMLRelation;
import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.util.TempFile;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
+import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -83,14 +86,19 @@ class TestXDDFChart {
chart.plot(data);
- try (OutputStream out = new FileOutputStream("/tmp/chart20201220.xlsx")) {
- wb.write(out);
+ File file = TempFile.createTempFile("chart20201220", ".xlsx");
+ try {
+ try (OutputStream out = new FileOutputStream(file)) {
+ wb.write(out);
+ }
+ } finally {
+ assertTrue(!file.exists() || file.delete());
}
}
}
private XDDFChart newXDDFChart() {
- XDDFChart xddfChart = new XDDFChart() {
+ return new XDDFChart() {
@Override
protected POIXMLRelation getChartRelation() {
return null;
@@ -106,6 +114,5 @@ class TestXDDFChart {
return null;
}
};
- return xddfChart;
}
}