Skip to content

Commit 41ad385

Browse files
committed
PDFBOX-5660: Sonar fix
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1925043 13f79535-47bb-0310-9956-ffa450edef68
1 parent 85428cd commit 41ad385

File tree

2 files changed

+35
-73
lines changed

2 files changed

+35
-73
lines changed

xmpbox/src/test/java/org/apache/xmpbox/schema/XMPSchemaTest.java

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
package org.apache.xmpbox.schema;
2323

24+
import java.io.IOException;
2425
import static org.junit.jupiter.api.Assertions.assertEquals;
2526
import static org.junit.jupiter.api.Assertions.assertFalse;
2627
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -55,7 +56,7 @@ class XMPSchemaTest
5556
* @throws IllegalArgumentException
5657
*/
5758
@Test
58-
void testBagManagement() throws Exception
59+
void testBagManagement()
5960
{
6061
String bagName = "BAGTEST";
6162
String value1 = "valueOne";
@@ -71,11 +72,10 @@ void testBagManagement() throws Exception
7172
List<String> values2 = schem.getUnqualifiedBagValueList(bagName);
7273
assertEquals(1, values2.size());
7374
assertEquals(value2, values2.get(0));
74-
7575
}
7676

7777
@Test
78-
void testArrayList() throws Exception
78+
void testArrayList() throws BadFieldValueException
7979
{
8080
XMPMetadata meta = XMPMetadata.createXMPMetadata();
8181
ArrayProperty newSeq = meta.getTypeMapping().createArrayProperty(null, "nsSchem", "seqType", Cardinality.Seq);
@@ -97,7 +97,7 @@ void testArrayList() throws Exception
9797
* @throws java.io.IOException
9898
*/
9999
@Test
100-
void testSeqManagement() throws Exception
100+
void testSeqManagement()
101101
{
102102
Calendar date = Calendar.getInstance();
103103
BooleanType bool = parent.getTypeMapping().createBoolean(null, "rdf", "li", true);
@@ -141,15 +141,15 @@ void rdfAboutTest()
141141
}
142142

143143
@Test
144-
void testBadRdfAbout() throws Exception
144+
void testBadRdfAbout()
145145
{
146146
assertThrows(BadFieldValueException.class, () -> {
147147
schem.setAbout(new Attribute(null, "about", ""));
148148
});
149149
}
150150

151151
@Test
152-
void testSetSpecifiedSimpleTypeProperty() throws Exception
152+
void testSetSpecifiedSimpleTypeProperty() throws BadFieldValueException
153153
{
154154
String prop = "testprop";
155155
String val = "value";
@@ -163,7 +163,7 @@ void testSetSpecifiedSimpleTypeProperty() throws Exception
163163
}
164164

165165
@Test
166-
void testSpecifiedSimplePropertyFormer() throws Exception
166+
void testSpecifiedSimplePropertyFormer() throws BadFieldValueException
167167
{
168168
String prop = "testprop";
169169
String val = "value";
@@ -176,7 +176,7 @@ void testSpecifiedSimplePropertyFormer() throws Exception
176176
}
177177

178178
@Test
179-
void testAsSimpleMethods() throws Exception
179+
void testAsSimpleMethods() throws BadFieldValueException
180180
{
181181
String bool = "bool";
182182
boolean boolVal = true;
@@ -235,7 +235,7 @@ void testAsSimpleMethods() throws Exception
235235
* @throws BadFieldValueException
236236
*/
237237
@Test
238-
void testProperties() throws Exception
238+
void testProperties() throws BadFieldValueException
239239
{
240240

241241
assertEquals("nsURI", schem.getNamespace());
@@ -288,50 +288,13 @@ void testProperties() throws Exception
288288
assertEquals(intType, schem.getIntegerProperty("intType"));
289289

290290
// Check bad type verification
291-
boolean ok = false;
292-
try
293-
{
294-
schem.getIntegerProperty("boolType");
295-
}
296-
catch (BadFieldValueException e)
297-
{
298-
ok = true;
299-
}
300-
assertTrue(ok);
301-
ok = false;
302-
try
303-
{
304-
schem.getUnqualifiedTextProperty("intType");
305-
}
306-
catch (BadFieldValueException e)
307-
{
308-
ok = true;
309-
}
310-
assertTrue(ok);
311-
ok = false;
312-
try
313-
{
314-
schem.getDateProperty("textType");
315-
}
316-
catch (BadFieldValueException e)
317-
{
318-
ok = true;
319-
}
320-
assertTrue(ok);
321-
ok = false;
322-
try
323-
{
324-
schem.getBooleanProperty("dateType");
325-
}
326-
catch (BadFieldValueException e)
327-
{
328-
ok = true;
329-
}
330-
291+
assertThrows(BadFieldValueException.class, () -> schem.getIntegerProperty("boolType"));
292+
assertThrows(BadFieldValueException.class, () -> schem.getDateProperty("textType"));
293+
assertThrows(BadFieldValueException.class, () -> schem.getBooleanProperty("dateType"));
331294
}
332295

333296
@Test
334-
void testAltProperties() throws Exception
297+
void testAltProperties() throws BadFieldValueException
335298
{
336299
String altProp = "AltProp";
337300

@@ -380,7 +343,7 @@ void testAltProperties() throws Exception
380343
* @throws java.io.IOException
381344
*/
382345
@Test
383-
void testMergeSchema() throws Exception
346+
void testMergeSchema() throws IOException, BadFieldValueException
384347
{
385348
String bagName = "bagName";
386349
String seqName = "seqName";
@@ -426,7 +389,7 @@ void testMergeSchema() throws Exception
426389
}
427390

428391
@Test
429-
void testListAndContainerAccessor() throws Exception
392+
void testListAndContainerAccessor()
430393
{
431394
String boolname = "bool";
432395
boolean boolVal = true;
@@ -440,6 +403,5 @@ void testListAndContainerAccessor() throws Exception
440403
assertTrue(schem.getAllAttributes().contains(att));
441404

442405
assertEquals(bool, schem.getProperty(boolname));
443-
444406
}
445407
}

xmpbox/src/test/java/org/apache/xmpbox/schema/XMPSchemaTester.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static PropertyType createPropertyType(Types type, Cardinality card)
7575
return TypeMapping.createPropertyType(type, card);
7676
}
7777

78-
public void testGetSetValue() throws Exception
78+
public void testGetSetValue() throws ReflectiveOperationException
7979
{
8080
if (type.type() == Types.Text && type.card() == Cardinality.Simple)
8181
{
@@ -119,11 +119,11 @@ else if (type.card() != Cardinality.Simple)
119119
}
120120
else
121121
{
122-
throw new Exception("Unknown type : " + type);
122+
throw new IllegalArgumentException("Unknown type : " + type);
123123
}
124124
}
125125

126-
public void testGetSetProperty() throws Exception
126+
public void testGetSetProperty() throws ReflectiveOperationException
127127
{
128128
if (type.type() == Types.Text && type.card() == Cardinality.Simple)
129129
{
@@ -187,7 +187,7 @@ else if (type.type() == Types.Thumbnail && type.card() == Cardinality.Alt)
187187
}
188188
else
189189
{
190-
throw new Exception("Unknown type : " + type);
190+
throw new IllegalArgumentException("Unknown type : " + type);
191191
}
192192
Field[] fields = schemaClass.getFields();
193193
for (Field field : fields)
@@ -323,7 +323,7 @@ protected String addToValueMethod(String prop)
323323

324324
}
325325

326-
protected void testGetSetBooleanProperty() throws Exception
326+
protected void testGetSetBooleanProperty() throws ReflectiveOperationException
327327
{
328328
String setName = setMethod(property);
329329
String getName = getMethod(property);
@@ -338,7 +338,7 @@ protected void testGetSetBooleanProperty() throws Exception
338338

339339
}
340340

341-
protected void testGetSetDateProperty() throws Exception
341+
protected void testGetSetDateProperty() throws ReflectiveOperationException
342342
{
343343
String setName = setMethod(property);
344344
String getName = getMethod(property);
@@ -352,7 +352,7 @@ protected void testGetSetDateProperty() throws Exception
352352
assertEquals(value, found);
353353
}
354354

355-
protected void testGetSetIntegerProperty() throws Exception
355+
protected void testGetSetIntegerProperty() throws ReflectiveOperationException
356356
{
357357
String setName = setMethod(property);
358358
String getName = getMethod(property);
@@ -366,7 +366,7 @@ protected void testGetSetIntegerProperty() throws Exception
366366
assertEquals(value, found);
367367
}
368368

369-
protected void testGetSetTextProperty() throws Exception
369+
protected void testGetSetTextProperty() throws ReflectiveOperationException
370370
{
371371
String setName = setMethod(property);
372372
String getName = getMethod(property);
@@ -381,7 +381,7 @@ protected void testGetSetTextProperty() throws Exception
381381

382382
}
383383

384-
protected void testGetSetURIProperty() throws Exception
384+
protected void testGetSetURIProperty() throws ReflectiveOperationException
385385
{
386386
String setName = setMethod(property);
387387
String getName = getMethod(property);
@@ -396,7 +396,7 @@ protected void testGetSetURIProperty() throws Exception
396396

397397
}
398398

399-
protected void testGetSetURLProperty() throws Exception
399+
protected void testGetSetURLProperty() throws ReflectiveOperationException
400400
{
401401
String setName = setMethod(property);
402402
String getName = getMethod(property);
@@ -411,7 +411,7 @@ protected void testGetSetURLProperty() throws Exception
411411

412412
}
413413

414-
protected void testGetSetAgentNameProperty() throws Exception
414+
protected void testGetSetAgentNameProperty() throws ReflectiveOperationException
415415
{
416416
String setName = setMethod(property);
417417
String getName = getMethod(property);
@@ -427,7 +427,7 @@ protected void testGetSetAgentNameProperty() throws Exception
427427

428428
}
429429

430-
protected void testGetSetTextListValue(String tp) throws Exception
430+
protected void testGetSetTextListValue(String tp) throws ReflectiveOperationException
431431
{
432432
String setName = addToValueMethod(property);
433433
String getName = getValueMethod(property);
@@ -448,7 +448,7 @@ protected void testGetSetTextListValue(String tp) throws Exception
448448
}
449449
}
450450

