Skip to content

Commit c6c172d

Browse files
committed
PDFBOX-5660: close input
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1929979 13f79535-47bb-0310-9956-ffa450edef68
1 parent 11b9e43 commit c6c172d

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

fontbox/src/test/java/org/apache/fontbox/afm/AFMParserTest.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class AFMParserTest
4545
public static final String HELVETICA_AFM = "src/test/resources/afm/Helvetica.afm";
4646

4747
@Test
48-
void testStartFontMetrics() throws IOException
48+
void testStartFontMetrics()
4949
{
5050
assertThrows(IOException.class,
5151
() -> new AFMParser(new ByteArrayInputStream("huhu".getBytes(StandardCharsets.US_ASCII))).parse(),
@@ -55,30 +55,39 @@ void testStartFontMetrics() throws IOException
5555
@Test
5656
void testEndFontMetrics() throws IOException
5757
{
58-
AFMParser parser = new AFMParser(new FileInputStream("src/test/resources/afm/NoEndFontMetrics.afm"));
59-
IOException e = assertThrows(IOException.class, parser::parse,
60-
"The AFMParser should have thrown an IOException because of a missing " + AFMParser.END_FONT_METRICS);
61-
assertTrue(e.getMessage().contains("Unknown AFM key"));
58+
try (InputStream is = new FileInputStream("src/test/resources/afm/NoEndFontMetrics.afm"))
59+
{
60+
AFMParser parser = new AFMParser(is);
61+
IOException e = assertThrows(IOException.class, parser::parse,
62+
"The AFMParser should have thrown an IOException because of a missing " + AFMParser.END_FONT_METRICS);
63+
assertTrue(e.getMessage().contains("Unknown AFM key"));
64+
}
6265
}
6366

6467
@Test
6568
void testMalformedFloat() throws IOException
6669
{
67-
AFMParser parser = new AFMParser(new FileInputStream("src/test/resources/afm/MalformedFloat.afm"));
68-
IOException e = assertThrows(IOException.class, parser::parse,
69-
"The AFMParser should have thrown an IOException because of a malformed float value");
70-
assertInstanceOf(NumberFormatException.class, e.getCause());
71-
assertTrue(e.getMessage().contains("4,1ab"));
70+
try (InputStream is = new FileInputStream("src/test/resources/afm/MalformedFloat.afm"))
71+
{
72+
AFMParser parser = new AFMParser(is);
73+
IOException e = assertThrows(IOException.class, parser::parse,
74+
"The AFMParser should have thrown an IOException because of a malformed float value");
75+
assertInstanceOf(NumberFormatException.class, e.getCause());
76+
assertTrue(e.getMessage().contains("4,1ab"));
77+
}
7278
}
7379

7480
@Test
7581
void testMalformedInteger() throws IOException
7682
{
77-
AFMParser parser = new AFMParser(new FileInputStream("src/test/resources/afm/MalformedInteger.afm"));
78-
IOException e = assertThrows(IOException.class, parser::parse,
79-
"The AFMParser should have thrown an IOException because of a malformed int value");
80-
assertInstanceOf(NumberFormatException.class, e.getCause());
81-
assertTrue(e.getMessage().contains("3.4"));
83+
try (InputStream is = new FileInputStream("src/test/resources/afm/MalformedInteger.afm"))
84+
{
85+
AFMParser parser = new AFMParser(is);
86+
IOException e = assertThrows(IOException.class, parser::parse,
87+
"The AFMParser should have thrown an IOException because of a malformed int value");
88+
assertInstanceOf(NumberFormatException.class, e.getCause());
89+
assertTrue(e.getMessage().contains("3.4"));
90+
}
8291
}
8392

8493
@Test

0 commit comments

Comments
 (0)