JAL-2106 DBRefEntry.isPrimary() minimal test & implementation
[jalview.git] / test / jalview / datamodel / DBRefEntryTest.java
index ae6dcda..8cc31e0 100644 (file)
@@ -138,4 +138,41 @@ public class DBRefEntryTest
     assertFalse(ref1.updateFrom(ref2));
     assertEquals("10", ref1.getVersion());
   }
+
+  @Test(groups = { "Functional" })
+  public void testIsPrimary()
+  {
+    DBRefEntry dbr = new DBRefEntry(DBRefSource.UNIPROT, "", "Q12345");
+    assertTrue(dbr.isPrimary());
+    /*
+     *  1:1 mapping with shift
+     */
+    dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 5, 9 }, 1,
+            1));
+    assertTrue(dbr.isPrimary());
+
+    /*
+     *  1:1 mapping with shift and sequenceRef
+     */
+    dbr.setMap(new Mapping(new Sequence("foo", "ASDF"), new int[] { 1, 3 },
+            new int[] { 5, 9 }, 1, 1));
+    assertFalse(dbr.isPrimary());
+
+    /*
+     * 1:3 mapping with shift (fail)
+     */
+    dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 5, 9 }, 1,
+            3));
+    assertFalse(dbr.isPrimary());
+    /*
+     * 2:2 mapping with shift (expected fail, but maybe not realistic)
+     */
+    dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 5, 9 }, 2,
+            2));
+    assertFalse(dbr.isPrimary());
+
+    dbr.setVersion(DBRefSource.EMBL + ":0");
+    assertFalse(dbr.isPrimary());
+
+  }
 }