@@ -55,25 +55,28 @@ private PDDocument createDocument(String title, PDFont font, String text) throws
5555 void testEscapeTitle () throws IOException
5656 {
5757 PDFTextStripper stripper = new PDFText2HTML ();
58- PDDocument doc = createDocument ("<script>\u3042 " , new PDType1Font (FontName .HELVETICA ),
59- "<foo>" );
60- String text = stripper .getText (doc );
61-
62- Matcher m = Pattern .compile ("<title>(.*?)</title>" ).matcher (text );
63- assertTrue (m .find ());
64- assertEquals ("<script>あ" , m .group (1 ));
65- assertTrue (text .contains ("<foo>" ));
58+ try (PDDocument doc = createDocument ("<script>\u3042 " , new PDType1Font (FontName .HELVETICA ), "<foo>" ))
59+ {
60+ String text = stripper .getText (doc );
61+
62+ Matcher m = Pattern .compile ("<title>(.*?)</title>" ).matcher (text );
63+ assertTrue (m .find ());
64+ assertEquals ("<script>あ" , m .group (1 ));
65+ assertTrue (text .contains ("<foo>" ));
66+ }
6667 }
6768
6869 @ Test
6970 void testStyle () throws IOException
7071 {
7172 PDFTextStripper stripper = new PDFText2HTML ();
72- PDDocument doc = createDocument ("t" , new PDType1Font (FontName .HELVETICA_BOLD ), "<bold>" );
73- String text = stripper .getText (doc );
74-
75- Matcher bodyMatcher = Pattern .compile ("<p>(.*?)</p>" ).matcher (text );
76- assertTrue (bodyMatcher .find (), "body p exists" );
77- assertEquals ("<b><bold></b>" , bodyMatcher .group (1 ), "body p" );
73+ try (PDDocument doc = createDocument ("t" , new PDType1Font (FontName .HELVETICA_BOLD ), "<bold>" ))
74+ {
75+ String text = stripper .getText (doc );
76+
77+ Matcher bodyMatcher = Pattern .compile ("<p>(.*?)</p>" ).matcher (text );
78+ assertTrue (bodyMatcher .find (), "body p exists" );
79+ assertEquals ("<b><bold></b>" , bodyMatcher .group (1 ), "body p" );
80+ }
7881 }
7982}
0 commit comments