X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fviewmodel%2Fstyles%2FViewStyleTest.java;h=3019afa0526963f1a79d64b2065541862cca2b56;hb=8d46b6025f358a2642fb5996be91a75885f8fc88;hp=9a0820fac8ebeea81d7238810400cdd7704b51d7;hpb=882adcab8cf6f9c72a7e946223f817878c5ee444;p=jalview.git diff --git a/test/jalview/viewmodel/styles/ViewStyleTest.java b/test/jalview/viewmodel/styles/ViewStyleTest.java index 9a0820f..3019afa 100644 --- a/test/jalview/viewmodel/styles/ViewStyleTest.java +++ b/test/jalview/viewmodel/styles/ViewStyleTest.java @@ -1,20 +1,49 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.viewmodel.styles; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertTrue; + +import jalview.gui.JvOptionPane; import java.awt.Color; import java.lang.reflect.Field; import java.util.Random; -import org.junit.Assert; -import org.junit.Test; - +import org.testng.AssertJUnit; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; public class ViewStyleTest { + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + Random r = new Random(); /** @@ -30,27 +59,59 @@ public class ViewStyleTest * @throws IllegalAccessException * @throws IllegalArgumentException */ - @Test - public void testCopyConstructor() throws IllegalArgumentException, - IllegalAccessException + @Test(groups = { "Functional" }) + public void testCopyConstructor() + throws IllegalArgumentException, IllegalAccessException { ViewStyle vs1 = new ViewStyle(); Field[] fields = ViewStyle.class.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); - changeValue(vs1, field); + if (!copyConstructorIgnores(field)) + { + changeValue(vs1, field); + } } ViewStyle vs2 = new ViewStyle(vs1); - 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); + for (Field field1 : fields) + { + 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 tests here for any fields that we expect to be ignored by the copy + * constructor + * + * @param field + * @return + */ + private boolean copyConstructorIgnores(Field field) + { + /* + * 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; } /** @@ -64,7 +125,6 @@ public class ViewStyleTest throws IllegalAccessException { Class type = field.getType(); - final int numValue = 1 + r.nextInt(100); if (type.equals(boolean.class) || type.equals(Boolean.class)) { @@ -114,13 +174,13 @@ 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 { - Assert.fail("Unhandled field type (add to test): " + field.getName() - + ":" + type); + AssertJUnit.fail("Unhandled field type (add to test): " + + field.getName() + ":" + type); } } @@ -147,9 +207,9 @@ public class ViewStyleTest * @throws IllegalAccessException * @throws IllegalArgumentException */ - @Test - public void testEquals() throws IllegalArgumentException, - IllegalAccessException + @Test(groups = { "Functional" }) + public void testEquals() + throws IllegalArgumentException, IllegalAccessException { ViewStyle vs1 = new ViewStyle(); ViewStyle vs2 = new ViewStyle(vs1); @@ -162,13 +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)); - // restore original value before testing the next field - field.set(vs2, oldValue); + 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()); + } + // restore original value before testing the next field + field.set(vs2, oldValue); + } } } }