Skip to content

Commit 8399e31

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

4 files changed

Lines changed: 12 additions & 35 deletions

File tree

pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertThrows;
2122
import static org.junit.jupiter.api.Assertions.assertTrue;
22-
import static org.junit.jupiter.api.Assertions.fail;
2323

2424
import java.io.File;
2525
import java.io.IOException;
@@ -95,11 +95,9 @@ public static Collection<Integer> keyLengths()
9595
@BeforeAll
9696
static void init() throws NoSuchAlgorithmException
9797
{
98-
if (Cipher.getMaxAllowedKeyLength("AES") != Integer.MAX_VALUE)
99-
{
100-
// we need strong encryption for these tests
101-
fail("JCE unlimited strength jurisdiction policy files are not installed");
102-
}
98+
// we need strong encryption for these tests
99+
assertEquals(Integer.MAX_VALUE, Cipher.getMaxAllowedKeyLength("AES"),
100+
"JCE unlimited strength jurisdiction policy files are not installed");
103101
TESTRESULTSDIR.mkdirs();
104102
}
105103

@@ -169,16 +167,11 @@ void testProtectionError(int keyLength) throws IOException
169167
document.protect(policy);
170168

171169
File file = save("testProtectionError");
172-
try (PDDocument encryptedDoc = reload(file, password2, getKeyStore(keyStore2)))
173-
{
174-
assertTrue(encryptedDoc.isEncrypted());
175-
fail("No exception when using an incorrect decryption key");
176-
}
177-
catch (IOException ex)
178-
{
179-
String msg = ex.getMessage();
180-
assertTrue(msg.contains("serial-#: rid 2 vs. cert 3"), "not the expected exception: " + msg);
181-
}
170+
IOException ex = assertThrows(IOException.class,
171+
() -> reload(file, password2, getKeyStore(keyStore2)),
172+
"No exception when using an incorrect decryption key");
173+
String msg = ex.getMessage();
174+
assertTrue(msg.contains("serial-#: rid 2 vs. cert 3"), "not the expected exception: " + msg);
182175
}
183176

184177

pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestBaseParser.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.pdfbox.pdfparser;
1919

2020
import static org.junit.jupiter.api.Assertions.assertEquals;
21-
import static org.junit.jupiter.api.Assertions.fail;
2221

2322
import java.io.IOException;
2423
import java.io.InputStream;
@@ -42,10 +41,6 @@ void testBaseParserStackOverflow()
4241
{
4342
assertEquals("Missing root object specification in trailer.", exception.getMessage());
4443
}
45-
catch (Exception exception)
46-
{
47-
fail("Unexpected Exception");
48-
}
4944
}
5045

5146
}

pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/TestEmbeddedFiles.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static org.junit.jupiter.api.Assertions.assertNotNull;
2121
import static org.junit.jupiter.api.Assertions.assertNull;
2222
import static org.junit.jupiter.api.Assertions.assertTrue;
23-
import static org.junit.jupiter.api.Assertions.fail;
2423

2524
import java.io.IOException;
2625
import java.io.UnsupportedEncodingException;
@@ -69,10 +68,6 @@ void testNullEmbeddedFile() throws IOException
6968
assertNull(spec.getFile());
7069
assertNull(spec.getEmbeddedFile());
7170
}
72-
catch (NullPointerException e)
73-
{
74-
fail("null pointer exception");
75-
}
7671
assertTrue(ok, "Was able to get file without exception");
7772
assertNull(embeddedFile, "EmbeddedFile was correctly null");
7873
}

pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import static org.junit.jupiter.api.Assertions.assertNull;
5353
import static org.junit.jupiter.api.Assertions.assertThrows;
5454
import static org.junit.jupiter.api.Assertions.assertTrue;
55-
import static org.junit.jupiter.api.Assertions.fail;
5655
import org.junit.jupiter.api.BeforeAll;
5756
import org.junit.jupiter.api.Test;
5857
import org.junit.jupiter.api.parallel.Execution;
@@ -851,16 +850,11 @@ void testSurrogatePairCharacterExceptionIsValidCodePoint() throws IOException
851850
contents.beginText();
852851
contents.setFont(font, 64);
853852
contents.newLineAtOffset(100, 700);
854-
contents.showText(message);
853+
IllegalStateException ex =
854+
assertThrows(IllegalStateException.class, () -> contents.showText(message));
855+
assertEquals("could not find the glyphId for the character: 𩸽, codePoint: 171581 (0x29E3D)" ,ex.getMessage());
855856
contents.endText();
856857
}
857-
catch (IllegalStateException e)
858-
{
859-
assertEquals("could not find the glyphId for the character: 𩸽, codePoint: 171581 (0x29E3D)", e.getMessage());
860-
return;
861-
}
862-
863-
fail();
864858
}
865859
}
866860

0 commit comments

Comments
 (0)