X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fviewmodel%2Fstyles%2FViewStyleTest.java;h=3019afa0526963f1a79d64b2065541862cca2b56;hb=dc5a5883cfe90255079e41538e56bc433bd1e4a5;hp=26c3574722169ab4518caebe961d62e6aa7870fc;hpb=5f4e1e4c330b045e9c8bce28ee132a0fca3834d8;p=jalview.git diff --git a/test/jalview/viewmodel/styles/ViewStyleTest.java b/test/jalview/viewmodel/styles/ViewStyleTest.java index 26c3574..3019afa 100644 --- a/test/jalview/viewmodel/styles/ViewStyleTest.java +++ b/test/jalview/viewmodel/styles/ViewStyleTest.java @@ -60,15 +60,15 @@ public class ViewStyleTest * @throws IllegalArgumentException */ @Test(groups = { "Functional" }) - public void testCopyConstructor() throws IllegalArgumentException, - IllegalAccessException + public void testCopyConstructor() + throws IllegalArgumentException, IllegalAccessException { ViewStyle vs1 = new ViewStyle(); Field[] fields = ViewStyle.class.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); - if (!copyConstructorIgnores(field.getName())) + if (!copyConstructorIgnores(field)) { changeValue(vs1, field); } @@ -78,27 +78,39 @@ 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 + "/" - + value2 + ") - not set in copy constructor?"; - assertEquals(msg, value1, value2); + 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("Hashcode not equals", vs1.hashCode(), vs2.hashCode()); } /** - * Add any field names in here that we expect to be ignored by the copy + * 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; + } + if (field.getType().toString().contains("com_atlassian_clover")) + { + return true; + } + return false; } @@ -162,8 +174,8 @@ public class ViewStyleTest } else if (type.equals(Color.class)) { - field.set(vs, Color.RED.equals(field.get(vs)) ? Color.BLACK - : Color.RED); + field.set(vs, + Color.RED.equals(field.get(vs)) ? Color.BLACK : Color.RED); } else { @@ -196,8 +208,8 @@ public class ViewStyleTest * @throws IllegalArgumentException */ @Test(groups = { "Functional" }) - public void testEquals() throws IllegalArgumentException, - IllegalAccessException + public void testEquals() + throws IllegalArgumentException, IllegalAccessException { ViewStyle vs1 = new ViewStyle(); ViewStyle vs2 = new ViewStyle(vs1); @@ -210,19 +222,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(), - vs1.equals(vs2)); - - if (vs1.hashCode() == vs2.hashCode()) + if (!copyConstructorIgnores(field)) { - // uncomment next line to see which fields hashCode ignores - // System.out.println("hashCode ignores " + field.getName()); + 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()); + } + // restore original value before testing the next field + field.set(vs2, oldValue); } - // restore original value before testing the next field - field.set(vs2, oldValue); } } }