From 8e77cd5b7bb56788c295dedef3ac29b3616bab19 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 8 Nov 2018 15:34:57 +0000 Subject: [PATCH] JAL-1889 ignore Clover instrumentation in test (second attempt) --- test/jalview/viewmodel/styles/ViewStyleTest.java | 57 ++++++++++++---------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/test/jalview/viewmodel/styles/ViewStyleTest.java b/test/jalview/viewmodel/styles/ViewStyleTest.java index 2fcfe1a..bc74d8a 100644 --- a/test/jalview/viewmodel/styles/ViewStyleTest.java +++ b/test/jalview/viewmodel/styles/ViewStyleTest.java @@ -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,27 +78,36 @@ 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! + * just instrumentation added by test coverage while testing */ + String type = field.getClass().toString(); + if (type.toString().contains("com_atlassian_clover")) + { + // instrumentation added for test coverage - ignore + return true; + } return false; } @@ -114,11 +123,6 @@ public class ViewStyleTest { Class type = field.getType(); - if (type.toString().contains("com_atlassian_clover")) - { - // instrumentation added for test coverage - ignore - return; - } if (type.equals(boolean.class) || type.equals(Boolean.class)) { boolean value = (Boolean) field.get(vs); @@ -215,19 +219,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); } } } -- 1.7.10.2