Skip to content

Commit b5adf76

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

1 file changed

Lines changed: 24 additions & 40 deletions

File tree

‎pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/color/PDIndexedTest.java‎

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertThrows;
2121
import static org.junit.jupiter.api.Assertions.assertTrue;
22-
import static org.junit.jupiter.api.Assertions.fail;
2322

2423
import java.io.ByteArrayOutputStream;
2524
import java.io.IOException;
@@ -41,7 +40,7 @@ class PDIndexedTest
4140
* Test of factory method for PDFBOX-6192.
4241
*/
4342
@Test
44-
void testFactory()
43+
void testFactory() throws IOException
4544
{
4645
final PDColorSpace baseColorspace = PDDeviceRGB.INSTANCE;
4746
// define 6 color values
@@ -52,44 +51,37 @@ void testFactory()
5251
// expected written string for COSArray
5352
final String outputString = "/Indexed /DeviceRGB 5 <" + stringLookupData + ">";
5453

55-
try
56-
{
57-
byte[] lookupData = COSString.parseHex(stringLookupData).getBytes();
58-
PDIndexed pdIndexed = PDIndexed.create(baseColorspace, hival, lookupData);
59-
COSArray indexedCOSArray = ((COSArray) pdIndexed.getCOSObject());
60-
assertEquals(hival, ((COSNumber) indexedCOSArray.getObject(2)).intValue(),
61-
"unexpected value for hival");
62-
assertEquals(COSName.INDEXED.getName(), pdIndexed.getName(),
63-
"unexpected value for name");
64-
assertEquals(baseColorspace, pdIndexed.getBaseColorSpace(),
65-
"unexpected value for base colorspace");
66-
String lookupDataString = ((COSString) indexedCOSArray.getObject(3)).toHexString();
67-
assertEquals(stringLookupData, lookupDataString, "unexpected value for lookup data");
54+
byte[] lookupData = COSString.parseHex(stringLookupData).getBytes();
55+
PDIndexed pdIndexed = PDIndexed.create(baseColorspace, hival, lookupData);
56+
COSArray indexedCOSArray = ((COSArray) pdIndexed.getCOSObject());
57+
assertEquals(hival, ((COSNumber) indexedCOSArray.getObject(2)).intValue(),
58+
"unexpected value for hival");
59+
assertEquals(COSName.INDEXED.getName(), pdIndexed.getName(),
60+
"unexpected value for name");
61+
assertEquals(baseColorspace, pdIndexed.getBaseColorSpace(),
62+
"unexpected value for base colorspace");
63+
String lookupDataString = ((COSString) indexedCOSArray.getObject(3)).toHexString();
64+
assertEquals(stringLookupData, lookupDataString, "unexpected value for lookup data");
6865

69-
try (PDDocument document = new PDDocument())
70-
{
71-
PDPage page = new PDPage();
72-
PDResources resources = new PDResources();
73-
resources.add(pdIndexed);
74-
page.setResources(resources);
75-
document.addPage(page);
76-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
77-
document.save(baos, CompressParameters.NO_COMPRESSION);
78-
String pdfAsString = baos.toString();
79-
assertTrue(pdfAsString.contains(outputString), "output doesn't match expected string");
80-
}
81-
}
82-
catch (IOException e)
66+
try (PDDocument document = new PDDocument())
8367
{
84-
fail("Unexpected exception", e);
68+
PDPage page = new PDPage();
69+
PDResources resources = new PDResources();
70+
resources.add(pdIndexed);
71+
page.setResources(resources);
72+
document.addPage(page);
73+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
74+
document.save(baos, CompressParameters.NO_COMPRESSION);
75+
String pdfAsString = baos.toString();
76+
assertTrue(pdfAsString.contains(outputString), "output doesn't match expected string");
8577
}
8678
}
8779

8880
/**
8981
* Test parameter of factory method.
9082
*/
9183
@Test
92-
void testFactoryParameterChecks()
84+
void testFactoryParameterChecks() throws IOException
9385
{
9486
final PDColorSpace baseColorspace = PDDeviceRGB.INSTANCE;
9587
// empty lookupData as placeholder
@@ -99,15 +91,7 @@ void testFactoryParameterChecks()
9991
// create s string containing 6 RGB values. Spaces are added for a better readability
10092
final String stringLookupData = "AA1166 112233 000000 FEDC01 4561FE DC34DA" //
10193
.replace(" ", "");
102-
byte[] lookupData = null;
103-
try
104-
{
105-
lookupData = COSString.parseHex(stringLookupData).getBytes();
106-
}
107-
catch (IOException e)
108-
{
109-
fail("Unexpected exception", e);
110-
}
94+
byte[] lookupData = COSString.parseHex(stringLookupData).getBytes();
11195

11296
// check lookupData not null
11397
assertThrows(IllegalArgumentException.class,

0 commit comments

Comments
 (0)