2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertNull;
26 import static org.testng.AssertJUnit.assertSame;
27 import static org.testng.AssertJUnit.assertTrue;
29 import org.testng.annotations.Test;
31 public class SequenceFeatureTest
33 @Test(groups = { "Functional" })
34 public void testCopyConstructor()
36 SequenceFeature sf1 = new SequenceFeature("type", "desc", 22, 33,
38 sf1.setValue("STRAND", "+");
39 sf1.setValue("Note", "Testing");
40 Integer count = new Integer(7);
41 sf1.setValue("Count", count);
43 SequenceFeature sf2 = new SequenceFeature(sf1);
44 assertEquals("type", sf2.getType());
45 assertEquals("desc", sf2.getDescription());
46 assertEquals(22, sf2.getBegin());
47 assertEquals(33, sf2.getEnd());
48 assertEquals("+", sf2.getValue("STRAND"));
49 assertEquals("Testing", sf2.getValue("Note"));
50 // shallow clone of otherDetails map - contains the same object values!
51 assertSame(count, sf2.getValue("Count"));
55 * Tests for retrieving a 'miscellaneous details' property value, with or
56 * without a supplied default
58 @Test(groups = { "Functional" })
59 public void testGetValue()
61 SequenceFeature sf1 = new SequenceFeature("type", "desc", 22, 33,
63 sf1.setValue("STRAND", "+");
64 assertEquals("+", sf1.getValue("STRAND"));
65 assertNull(sf1.getValue("strand")); // case-sensitive
66 assertEquals(".", sf1.getValue("unknown", "."));
67 Integer i = new Integer(27);
68 assertSame(i, sf1.getValue("Unknown", i));
72 * Tests the method that returns 1 / -1 / 0 for strand "+" / "-" / other
74 @Test(groups = { "Functional" })
75 public void testGetStrand()
77 SequenceFeature sf = new SequenceFeature("type", "desc", 22, 33, 12.5f,
79 assertEquals(0, sf.getStrand());
80 sf.setValue("STRAND", "+");
81 assertEquals(1, sf.getStrand());
82 sf.setValue("STRAND", "-");
83 assertEquals(-1, sf.getStrand());
84 sf.setValue("STRAND", ".");
85 assertEquals(0, sf.getStrand());
89 * Tests for equality, and that equal objects have the same hashCode
91 @Test(groups = { "Functional" })
92 public void testEqualsAndHashCode()
94 SequenceFeature sf1 = new SequenceFeature("type", "desc", 22, 33,
96 sf1.setValue("ID", "id");
97 sf1.setValue("Name", "name");
98 sf1.setValue("Parent", "parent");
101 SequenceFeature sf2 = new SequenceFeature("type", "desc", 22, 33,
103 sf2.setValue("ID", "id");
104 sf2.setValue("Name", "name");
105 sf2.setValue("Parent", "parent");
109 assertFalse(sf1.equals(null));
110 assertTrue(sf1.equals(sf2));
111 assertTrue(sf2.equals(sf1));
112 assertEquals(sf1.hashCode(), sf2.hashCode());
114 // changing type breaks equals:
116 assertFalse(sf1.equals(sf2));
118 // changing description breaks equals:
120 sf2.setDescription("Desc");
121 assertFalse(sf1.equals(sf2));
123 // changing start position breaks equals:
124 sf2.setDescription("desc");
126 assertFalse(sf1.equals(sf2));
128 // changing end position breaks equals:
131 assertFalse(sf1.equals(sf2));
133 // changing feature group breaks equals:
135 sf2.setFeatureGroup("Group");
136 assertFalse(sf1.equals(sf2));
138 // changing ID breaks equals:
139 sf2.setFeatureGroup("group");
140 sf2.setValue("ID", "id2");
141 assertFalse(sf1.equals(sf2));
143 // changing Name breaks equals:
144 sf2.setValue("ID", "id");
145 sf2.setValue("Name", "Name");
146 assertFalse(sf1.equals(sf2));
148 // changing Parent breaks equals:
149 sf2.setValue("Name", "name");
150 sf1.setValue("Parent", "Parent");
151 assertFalse(sf1.equals(sf2));
153 // changing strand breaks equals:
154 sf1.setValue("Parent", "parent");
156 assertFalse(sf1.equals(sf2));
158 // changing phase breaks equals:
161 assertFalse(sf1.equals(sf2));
163 // restore equality as sanity check:
165 assertTrue(sf1.equals(sf2));
166 assertTrue(sf2.equals(sf1));
167 assertEquals(sf1.hashCode(), sf2.hashCode());
169 // changing status doesn't change equals:
170 sf1.setStatus("new");
171 assertTrue(sf1.equals(sf2));