Skip to content

Commit 85428cd

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

File tree

1 file changed

+26
-60
lines changed

1 file changed

+26
-60
lines changed

xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java

Lines changed: 26 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static org.junit.jupiter.api.Assertions.fail;
2727

2828
import java.io.ByteArrayOutputStream;
29+
import java.io.IOException;
2930
import java.io.InputStream;
3031
import java.util.List;
3132

@@ -35,6 +36,7 @@
3536
import org.apache.xmpbox.schema.DublinCoreSchema;
3637
import org.apache.xmpbox.schema.XMPBasicSchema;
3738
import org.apache.xmpbox.schema.XMPSchema;
39+
import org.apache.xmpbox.type.BadFieldValueException;
3840
import org.apache.xmpbox.type.ThumbnailType;
3941
import org.apache.xmpbox.xml.DomXmpParser;
4042
import org.apache.xmpbox.xml.XmpParsingException;
@@ -43,86 +45,73 @@
4345
import org.junit.jupiter.api.Test;
4446
import org.apache.xmpbox.xml.XmpSerializer;
4547

46-
class DeserializationTest {
48+
class DeserializationTest
49+
{
4750

4851
protected ByteArrayOutputStream bos;
4952

5053
protected XmpSerializer serializer;
5154

55+
private DomXmpParser xdb;
56+
5257
@BeforeEach
53-
void init() throws Exception
58+
void init() throws XmpParsingException
5459
{
5560
bos = new ByteArrayOutputStream();
5661
serializer = new XmpSerializer();
62+
xdb = new DomXmpParser();
5763
}
5864

5965
@Test
60-
void testStructuredRecursive() throws Exception
66+
void testStructuredRecursive() throws XmpParsingException
6167
{
6268
InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/structured_recursive.xml");
6369

64-
DomXmpParser xdb = new DomXmpParser();
65-
6670
xdb.parse(fis);
67-
6871
}
6972

7073
@Test
71-
void testEmptyLi() throws Exception
74+
void testEmptyLi() throws XmpParsingException
7275
{
7376
InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/empty_list.xml");
7477

75-
DomXmpParser xdb = new DomXmpParser();
76-
7778
xdb.parse(fis);
78-
7979
}
8080

8181
@Test
82-
void testEmptyLi2() throws Exception
82+
void testEmptyLi2() throws XmpParsingException
8383
{
8484
InputStream fis = DomXmpParser.class.getResourceAsStream("/validxmp/emptyli.xml");
85-
86-
DomXmpParser xdb = new DomXmpParser();
87-
8885
XMPMetadata meta = xdb.parse(fis);
8986
DublinCoreSchema dc = meta.getDublinCoreSchema();
9087
dc.getCreatorsProperty();
9188
}
9289

9390
@Test
94-
void testGetTitle() throws Exception
91+
void testGetTitle() throws XmpParsingException, BadFieldValueException
9592
{
9693
InputStream fis = DomXmpParser.class.getResourceAsStream("/validxmp/emptyli.xml");
97-
98-
DomXmpParser xdb = new DomXmpParser();
99-
10094
XMPMetadata meta = xdb.parse(fis);
10195
DublinCoreSchema dc = meta.getDublinCoreSchema();
10296
String s = dc.getTitle(null);
10397
assertEquals("title value", s);
10498
}
10599

106100
@Test
107-
void testAltBagSeq() throws Exception
101+
void testAltBagSeq() throws XmpParsingException
108102
{
109103
InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/AltBagSeqTest.xml");
110-
111-
DomXmpParser xdb = new DomXmpParser();
112-
113104
xdb.parse(fis);
114105
// XMPMetadata metadata=xdb.parse(fis);
115106
// SaveMetadataHelper.serialize(metadata, true, System.out);
116107
}
117108

118109
@Test
119-
void testIsartorStyleWithThumbs() throws Exception
110+
void testIsartorStyleWithThumbs() throws XmpParsingException, IOException, BadFieldValueException
120111
{
121112

122113
InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/ThumbisartorStyle.xml");
123114

124-
DomXmpParser xdb = new DomXmpParser();
125-
126115
XMPMetadata metadata = xdb.parse(fis);
127116

128117
// <xmpMM:DocumentID>
@@ -159,11 +148,9 @@ void testIsartorStyleWithThumbs() throws Exception
159148
}
160149

161150
@Test
162-
void testWithNoXPacketStart() throws Exception
151+
void testWithNoXPacketStart() throws XmpParsingException
163152
{
164153
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/noxpacket.xml");
165-
166-
DomXmpParser xdb = new DomXmpParser();
167154
try
168155
{
169156
xdb.parse(fis);
@@ -176,11 +163,9 @@ void testWithNoXPacketStart() throws Exception
176163
}
177164

178165
@Test
179-
void testWithNoXPacketEnd() throws Exception
166+
void testWithNoXPacketEnd() throws XmpParsingException
180167
{
181168
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/noxpacketend.xml");
182-
183-
DomXmpParser xdb = new DomXmpParser();
184169
try
185170
{
186171
xdb.parse(fis);
@@ -193,11 +178,9 @@ void testWithNoXPacketEnd() throws Exception
193178
}
194179

195180
@Test
196-
void testWithNoRDFElement() throws Exception
181+
void testWithNoRDFElement() throws XmpParsingException
197182
{
198183
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/noroot.xml");
199-
200-
DomXmpParser xdb = new DomXmpParser();
201184
try
202185
{
203186
xdb.parse(fis);
@@ -210,11 +193,9 @@ void testWithNoRDFElement() throws Exception
210193
}
211194

212195
@Test
213-
void testWithTwoRDFElement() throws Exception
196+
void testWithTwoRDFElement() throws XmpParsingException
214197
{
215198
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/tworoot.xml");
216-
217-
DomXmpParser xdb = new DomXmpParser();
218199
try
219200
{
220201
xdb.parse(fis);
@@ -227,11 +208,9 @@ void testWithTwoRDFElement() throws Exception
227208
}
228209

229210
@Test
230-
void testWithInvalidRDFElementPrefix() throws Exception
211+
void testWithInvalidRDFElementPrefix()
231212
{
232213
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/invalidroot2.xml");
233-
234-
DomXmpParser xdb = new DomXmpParser();
235214
try
236215
{
237216
xdb.parse(fis);
@@ -244,11 +223,9 @@ void testWithInvalidRDFElementPrefix() throws Exception
244223
}
245224

246225
@Test
247-
void testWithRDFRootAsText() throws Exception
226+
void testWithRDFRootAsText()
248227
{
249228
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/invalidroot.xml");
250-
251-
DomXmpParser xdb = new DomXmpParser();
252229
try
253230
{
254231
xdb.parse(fis);
@@ -261,11 +238,9 @@ void testWithRDFRootAsText() throws Exception
261238
}
262239

263240
@Test
264-
void testUndefinedSchema() throws Exception
241+
void testUndefinedSchema()
265242
{
266243
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/undefinedschema.xml");
267-
268-
DomXmpParser xdb = new DomXmpParser();
269244
try
270245
{
271246
xdb.parse(fis);
@@ -278,11 +253,9 @@ void testUndefinedSchema() throws Exception
278253
}
279254

280255
@Test
281-
void testUndefinedPropertyWithDefinedSchema() throws Exception
256+
void testUndefinedPropertyWithDefinedSchema()
282257
{
283258
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/undefinedpropertyindefinedschema.xml");
284-
285-
DomXmpParser xdb = new DomXmpParser();
286259
try
287260
{
288261
xdb.parse(fis);
@@ -295,11 +268,9 @@ void testUndefinedPropertyWithDefinedSchema() throws Exception
295268
}
296269

297270
@Test
298-
void testUndefinedStructuredWithDefinedSchema() throws Exception
271+
void testUndefinedStructuredWithDefinedSchema()
299272
{
300273
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/undefinedstructuredindefinedschema.xml");
301-
302-
DomXmpParser xdb = new DomXmpParser();
303274
try
304275
{
305276
xdb.parse(fis);
@@ -312,10 +283,9 @@ void testUndefinedStructuredWithDefinedSchema() throws Exception
312283
}
313284

314285
@Test
315-
void testRdfAboutFound() throws Exception
286+
void testRdfAboutFound() throws XmpParsingException
316287
{
317288
InputStream fis = DomXmpParser.class.getResourceAsStream("/validxmp/emptyli.xml");
318-
DomXmpParser xdb = new DomXmpParser();
319289
XMPMetadata meta = xdb.parse(fis);
320290
List<XMPSchema> schemas = meta.getAllSchemas();
321291
for (XMPSchema xmpSchema : schemas)
@@ -325,10 +295,9 @@ void testRdfAboutFound() throws Exception
325295
}
326296

327297
@Test
328-
void testWihtAttributesAsProperties() throws Exception
298+
void testWihtAttributesAsProperties() throws XmpParsingException
329299
{
330300
InputStream fis = DomXmpParser.class.getResourceAsStream("/validxmp/attr_as_props.xml");
331-
DomXmpParser xdb = new DomXmpParser();
332301
XMPMetadata meta = xdb.parse(fis);
333302

334303
AdobePDFSchema pdf = meta.getAdobePDFSchema();
@@ -339,21 +308,18 @@ void testWihtAttributesAsProperties() throws Exception
339308

340309
XMPBasicSchema basic = meta.getXMPBasicSchema();
341310
assertNotNull(basic.getCreateDate());
342-
343311
}
344312

345313
@Test
346-
void testSpaceTextValues() throws Exception
314+
void testSpaceTextValues() throws XmpParsingException
347315
{
348316
// check values with spaces at start or end
349317
// in this case, the value should not be trimmed
350318
InputStream is = DomXmpParser.class.getResourceAsStream("/validxmp/only_space_fields.xmp");
351-
DomXmpParser xdb = new DomXmpParser();
352319
XMPMetadata meta = xdb.parse(is);
353320
// check producer
354321
assertEquals(" ", meta.getAdobePDFSchema().getProducer());
355322
// check creator tool
356323
assertEquals("Canon ",meta.getXMPBasicSchema().getCreatorTool());
357-
358324
}
359325
}

0 commit comments

Comments
 (0)