Skip to content

Commit e0fca8b

Browse files
committed
FOP-3277: improve test based on Simon's feedback
1 parent 1acd5d5 commit e0fca8b

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

fop-core/src/test/java/org/apache/fop/svg/BasicPDFTranscoderTestCase.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,12 @@
2020
package org.apache.fop.svg;
2121

2222
import java.io.ByteArrayInputStream;
23-
import java.io.File;
24-
import java.io.FileOutputStream;
23+
import java.io.ByteArrayOutputStream;
2524
import java.io.IOException;
26-
import java.io.OutputStream;
2725
import java.util.HashMap;
2826
import java.util.Map;
2927

30-
import org.junit.Rule;
3128
import org.junit.Test;
32-
import org.junit.rules.TemporaryFolder;
3329
import static org.junit.Assert.assertEquals;
3430

3531
import org.apache.pdfbox.Loader;
@@ -52,9 +48,6 @@
5248
*/
5349
public class BasicPDFTranscoderTestCase extends AbstractBasicTranscoderTest {
5450

55-
@Rule
56-
public TemporaryFolder tempFolder = new TemporaryFolder();
57-
5851
@Override
5952
protected Transcoder createTranscoder() {
6053
return new PDFTranscoder();
@@ -101,8 +94,7 @@ public void testFontSubstitution() throws ConfigurationException, IOException, T
10194
+ "</svg>";
10295
TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(svgFragment.getBytes()));
10396

104-
File outputFile = tempFolder.newFile("output.pdf");
105-
OutputStream os = new FileOutputStream(outputFile);
97+
ByteArrayOutputStream os = new ByteArrayOutputStream();
10698
TranscoderOutput output = new TranscoderOutput(os);
10799

108100
try {
@@ -111,20 +103,14 @@ public void testFontSubstitution() throws ConfigurationException, IOException, T
111103
os.close();
112104
}
113105

114-
PDDocument pdfDocument = null;
115-
try {
116-
pdfDocument = Loader.loadPDF(outputFile);
106+
try (PDDocument pdfDocument = Loader.loadPDF(os.toByteArray())) {
117107
FontExtractor fontExtractor = new FontExtractor();
118108
fontExtractor.getText(pdfDocument);
119109
assertEquals("Courier", fontExtractor.getFontUsage().get("H"));
120-
} finally {
121-
if (pdfDocument != null) {
122-
pdfDocument.close();
123-
}
124110
}
125111
}
126112

127-
class FontExtractor extends PDFTextStripper {
113+
static class FontExtractor extends PDFTextStripper {
128114

129115
private Map<String, String> fontUsage = new HashMap<>();
130116

0 commit comments

Comments
 (0)