1919import static org .junit .jupiter .api .Assertions .assertEquals ;
2020import static org .junit .jupiter .api .Assertions .assertNotEquals ;
2121import static org .junit .jupiter .api .Assertions .assertNotSame ;
22- import static org .junit .jupiter .api .Assertions .fail ;
2322
2423import java .io .ByteArrayOutputStream ;
2524import java .io .IOException ;
2625import java .nio .charset .StandardCharsets ;
2726
2827import org .apache .pdfbox .pdfwriter .COSWriter ;
28+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
2929import org .junit .jupiter .api .BeforeAll ;
3030import org .junit .jupiter .api .Test ;
3131
@@ -125,21 +125,16 @@ void testAccept()
125125 {
126126 ByteArrayOutputStream outStream = new ByteArrayOutputStream ();
127127 COSWriter visitor = new COSWriter (outStream );
128- int index = 0 ;
129- try
128+ for (int i = -1000 ; i < 3000 ; i += 200 )
130129 {
131- for (int i = -1000 ; i < 3000 ; i += 200 )
130+ final int index = i ;
131+ assertDoesNotThrow (() ->
132132 {
133- index = i ;
134- COSInteger cosInt = COSInteger .get (i );
133+ COSInteger cosInt = COSInteger .get (index );
135134 cosInt .accept (visitor );
136- testByteArrays (String .valueOf (i ).getBytes (StandardCharsets .ISO_8859_1 ), outStream .toByteArray ());
135+ testByteArrays (String .valueOf (index ).getBytes (StandardCharsets .ISO_8859_1 ), outStream .toByteArray ());
137136 outStream .reset ();
138- }
139- }
140- catch (Exception e )
141- {
142- fail ("Failed to write " + index + " exception: " + e .getMessage ());
137+ }, "Failed to write " + index );
143138 }
144139 }
145140
@@ -150,21 +145,16 @@ void testAccept()
150145 void testWritePDF ()
151146 {
152147 ByteArrayOutputStream outStream = new ByteArrayOutputStream ();
153- int index = 0 ;
154- try
148+ for (int i = -1000 ; i < 3000 ; i += 200 )
155149 {
156- for (int i = -1000 ; i < 3000 ; i += 200 )
150+ final int index = i ;
151+ assertDoesNotThrow (() ->
157152 {
158- index = i ;
159- COSInteger cosInt = COSInteger .get (i );
153+ COSInteger cosInt = COSInteger .get (index );
160154 cosInt .writePDF (outStream );
161- testByteArrays (String .valueOf (i ).getBytes (StandardCharsets .ISO_8859_1 ), outStream .toByteArray ());
155+ testByteArrays (String .valueOf (index ).getBytes (StandardCharsets .ISO_8859_1 ), outStream .toByteArray ());
162156 outStream .reset ();
163- }
164- }
165- catch (Exception e )
166- {
167- fail ("Failed to write " + index + " exception: " + e .getMessage ());
157+ }, "Failed to write " + index );
168158 }
169159 }
170160}
0 commit comments