JAL-1889 ignore 'synthetic' fields added for jacoco
[jalview.git] / test / jalview / viewmodel / styles / ViewStyleTest.java
index 26c3574..7deb2b0 100644 (file)
@@ -68,7 +68,7 @@ public class ViewStyleTest
     for (Field field : fields)
     {
       field.setAccessible(true);
-      if (!copyConstructorIgnores(field.getName()))
+      if (!copyConstructorIgnores(field))
       {
         changeValue(vs1, field);
       }
@@ -78,37 +78,45 @@ public class ViewStyleTest
 
     for (Field field1 : fields)
     {
-      final Object value1 = field1.get(vs1);
-      final Object value2 = field1.get(vs2);
-      String msg = "Mismatch in " + field1.getName() + "(" + value1 + "/"
+      if (!copyConstructorIgnores(field1))
+      {
+        final Object value1 = field1.get(vs1);
+        final Object value2 = field1.get(vs2);
+        String msg = "Mismatch in " + field1.getName() + "(" + value1 + "/"
               + value2 + ") - not set in copy constructor?";
-      assertEquals(msg, value1, value2);
+        assertEquals(msg, value1, value2);
+      }
     }
     assertEquals("Hashcode not equals", vs1.hashCode(), vs2.hashCode());
   }
 
   /**
-   * Add any field names in here that we expect to be ignored by the copy
-   * constructor
+   * Add tests here for any fields that we expect to be ignored by 
+   * the copy constructor
    * 
-   * @param name
+   * @param field
    * @return
    */
-  private boolean copyConstructorIgnores(String name)
+  private boolean copyConstructorIgnores(Field field)
   {
     /*
-     * currently none!
+     * ignore instrumentation added by jacoco for test coverage
      */
+    if (field.isSynthetic())
+    {
+      return true;
+    }
+
     return false;
   }
-
+  
   /**
-   * Change the value of one field in a ViewStyle object
-   * 
-   * @param vs
-   * @param field
-   * @throws IllegalAccessException
-   */
+  * Change the value of one field in a ViewStyle object
+  * 
+  * @param vs
+  * @param field
+  * @throws IllegalAccessException
+  */
   protected void changeValue(ViewStyle vs, Field field)
           throws IllegalAccessException
   {
@@ -210,19 +218,22 @@ public class ViewStyleTest
     Field[] fields = ViewStyle.class.getDeclaredFields();
     for (Field field : fields)
     {
-      field.setAccessible(true);
-      Object oldValue = field.get(vs2);
-      changeValue(vs2, field);
-      assertFalse("equals method ignores " + field.getName(),
+      if (!copyConstructorIgnores(field))
+      {
+        field.setAccessible(true);
+        Object oldValue = field.get(vs2);
+        changeValue(vs2, field);
+        assertFalse("equals method ignores " + field.getName(),
               vs1.equals(vs2));
 
-      if (vs1.hashCode() == vs2.hashCode())
-      {
-        // uncomment next line to see which fields hashCode ignores
-        // System.out.println("hashCode ignores " + field.getName());
+        if (vs1.hashCode() == vs2.hashCode())
+        {
+          // uncomment next line to see which fields hashCode ignores
+          // System.out.println("hashCode ignores " + field.getName());
+        }
+        // restore original value before testing the next field
+        field.set(vs2, oldValue);
       }
-      // restore original value before testing the next field
-      field.set(vs2, oldValue);
     }
   }
 }