Skip to content

Commit 0bb0dbf

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

2 files changed

Lines changed: 20 additions & 39 deletions

File tree

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
import static org.junit.jupiter.api.Assertions.assertFalse;
2121
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2222
import static org.junit.jupiter.api.Assertions.assertTrue;
23-
import static org.junit.jupiter.api.Assertions.fail;
2423

2524
import java.io.ByteArrayOutputStream;
25+
import java.io.IOException;
2626
import java.nio.charset.StandardCharsets;
2727

2828
import org.apache.pdfbox.pdfwriter.COSWriter;
@@ -92,23 +92,14 @@ void testEquals()
9292

9393
@Override
9494
@Test
95-
void testAccept()
95+
void testAccept() throws IOException
9696
{
9797
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
9898
COSWriter visitor = new COSWriter(outStream);
99-
int index = 0;
100-
try
101-
{
102-
cosBooleanTrue.accept(visitor);
103-
testByteArrays(String.valueOf(cosBooleanTrue).getBytes(StandardCharsets.ISO_8859_1), outStream.toByteArray());
104-
outStream.reset();
105-
cosBooleanFalse.accept(visitor);
106-
testByteArrays(String.valueOf(cosBooleanFalse).getBytes(StandardCharsets.ISO_8859_1), outStream.toByteArray());
107-
outStream.reset();
108-
}
109-
catch (Exception e)
110-
{
111-
fail("Failed to write " + index + " exception: " + e.getMessage());
112-
}
99+
cosBooleanTrue.accept(visitor);
100+
testByteArrays(String.valueOf(cosBooleanTrue).getBytes(StandardCharsets.ISO_8859_1), outStream.toByteArray());
101+
outStream.reset();
102+
cosBooleanFalse.accept(visitor);
103+
testByteArrays(String.valueOf(cosBooleanFalse).getBytes(StandardCharsets.ISO_8859_1), outStream.toByteArray());
113104
}
114105
}

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

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2121
import static org.junit.jupiter.api.Assertions.assertNotSame;
22-
import static org.junit.jupiter.api.Assertions.fail;
2322

2423
import java.io.ByteArrayOutputStream;
2524
import java.io.IOException;
2625
import java.nio.charset.StandardCharsets;
2726

2827
import org.apache.pdfbox.pdfwriter.COSWriter;
28+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2929
import org.junit.jupiter.api.BeforeAll;
3030
import 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

Comments
 (0)