Author: tilman
Date: Sat Nov 29 18:09:49 2025
New Revision: 1930130

Log:
PDFBOX-6112: test simple values to increase test coverage

Modified:
   
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/schema/PhotoshopSchemaTest.java
   
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/schema/SchemaTester.java

Modified: 
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/schema/PhotoshopSchemaTest.java
==============================================================================
--- 
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/schema/PhotoshopSchemaTest.java
  Sat Nov 29 18:09:45 2025        (r1930129)
+++ 
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/schema/PhotoshopSchemaTest.java
  Sat Nov 29 18:09:49 2025        (r1930130)
@@ -100,6 +100,15 @@ class PhotoshopSchemaTest
 
     @ParameterizedTest
     @MethodSource("initializeParameters")
+    void testRandomSetterSimple(String fieldName, Types type, Cardinality card)
+            throws ReflectiveOperationException
+    {
+        SchemaTester schemaTester = new SchemaTester(metadata, schemaClass, 
fieldName, type, card);
+        schemaTester.testRandomSetterSimple();
+    }
+
+    @ParameterizedTest
+    @MethodSource("initializeParameters")
     void testPropertySetterInArray(String fieldName, Types type, Cardinality 
card) throws Exception
     {
         SchemaTester schemaTester = new SchemaTester(metadata, schemaClass, 
fieldName, type, card);

Modified: 
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/schema/SchemaTester.java
==============================================================================
--- 
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/schema/SchemaTester.java
 Sat Nov 29 18:09:45 2025        (r1930129)
+++ 
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/schema/SchemaTester.java
 Sat Nov 29 18:09:49 2025        (r1930130)
@@ -201,6 +201,15 @@ class SchemaTester extends AbstractTypeT
         }
     }
 
+    public void testRandomSetterSimple() throws ReflectiveOperationException
+    {
+        initializeSeed(new Random());
+        for (int i=0; i < RAND_LOOP_COUNT;i++)
+        {
+            internalTestSetterSimple();
+        }
+    }
+
     private void internalTestPropertySetterSimple() throws Exception
     {
         if (cardinality != Cardinality.Simple)
@@ -283,4 +292,38 @@ class SchemaTester extends AbstractTypeT
         sb.append(schema.getPrefix()).append(":").append(name);
         return sb.toString();
     }
+
+    // Test simple values to increase test coverage
+    private void internalTestSetterSimple() throws ReflectiveOperationException
+    {
+        if (cardinality != Cardinality.Simple)
+        {
+            return;
+        }
+
+        if (schemaClass == PhotoshopSchema.class && 
+                ("Urgency".equals(fieldName) || "ColorMode".equals(fieldName) 
|| "DateCreated".equals(fieldName)))
+        {
+            // can't test these because return type != parameter (Urgency / 
ColorMode)
+            // or because value isn't expected parameter (DateCreated: 
getJavaValue() gives Calendar)
+            return;
+        }
+
+        XMPSchema schema = getSchema();
+
+        String setter = calculateSimpleSetter(fieldName);
+        Object value = getJavaValue(type);
+        AbstractSimpleProperty asp = 
typeMapping.instanciateSimpleProperty(schema.getNamespace(), schema
+                .getPrefix(), fieldName, value, type);
+        Method set = schemaClass.getMethod(setter, String.class);
+        set.invoke(schema, value);
+        // check property set
+        AbstractSimpleProperty stored = (AbstractSimpleProperty) 
schema.getProperty(fieldName);
+        assertEquals(value, stored.getValue());
+        // check getter
+        String getter = calculateSimpleGetter(fieldName);
+        Method get = schemaClass.getMethod(getter);
+        Object result = get.invoke(schema);
+        assertEquals(value, result);
+    }
 }

Reply via email to