Skip to content

Commit ace0d82

Browse files
committed
PDFBOX-5660: Sonar fix
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1935281 13f79535-47bb-0310-9956-ffa450edef68
1 parent 9dda389 commit ace0d82

1 file changed

Lines changed: 20 additions & 31 deletions

File tree

‎pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSString.java‎

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2222
import static org.junit.jupiter.api.Assertions.assertThrows;
2323
import static org.junit.jupiter.api.Assertions.assertTrue;
24-
import static org.junit.jupiter.api.Assertions.fail;
2524

2625
import java.io.ByteArrayOutputStream;
2726
import java.io.IOException;
@@ -88,23 +87,18 @@ private void writePDFTests(String expected, COSString testSubj) throws IOExcepti
8887

8988
/**
9089
* Test parseHex() - tests that the proper String is created from a hex string input.
90+
*
91+
* @throws IOException
9192
*/
9293
@Test
93-
void testFromHex()
94+
void testFromHex() throws IOException
9495
{
9596
String expected = "Quick and simple test";
9697
String hexForm = createHex(expected);
97-
try
98-
{
99-
COSString test1 = COSString.parseHex(hexForm);
100-
writePDFTests("(" + expected + ")", test1);
101-
COSString test2 = COSString.parseHex(createHex(ESC_CHAR_STRING));
102-
writePDFTests("(" + ESC_CHAR_STRING_PDF_FORMAT + ")", test2);
103-
}
104-
catch (IOException e)
105-
{
106-
fail("IOException thrown: " + e.getMessage());
107-
}
98+
COSString test1 = COSString.parseHex(hexForm);
99+
writePDFTests("(" + expected + ")", test1);
100+
COSString test2 = COSString.parseHex(createHex(ESC_CHAR_STRING));
101+
writePDFTests("(" + ESC_CHAR_STRING_PDF_FORMAT + ")", test2);
108102
assertThrows(IOException.class, () -> COSString.parseHex(hexForm + "xx"),
109103
"Should have thrown an IOException here");
110104
}
@@ -137,30 +131,25 @@ void testGetHex()
137131

138132
/**
139133
* Test testGetString() - ensure getString() are returned in the correct format.
134+
*
135+
* @throws IOException
140136
*/
141137
@Test
142-
void testGetString()
138+
void testGetString() throws IOException
143139
{
144-
try
145-
{
146-
String testStr = "Test subject for getString()";
147-
COSString test1 = new COSString(testStr);
148-
assertEquals(testStr, test1.getString());
140+
String testStr = "Test subject for getString()";
141+
COSString test1 = new COSString(testStr);
142+
assertEquals(testStr, test1.getString());
149143

150-
COSString hexStr = COSString.parseHex(createHex(testStr));
151-
assertEquals(testStr, hexStr.getString());
144+
COSString hexStr = COSString.parseHex(createHex(testStr));
145+
assertEquals(testStr, hexStr.getString());
152146

153-
COSString escapedString = new COSString(ESC_CHAR_STRING);
154-
assertEquals(ESC_CHAR_STRING, escapedString.getString());
147+
COSString escapedString = new COSString(ESC_CHAR_STRING);
148+
assertEquals(ESC_CHAR_STRING, escapedString.getString());
155149

156-
testStr = "Line1\nLine2\nLine3\n";
157-
COSString lineFeedString = new COSString(testStr);
158-
assertEquals(testStr, lineFeedString.getString());
159-
}
160-
catch (IOException e)
161-
{
162-
fail("IOException thrown: " + e.getMessage());
163-
}
150+
testStr = "Line1\nLine2\nLine3\n";
151+
COSString lineFeedString = new COSString(testStr);
152+
assertEquals(testStr, lineFeedString.getString());
164153
}
165154

166155
/**

0 commit comments

Comments
 (0)