451-
protected void testGetSetDateListValue(String tp) throws Exception
451+
protected void testGetSetDateListValue(String tp) throws ReflectiveOperationException
452452
{
453453
String setName = addToValueMethod(property);
454454
String getName = getValueMethod(property);
@@ -469,7 +469,7 @@ protected void testGetSetDateListValue(String tp) throws Exception
469469
}
470470
}
471471

472-
protected void testGetSetThumbnail() throws Exception
472+
protected void testGetSetThumbnail() throws ReflectiveOperationException
473473
{
474474
String addName = addMethod(property);
475475
String getName = getMethod(property);
@@ -489,7 +489,7 @@ protected void testGetSetThumbnail() throws Exception
489489
assertEquals(img, t1.getImage());
490490
}
491491

492-
protected void testGetSetLangAltValue() throws Exception
492+
protected void testGetSetLangAltValue() throws ReflectiveOperationException
493493
{
494494
String setName = addToValueMethod(property);
495495
String getName = getValueMethod(property);
@@ -513,7 +513,7 @@ protected void testGetSetLangAltValue() throws Exception
513513
}
514514
}
515515

516-
protected void testGetSetURLValue() throws Exception
516+
protected void testGetSetURLValue() throws ReflectiveOperationException
517517
{
518518
String setName = addToValueMethod(property);
519519
String getName = getValueMethod(property);
@@ -534,7 +534,7 @@ protected void testGetSetURLValue() throws Exception
534534
}
535535
}
536536

