Skip to content

Commit 7c590b6

Browse files
committed
PDFBOX-6112: test simple values to increase test coverage
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930129 13f79535-47bb-0310-9956-ffa450edef68
1 parent 469d0cb commit 7c590b6

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ void testRandomPropertySetterSimple(String fieldName, Types type, Cardinality ca
104104
schemaTester.testRandomPropertySetterSimple();
105105
}
106106

107+
@ParameterizedTest
108+
@MethodSource("initializeParameters")
109+
void testRandomSetterSimple(String fieldName, Types type, Cardinality card)
110+
throws ReflectiveOperationException
111+
{
112+
SchemaTester schemaTester = new SchemaTester(metadata, schemaClass, fieldName, type, card);
113+
schemaTester.testRandomSetterSimple();
114+
}
115+
107116
@ParameterizedTest
108117
@MethodSource("initializeParameters")
109118
void testPropertySetterInArray(String fieldName, Types type, Cardinality card)

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ public void testRandomPropertySetterSimple() throws ReflectiveOperationException
201201
}
202202
}
203203

204+
public void testRandomSetterSimple() throws ReflectiveOperationException
205+
{
206+
initializeSeed(new Random());
207+
for (int i=0; i < RAND_LOOP_COUNT;i++)
208+
{
209+
internalTestSetterSimple();
210+
}
211+
}
212+
204213
private void internalTestPropertySetterSimple() throws ReflectiveOperationException
205214
{
206215
if (cardinality != Cardinality.Simple)
@@ -283,4 +292,38 @@ protected String getPropertyQualifiedName(String name)
283292
sb.append(schema.getPrefix()).append(":").append(name);
284293
return sb.toString();
285294
}
295+
296+
// Test simple values to increase test coverage
297+
private void internalTestSetterSimple() throws ReflectiveOperationException
298+
{
299+
if (cardinality != Cardinality.Simple)
300+
{
301+
return;
302+
}
303+
304+
if (schemaClass == PhotoshopSchema.class &&
305+
("Urgency".equals(fieldName) || "ColorMode".equals(fieldName) || "DateCreated".equals(fieldName)))
306+
{
307+
// can't test these because return type != parameter (Urgency / ColorMode)
308+
// or because value isn't expected parameter (DateCreated: getJavaValue() gives Calendar)
309+
return;
310+
}
311+
312+
XMPSchema schema = getSchema();
313+
314+
String setter = calculateSimpleSetter(fieldName);
315+
Object value = getJavaValue(type);
316+
AbstractSimpleProperty asp = typeMapping.instanciateSimpleProperty(schema.getNamespace(), schema
317+
.getPrefix(), fieldName, value, type);
318+
Method set = schemaClass.getMethod(setter, String.class);
319+
set.invoke(schema, value);
320+
// check property set
321+
AbstractSimpleProperty stored = (AbstractSimpleProperty) schema.getProperty(fieldName);
322+
assertEquals(value, stored.getValue());
323+
// check getter
324+
String getter = calculateSimpleGetter(fieldName);
325+
Method get = schemaClass.getMethod(getter);
326+
Object result = get.invoke(schema);
327+
assertEquals(value, result);
328+
}
286329
}

0 commit comments

Comments
 (0)