Author: tilman
Date: Sun Jun 14 16:14:26 2026
New Revision: 1935312
Log:
PDFBOX-5660: Sonar fix
Modified:
pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java
Modified:
pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java
==============================================================================
---
pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java
Sun Jun 14 16:14:22 2026 (r1935311)
+++
pdfbox/trunk/xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java
Sun Jun 14 16:14:26 2026 (r1935312)
@@ -23,7 +23,7 @@ package org.apache.xmpbox.parser;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -213,12 +213,8 @@ class DeserializationTest
{
try (InputStream is =
DomXmpParser.class.getResourceAsStream("/invalidxmp/noxpacket.xml"))
{
- xdb.parse(is);
- fail("Should fail during parse");
- }
- catch (XmpParsingException e)
- {
- assertEquals(ErrorType.XpacketBadStart, e.getErrorType());
+ XmpParsingException ex = assertThrows(XmpParsingException.class,
() -> xdb.parse(is));
+ assertEquals(ErrorType.XpacketBadStart, ex.getErrorType());
}
}
@@ -227,12 +223,8 @@ class DeserializationTest
{
try (InputStream is =
DomXmpParser.class.getResourceAsStream("/invalidxmp/noxpacketend.xml"))
{
- xdb.parse(is);
- fail("Should fail during parse");
- }
- catch (XmpParsingException e)
- {
- assertEquals(ErrorType.XpacketBadEnd, e.getErrorType());
+ XmpParsingException ex = assertThrows(XmpParsingException.class,
() -> xdb.parse(is));
+ assertEquals(ErrorType.XpacketBadEnd, ex.getErrorType());
}
}
@@ -241,12 +233,8 @@ class DeserializationTest
{
try (InputStream is =
DomXmpParser.class.getResourceAsStream("/invalidxmp/noroot.xml"))
{
- xdb.parse(is);
- fail("Should fail during parse");
- }
- catch (XmpParsingException e)
- {
- assertEquals(ErrorType.Format, e.getErrorType());
+ XmpParsingException ex = assertThrows(XmpParsingException.class,
() -> xdb.parse(is));
+ assertEquals(ErrorType.Format, ex.getErrorType());
}
}
@@ -255,12 +243,8 @@ class DeserializationTest
{
try (InputStream is =
DomXmpParser.class.getResourceAsStream("/invalidxmp/tworoot.xml"))
{
- xdb.parse(is);
- fail("Should fail during parse");
- }
- catch (XmpParsingException e)
- {
- assertEquals(ErrorType.Format, e.getErrorType());
+ XmpParsingException ex = assertThrows(XmpParsingException.class,
() -> xdb.parse(is));
+ assertEquals(ErrorType.Format, ex.getErrorType());
}
}
@@ -269,12 +253,8 @@ class DeserializationTest
{
try (InputStream is =
DomXmpParser.class.getResourceAsStream("/invalidxmp/invalidroot2.xml"))
{
- xdb.parse(is);
- fail("Should fail during parse");
- }
- catch (XmpParsingException e)
- {
- assertEquals(ErrorType.Format, e.getErrorType());
+ XmpParsingException ex = assertThrows(XmpParsingException.class,
() -> xdb.parse(is));
+ assertEquals(ErrorType.Format, ex.getErrorType());
}
}
@@ -283,12 +263,8 @@ class DeserializationTest
{
try (InputStream is =
DomXmpParser.class.getResourceAsStream("/invalidxmp/invalidroot.xml"))
{
- xdb.parse(is);
- fail("Should fail during parse");
- }
- catch (XmpParsingException e)
- {
- assertEquals(ErrorType.Format, e.getErrorType());
+ XmpParsingException ex = assertThrows(XmpParsingException.class,
() -> xdb.parse(is));
+ assertEquals(ErrorType.Format, ex.getErrorType());
}
}
@@ -297,12 +273,8 @@ class DeserializationTest
{
try (InputStream is =
DomXmpParser.class.getResourceAsStream("/invalidxmp/undefinedschema.xml"))
{
- xdb.parse(is);
- fail("Should fail during parse");
- }
- catch (XmpParsingException e)
- {
- assertEquals(ErrorType.NoSchema, e.getErrorType());
+ XmpParsingException ex = assertThrows(XmpParsingException.class,
() -> xdb.parse(is));
+ assertEquals(ErrorType.NoSchema, ex.getErrorType());
}
}
@@ -311,12 +283,8 @@ class DeserializationTest
{
try (InputStream is =
DomXmpParser.class.getResourceAsStream("/invalidxmp/undefinedpropertyindefinedschema.xml"))
{
- xdb.parse(is);
- fail("Should fail during parse");
- }
- catch (XmpParsingException e)
- {
- assertEquals(ErrorType.NoType, e.getErrorType(), e.getMessage());
+ XmpParsingException ex = assertThrows(XmpParsingException.class,
() -> xdb.parse(is));
+ assertEquals(ErrorType.NoType, ex.getErrorType());
}
}
@@ -325,12 +293,8 @@ class DeserializationTest
{
try (InputStream is =
DomXmpParser.class.getResourceAsStream("/invalidxmp/undefinedstructuredindefinedschema.xml"))
{
- xdb.parse(is);
- fail("Should fail during parse");
- }
- catch (XmpParsingException e)
- {
- assertEquals(ErrorType.NoValueType, e.getErrorType());
+ XmpParsingException ex = assertThrows(XmpParsingException.class,
() -> xdb.parse(is));
+ assertEquals(ErrorType.NoValueType, ex.getErrorType());
}
}