537-
protected void testGetSetTextValue() throws Exception
537+
protected void testGetSetTextValue() throws ReflectiveOperationException
538538
{
539539
String setName = setValueMethod(property);
540540
String getName = getValueMethod(property);
@@ -548,7 +548,7 @@ protected void testGetSetTextValue() throws Exception
548548
assertEquals(value, found);
549549
}
550550

551-
protected void testGetSetBooleanValue() throws Exception
551+
protected void testGetSetBooleanValue() throws ReflectiveOperationException
552552
{
553553
String setName = setValueMethod(property);
554554
String getName = getValueMethod(property);
@@ -562,7 +562,7 @@ protected void testGetSetBooleanValue() throws Exception
562562
assertEquals(value, found);
563563
}
564564

565-
protected void testGetSetDateValue() throws Exception
565+
protected void testGetSetDateValue() throws ReflectiveOperationException
566566
{
567567
String setName = setValueMethod(property);
568568
String getName = getValueMethod(property);
@@ -576,7 +576,7 @@ protected void testGetSetDateValue() throws Exception
576576
assertEquals(value, found);
577577
}
578578

579-
protected void testGetSetIntegerValue() throws Exception
579+
protected void testGetSetIntegerValue() throws ReflectiveOperationException
580580
{
581581
String setName = setValueMethod(property);
582582
String getName = getValueMethod(property);

0 commit comments

Comments
 (0)