Clover icon

Coverage Report

  1. Project Clover database Tue Mar 10 2026 14:58:44 GMT
  2. Package jalview.datamodel

File DBRefEntryTest.java

 

Code metrics

0
87
4
1
253
135
4
0.05
21.75
4
1

Classes

Class Line # Actions
DBRefEntryTest 34 87 4
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.datamodel;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertFalse;
25    import static org.testng.AssertJUnit.assertSame;
26    import static org.testng.AssertJUnit.assertTrue;
27   
28    import jalview.gui.JvOptionPane;
29    import jalview.util.MapList;
30   
31    import org.testng.annotations.BeforeClass;
32    import org.testng.annotations.Test;
33   
 
34    public class DBRefEntryTest
35    {
36   
 
37  0 toggle @BeforeClass(alwaysRun = true)
38    public void setUpJvOptionPane()
39    {
40  0 JvOptionPane.setInteractiveMode(false);
41  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
42    }
43   
44    /**
45    * Tests for the method that compares equality of reference (but not mapping)
46    */
 
47  0 toggle @Test(groups = { "Functional" })
48    public void testEqualRef()
49    {
50  0 DBRefEntry ref1 = new DBRefEntry("UNIPROT", "1", "V71633");
51  0 assertTrue(ref1.equalRef(ref1));
52  0 assertFalse(ref1.equalRef(null));
53   
54    // comparison is not case sensitive
55  0 DBRefEntry ref2 = new DBRefEntry("uniprot", "1", "v71633");
56  0 assertTrue(ref1.equalRef(ref2));
57  0 assertTrue(ref2.equalRef(ref1));
58   
59    // source, version and accessionid must match
60  0 assertFalse(ref1.equalRef(new DBRefEntry("UNIPRO", "1", "V71633")));
61  0 assertFalse(ref1.equalRef(new DBRefEntry("UNIPROT", "2", "V71633")));
62  0 assertFalse(ref1.equalRef(new DBRefEntry("UNIPROT", "1", "V71632")));
63   
64    // presence of or differences in mappings are ignored
65  0 ref1.setMap(
66    new Mapping(new MapList(new int[]
67    { 1, 3 }, new int[] { 1, 1 }, 3, 1)));
68  0 assertTrue(ref1.equalRef(ref2));
69  0 assertTrue(ref2.equalRef(ref1));
70  0 ref1.setMap(
71    new Mapping(new MapList(new int[]
72    { 1, 6 }, new int[] { 1, 2 }, 3, 1)));
73  0 assertTrue(ref1.equalRef(ref2));
74  0 assertTrue(ref2.equalRef(ref1));
75    }
76   
77    /**
78    * Tests for the method that may update a DBRefEntry from another with a
79    * mapping or 'real' version
80    */
 
81  0 toggle @Test(groups = { "Functional" })
82    public void testUpdateFrom()
83    {
84  0 DBRefEntry ref1 = new DBRefEntry("UNIPROT", "1", "V71633");
85   
86  0 assertFalse(ref1.updateFrom(null));
87   
88    /*
89    * equivalent other dbref
90    */
91  0 DBRefEntry ref2 = new DBRefEntry("uniprot", "1", "v71633");
92  0 assertTrue(ref1.updateFrom(ref2));
93  0 assertEquals("UNIPROT", ref1.getSource()); // unchanged
94  0 assertEquals("V71633", ref1.getAccessionId()); // unchanged
95   
96    /*
97    * ref1 has no mapping, acquires mapping from ref2
98    */
99  0 Mapping map = new Mapping(
100    new MapList(new int[]
101    { 1, 3 }, new int[] { 1, 1 }, 3, 1));
102  0 ref2.setMap(map);
103  0 assertTrue(ref1.updateFrom(ref2));
104  0 assertSame(map, ref1.getMap()); // null mapping updated
105   
106    /*
107    * ref1 has a mapping, does not acquire mapping from ref2
108    */
109  0 ref2.setMap(new Mapping(map));
110  0 assertTrue(ref1.updateFrom(ref2));
111  0 assertSame(map, ref1.getMap()); // non-null mapping not updated
112   
113    /*
114    * ref2 has a different source, accession or version
115    */
116  0 ref2.setSource("pdb");
117  0 assertFalse(ref1.updateFrom(ref2));
118  0 ref2.setSource(ref1.getSource());
119  0 ref2.setAccessionId("P12345");
120  0 assertFalse(ref1.updateFrom(ref2));
121  0 ref2.setAccessionId(ref1.getAccessionId());
122  0 ref1.setVersion("2");
123  0 assertFalse(ref1.updateFrom(ref2));
124   
125    /*
126    * a non-null version supersedes "0" or "source:0"
127    */
128  0 ref2.setVersion(null);
129  0 assertFalse(ref1.updateFrom(ref2));
130  0 assertEquals("2", ref1.getVersion());
131  0 ref2.setVersion("3");
132  0 ref1.setVersion("0");
133  0 assertTrue(ref1.updateFrom(ref2));
134  0 assertEquals("3", ref1.getVersion());
135  0 ref1.setVersion("UNIPROT:0");
136  0 assertTrue(ref1.updateFrom(ref2));
137  0 assertEquals("3", ref1.getVersion());
138   
139    /*
140    * canonical == false superseded by canonical == true
141    */
142  0 ref1.setCanonical(false);
143  0 ref2.setCanonical(true);
144  0 assertTrue(ref1.updateFrom(ref2));
145  0 assertTrue(ref1.isCanonical());
146   
147    /*
148    * canonical == true NOT superseded by canonical == false
149    */
150  0 ref1.setCanonical(true);
151  0 ref2.setCanonical(false);
152  0 assertFalse(ref1.updateFrom(ref2));
153   
154    /*
155    * version "source:n" with n>0 is not superseded
156    */
157  0 ref1.setVersion("UNIPROT:1");
158  0 assertFalse(ref1.updateFrom(ref2));
159  0 assertEquals("UNIPROT:1", ref1.getVersion());
160   
161    /*
162    * version "10" is not superseded
163    */
164  0 ref1.setVersion("10");
165  0 assertFalse(ref1.updateFrom(ref2));
166  0 assertEquals("10", ref1.getVersion());
167    }
168   
 
169  0 toggle @Test(groups = { "Functional" })
170    public void testIsPrimaryCandidate()
171    {
172  0 DBRefEntry dbr = new DBRefEntry(DBRefSource.UNIPROT, "", "Q12345");
173  0 assertTrue(dbr.isPrimaryCandidate());
174   
175    /*
176    * 1:1 mapping - ok
177    */
178  0 dbr.setMap(
179    new Mapping(null, new int[]
180    { 1, 3 }, new int[] { 1, 3 }, 1, 1));
181  0 assertTrue(dbr.isPrimaryCandidate());
182   
183    /*
184    * 1:1 mapping of identical split ranges - not ok
185    */
186  0 dbr.setMap(
187    new Mapping(null, new int[]
188    { 1, 3, 6, 9 }, new int[] { 1, 3, 6, 9 }, 1, 1));
189  0 assertFalse(dbr.isPrimaryCandidate());
190   
191    /*
192    * 1:1 mapping of different ranges - not ok
193    */
194  0 dbr.setMap(
195    new Mapping(null, new int[]
196    { 1, 4 }, new int[] { 2, 5 }, 1, 1));
197  0 assertFalse(dbr.isPrimaryCandidate());
198   
199    /*
200    * 1:1 mapping of 'isoform' ranges - not ok
201    */
202  0 dbr.setMap(
203    new Mapping(null, new int[]
204    { 1, 2, 6, 9 }, new int[] { 1, 3, 7, 9 }, 1, 1));
205  0 assertFalse(dbr.isPrimaryCandidate());
206  0 dbr.setMap(null);
207  0 assertTrue(dbr.isPrimaryCandidate());
208   
209    /*
210    * Version string is prefixed with another dbref source string (fail)
211    */
212  0 dbr.setVersion(DBRefSource.EMBL + ":0");
213  0 assertFalse(dbr.isPrimaryCandidate());
214   
215    /*
216    * Version string is alphanumeric
217    */
218  0 dbr.setVersion("0.1.b");
219  0 assertTrue(dbr.isPrimaryCandidate());
220   
221    /*
222    * null version string can't be primary ref
223    */
224  0 dbr.setVersion(null);
225  0 assertFalse(dbr.isPrimaryCandidate());
226  0 dbr.setVersion("");
227  0 assertTrue(dbr.isPrimaryCandidate());
228   
229    /*
230    * 1:1 mapping and sequenceRef (fail)
231    */
232  0 dbr.setMap(
233    new Mapping(new Sequence("foo", "ASDF"), new int[]
234    { 1, 3 }, new int[] { 1, 3 }, 1, 1));
235  0 assertFalse(dbr.isPrimaryCandidate());
236   
237    /*
238    * 1:3 mapping (fail)
239    */
240  0 dbr.setMap(
241    new Mapping(null, new int[]
242    { 1, 3 }, new int[] { 1, 3 }, 1, 3));
243  0 assertFalse(dbr.isPrimaryCandidate());
244   
245    /*
246    * 2:2 mapping with shift (expected fail, but maybe use case for a pass)
247    */
248  0 dbr.setMap(
249    new Mapping(null, new int[]
250    { 1, 4 }, new int[] { 1, 4 }, 2, 2));
251  0 assertFalse(dbr.isPrimaryCandidate());
252    }
253    }