Author: tilman
Date: Sun Jun 14 11:12:03 2026
New Revision: 1935285

Log:
PDFBOX-5660: Sonar fix

Modified:
   pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSBoolean.java
   pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSInteger.java

Modified: 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSBoolean.java
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSBoolean.java 
Sun Jun 14 11:11:59 2026        (r1935284)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSBoolean.java 
Sun Jun 14 11:12:03 2026        (r1935285)
@@ -20,9 +20,9 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 
 import org.apache.pdfbox.pdfwriter.COSWriter;
@@ -92,23 +92,14 @@ class TestCOSBoolean extends TestCOSBase
 
     @Override
     @Test
-    void testAccept()
+    void testAccept() throws IOException
     {
         ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         COSWriter visitor = new COSWriter(outStream);
-        int index = 0;
-        try
-        {
-            cosBooleanTrue.accept(visitor);
-            
testByteArrays(String.valueOf(cosBooleanTrue).getBytes(StandardCharsets.ISO_8859_1),
 outStream.toByteArray());
-            outStream.reset();
-            cosBooleanFalse.accept(visitor);
-            
testByteArrays(String.valueOf(cosBooleanFalse).getBytes(StandardCharsets.ISO_8859_1),
 outStream.toByteArray());
-            outStream.reset();
-        }
-        catch (Exception e)
-        {
-            fail("Failed to write " + index + " exception: " + e.getMessage());
-        }
+        cosBooleanTrue.accept(visitor);
+        
testByteArrays(String.valueOf(cosBooleanTrue).getBytes(StandardCharsets.ISO_8859_1),
 outStream.toByteArray());
+        outStream.reset();
+        cosBooleanFalse.accept(visitor);
+        
testByteArrays(String.valueOf(cosBooleanFalse).getBytes(StandardCharsets.ISO_8859_1),
 outStream.toByteArray());
     }
 }

Modified: 
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSInteger.java
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSInteger.java 
Sun Jun 14 11:11:59 2026        (r1935284)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSInteger.java 
Sun Jun 14 11:12:03 2026        (r1935285)
@@ -19,13 +19,13 @@ package org.apache.pdfbox.cos;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertNotSame;
-import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 
 import org.apache.pdfbox.pdfwriter.COSWriter;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
@@ -125,21 +125,16 @@ class TestCOSInteger extends TestCOSNumb
     {
         ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         COSWriter visitor = new COSWriter(outStream);
-        int index = 0;
-        try
+        for (int i = -1000; i < 3000; i += 200)
         {
-            for (int i = -1000; i < 3000; i += 200)
+            final int index = i;
+            assertDoesNotThrow(() -> 
             {
-                index = i;
-                COSInteger cosInt = COSInteger.get(i);
+                COSInteger cosInt = COSInteger.get(index);
                 cosInt.accept(visitor);
-                
testByteArrays(String.valueOf(i).getBytes(StandardCharsets.ISO_8859_1), 
outStream.toByteArray());
+                
testByteArrays(String.valueOf(index).getBytes(StandardCharsets.ISO_8859_1), 
outStream.toByteArray());
                 outStream.reset();
-            }
-        }
-        catch (Exception e)
-        {
-            fail("Failed to write " + index + " exception: " + e.getMessage());
+            }, "Failed to write " + index);
         }
     }
 
@@ -150,21 +145,16 @@ class TestCOSInteger extends TestCOSNumb
     void testWritePDF()
     {
         ByteArrayOutputStream outStream = new ByteArrayOutputStream();
-        int index = 0;
-        try
+        for (int i = -1000; i < 3000; i += 200)
         {
-            for (int i = -1000; i < 3000; i += 200)
+            final int index = i;
+            assertDoesNotThrow(() -> 
             {
-                index = i;
-                COSInteger cosInt = COSInteger.get(i);
+                COSInteger cosInt = COSInteger.get(index);
                 cosInt.writePDF(outStream);
-                
testByteArrays(String.valueOf(i).getBytes(StandardCharsets.ISO_8859_1), 
outStream.toByteArray());
+                
testByteArrays(String.valueOf(index).getBytes(StandardCharsets.ISO_8859_1), 
outStream.toByteArray());
                 outStream.reset();
-            }
-        }
-        catch (Exception e)
-        {
-            fail("Failed to write " + index + " exception: " + e.getMessage());
+            }, "Failed to write " + index);
         }
     }
 }

Reply via email to