JAL-3438 spotless for 2.11.2.0
[jalview.git] / test / jalview / datamodel / DBRefEntryTest.java
index 8cc31e0..476e0bb 100644 (file)
@@ -25,13 +25,22 @@ import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
 
+import jalview.gui.JvOptionPane;
 import jalview.util.MapList;
 
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
 public class DBRefEntryTest
 {
 
+  @BeforeClass(alwaysRun = true)
+  public void setUpJvOptionPane()
+  {
+    JvOptionPane.setInteractiveMode(false);
+    JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+  }
+
   /**
    * Tests for the method that compares equality of reference (but not mapping)
    */
@@ -53,12 +62,14 @@ public class DBRefEntryTest
     assertFalse(ref1.equalRef(new DBRefEntry("UNIPROT", "1", "V71632")));
 
     // presence of or differences in mappings are ignored
-    ref1.setMap(new Mapping(new MapList(new int[] { 1, 3 }, new int[] { 1,
-        1 }, 3, 1)));
+    ref1.setMap(
+            new Mapping(new MapList(new int[]
+            { 1, 3 }, new int[] { 1, 1 }, 3, 1)));
     assertTrue(ref1.equalRef(ref2));
     assertTrue(ref2.equalRef(ref1));
-    ref1.setMap(new Mapping(new MapList(new int[] { 1, 6 }, new int[] { 1,
-        2 }, 3, 1)));
+    ref1.setMap(
+            new Mapping(new MapList(new int[]
+            { 1, 6 }, new int[] { 1, 2 }, 3, 1)));
     assertTrue(ref1.equalRef(ref2));
     assertTrue(ref2.equalRef(ref1));
   }
@@ -81,12 +92,13 @@ public class DBRefEntryTest
     assertTrue(ref1.updateFrom(ref2));
     assertEquals("UNIPROT", ref1.getSource()); // unchanged
     assertEquals("V71633", ref1.getAccessionId()); // unchanged
-  
+
     /*
      * ref1 has no mapping, acquires mapping from ref2
      */
-    Mapping map = new Mapping(new MapList(new int[] { 1, 3 }, new int[] {
-        1, 1 }, 3, 1));
+    Mapping map = new Mapping(
+            new MapList(new int[]
+            { 1, 3 }, new int[] { 1, 1 }, 3, 1));
     ref2.setMap(map);
     assertTrue(ref1.updateFrom(ref2));
     assertSame(map, ref1.getMap()); // null mapping updated
@@ -125,6 +137,21 @@ public class DBRefEntryTest
     assertEquals("3", ref1.getVersion());
 
     /*
+     * canonical == false superseded by canonical == true
+     */
+    ref1.setCanonical(false);
+    ref2.setCanonical(true);
+    assertTrue(ref1.updateFrom(ref2));
+    assertTrue(ref1.isCanonical());
+
+    /*
+     * canonical == true NOT superseded by canonical == false
+     */
+    ref1.setCanonical(true);
+    ref2.setCanonical(false);
+    assertFalse(ref1.updateFrom(ref2));
+
+    /*
      * version "source:n" with n>0 is not superseded
      */
     ref1.setVersion("UNIPROT:1");
@@ -140,39 +167,87 @@ public class DBRefEntryTest
   }
 
   @Test(groups = { "Functional" })
-  public void testIsPrimary()
+  public void testIsPrimaryCandidate()
   {
     DBRefEntry dbr = new DBRefEntry(DBRefSource.UNIPROT, "", "Q12345");
-    assertTrue(dbr.isPrimary());
+    assertTrue(dbr.isPrimaryCandidate());
+
     /*
-     *  1:1 mapping with shift
+     *  1:1 mapping - ok
      */
-    dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 5, 9 }, 1,
-            1));
-    assertTrue(dbr.isPrimary());
+    dbr.setMap(
+            new Mapping(null, new int[]
+            { 1, 3 }, new int[] { 1, 3 }, 1, 1));
+    assertTrue(dbr.isPrimaryCandidate());
 
     /*
-     *  1:1 mapping with shift and sequenceRef
+     *  1:1 mapping of identical split ranges - not ok
      */
-    dbr.setMap(new Mapping(new Sequence("foo", "ASDF"), new int[] { 1, 3 },
-            new int[] { 5, 9 }, 1, 1));
-    assertFalse(dbr.isPrimary());
+    dbr.setMap(
+            new Mapping(null, new int[]
+            { 1, 3, 6, 9 }, new int[] { 1, 3, 6, 9 }, 1, 1));
+    assertFalse(dbr.isPrimaryCandidate());
 
     /*
-     * 1:3 mapping with shift (fail)
+     *  1:1 mapping of different ranges - not ok
      */
-    dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 5, 9 }, 1,
-            3));
-    assertFalse(dbr.isPrimary());
+    dbr.setMap(
+            new Mapping(null, new int[]
+            { 1, 4 }, new int[] { 2, 5 }, 1, 1));
+    assertFalse(dbr.isPrimaryCandidate());
+
     /*
-     * 2:2 mapping with shift (expected fail, but maybe not realistic)
+     *  1:1 mapping of 'isoform' ranges - not ok
      */
-    dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 5, 9 }, 2,
-            2));
-    assertFalse(dbr.isPrimary());
+    dbr.setMap(
+            new Mapping(null, new int[]
+            { 1, 2, 6, 9 }, new int[] { 1, 3, 7, 9 }, 1, 1));
+    assertFalse(dbr.isPrimaryCandidate());
+    dbr.setMap(null);
+    assertTrue(dbr.isPrimaryCandidate());
 
+    /*
+     * Version string is prefixed with another dbref source string (fail)
+     */
     dbr.setVersion(DBRefSource.EMBL + ":0");
-    assertFalse(dbr.isPrimary());
+    assertFalse(dbr.isPrimaryCandidate());
+
+    /*
+     * Version string is alphanumeric
+     */
+    dbr.setVersion("0.1.b");
+    assertTrue(dbr.isPrimaryCandidate());
 
+    /*
+     * null version string can't be primary ref
+     */
+    dbr.setVersion(null);
+    assertFalse(dbr.isPrimaryCandidate());
+    dbr.setVersion("");
+    assertTrue(dbr.isPrimaryCandidate());
+
+    /*
+     *  1:1 mapping and sequenceRef (fail)
+     */
+    dbr.setMap(
+            new Mapping(new Sequence("foo", "ASDF"), new int[]
+            { 1, 3 }, new int[] { 1, 3 }, 1, 1));
+    assertFalse(dbr.isPrimaryCandidate());
+
+    /*
+     * 1:3 mapping (fail)
+     */
+    dbr.setMap(
+            new Mapping(null, new int[]
+            { 1, 3 }, new int[] { 1, 3 }, 1, 3));
+    assertFalse(dbr.isPrimaryCandidate());
+
+    /*
+     * 2:2 mapping with shift (expected fail, but maybe use case for a pass)
+     */
+    dbr.setMap(
+            new Mapping(null, new int[]
+            { 1, 4 }, new int[] { 1, 4 }, 2, 2));
+    assertFalse(dbr.isPrimaryCandidate());
   }
 }