X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fdatamodel%2FSequenceFeatureTest.java;h=2da8918a37c25742e69e133bf26d4e6b9bd97f8a;hb=5299e0d9142887a30889e8277d12039f10e5c36f;hp=82b260e8fd156c6a5187e896957fb0b4b4c8bbd6;hpb=b6e08d03ffec50725f18b77c174c94e5e49647e7;p=jalview.git diff --git a/test/jalview/datamodel/SequenceFeatureTest.java b/test/jalview/datamodel/SequenceFeatureTest.java index 82b260e..2da8918 100644 --- a/test/jalview/datamodel/SequenceFeatureTest.java +++ b/test/jalview/datamodel/SequenceFeatureTest.java @@ -1,3 +1,23 @@ +/* + * 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.datamodel; import static org.testng.AssertJUnit.assertEquals; @@ -6,10 +26,21 @@ import static org.testng.AssertJUnit.assertNull; import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; +import jalview.gui.JvOptionPane; + +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class SequenceFeatureTest { + + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + @Test(groups = { "Functional" }) public void testCopyConstructor() { @@ -92,56 +123,83 @@ public class SequenceFeatureTest assertEquals(sf1.hashCode(), sf2.hashCode()); // changing type breaks equals: + String restores = sf2.getType(); sf2.setType("Type"); assertFalse(sf1.equals(sf2)); + sf2.setType(restores); // changing description breaks equals: - sf2.setType("type"); + restores = sf2.getDescription(); sf2.setDescription("Desc"); assertFalse(sf1.equals(sf2)); + sf2.setDescription(restores); + + // changing score breaks equals: + float restoref = sf2.getScore(); + sf2.setScore(12.4f); + assertFalse(sf1.equals(sf2)); + sf2.setScore(restoref); + + // NaN doesn't match a number + restoref = sf2.getScore(); + sf2.setScore(Float.NaN); + assertFalse(sf1.equals(sf2)); + + // NaN matches NaN + sf1.setScore(Float.NaN); + assertTrue(sf1.equals(sf2)); + sf1.setScore(restoref); + sf2.setScore(restoref); // changing start position breaks equals: - sf2.setDescription("desc"); + int restorei = sf2.getBegin(); sf2.setBegin(21); assertFalse(sf1.equals(sf2)); + sf2.setBegin(restorei); // changing end position breaks equals: - sf2.setBegin(22); + restorei = sf2.getEnd(); sf2.setEnd(32); assertFalse(sf1.equals(sf2)); + sf2.setEnd(restorei); // changing feature group breaks equals: - sf2.setEnd(33); + restores = sf2.getFeatureGroup(); sf2.setFeatureGroup("Group"); assertFalse(sf1.equals(sf2)); + sf2.setFeatureGroup(restores); // changing ID breaks equals: - sf2.setFeatureGroup("group"); + restores = (String) sf2.getValue("ID"); sf2.setValue("ID", "id2"); assertFalse(sf1.equals(sf2)); + sf2.setValue("ID", restores); // changing Name breaks equals: - sf2.setValue("ID", "id"); + restores = (String) sf2.getValue("Name"); sf2.setValue("Name", "Name"); assertFalse(sf1.equals(sf2)); + sf2.setValue("Name", restores); // changing Parent breaks equals: - sf2.setValue("Name", "name"); + restores = (String) sf1.getValue("Parent"); sf1.setValue("Parent", "Parent"); assertFalse(sf1.equals(sf2)); + sf1.setValue("Parent", restores); // changing strand breaks equals: - sf1.setValue("Parent", "parent"); + restorei = sf2.getStrand(); sf2.setStrand("-"); assertFalse(sf1.equals(sf2)); + sf2.setStrand(restorei == 1 ? "+" : "-"); // changing phase breaks equals: - sf2.setStrand("+"); + restores = sf1.getPhase(); sf1.setPhase("2"); assertFalse(sf1.equals(sf2)); + sf1.setPhase(restores); // restore equality as sanity check: - sf1.setPhase("1"); assertTrue(sf1.equals(sf2)); assertTrue(sf2.equals(sf1)); assertEquals(sf1.hashCode(), sf2.hashCode()); @@ -150,4 +208,24 @@ public class SequenceFeatureTest sf1.setStatus("new"); assertTrue(sf1.equals(sf2)); } + + @Test(groups = { "Functional" }) + public void testIsContactFeature() + { + SequenceFeature sf = new SequenceFeature("type", "desc", 22, 33, 12.5f, + "group"); + assertFalse(sf.isContactFeature()); + sf.setType(""); + assertFalse(sf.isContactFeature()); + sf.setType(null); + assertFalse(sf.isContactFeature()); + sf.setType("Disulfide Bond"); + assertTrue(sf.isContactFeature()); + sf.setType("disulfide bond"); + assertTrue(sf.isContactFeature()); + sf.setType("Disulphide Bond"); + assertTrue(sf.isContactFeature()); + sf.setType("disulphide bond"); + assertTrue(sf.isContactFeature()); + } }