@@ -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