Merge branch 'feature/JAL-3181linkOrdering' into develop
[jalview.git] / test / jalview / util / UrlLinkTest.java
index 4092cf2..c7d37b0 100644 (file)
@@ -33,6 +33,7 @@ import jalview.datamodel.Sequence;
 import jalview.gui.JvOptionPane;
 
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -271,7 +272,7 @@ public class UrlLinkTest
     UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_ID
             + DELIM + URL_SUFFIX);
 
-    Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
+    Map<String, List<String>> linkset = new LinkedHashMap<>();
     ul.createLinksFromSeq(null, linkset);
 
     String key = DB + SEP + URL_PREFIX;
@@ -291,7 +292,7 @@ public class UrlLinkTest
   {
     UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + URL_SUFFIX);
 
-    Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
+    Map<String, List<String>> linkset = new LinkedHashMap<>();
     ul.createLinksFromSeq(null, linkset);
 
     String key = DB + SEP + URL_PREFIX + URL_SUFFIX;
@@ -311,8 +312,8 @@ public class UrlLinkTest
   {
 
     // create list of links and list of DBRefs
-    List<String> links = new ArrayList<String>();
-    List<DBRefEntry> refs = new ArrayList<DBRefEntry>();
+    List<String> links = new ArrayList<>();
+    List<DBRefEntry> refs = new ArrayList<>();
 
     // links as might be added into Preferences | Connections dialog
     links.add("EMBL-EBI Search | http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$"
@@ -341,7 +342,7 @@ public class UrlLinkTest
     UrlLink ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + SEQUENCE_ID
             + DELIM + URL_SUFFIX);
 
-    Map<String, List<String>> linkset = new LinkedHashMap<String, List<String>>();
+    Map<String, List<String>> linkset = new LinkedHashMap<>();
     ul.createLinksFromSeq(seq0, linkset);
 
     String key = seq0.getName() + SEP + URL_PREFIX + seq0.getName()
@@ -356,7 +357,7 @@ public class UrlLinkTest
 
     // Test where link takes a db annotation id and only has one dbref
     ul = new UrlLink(links.get(1));
-    linkset = new LinkedHashMap<String, List<String>>();
+    linkset = new LinkedHashMap<>();
     ul.createLinksFromSeq(seq0, linkset);
 
     key = "P83527|http://www.uniprot.org/uniprot/P83527";
@@ -371,7 +372,7 @@ public class UrlLinkTest
 
     // Test where link takes a db annotation id and has multiple dbrefs
     ul = new UrlLink(links.get(2));
-    linkset = new LinkedHashMap<String, List<String>>();
+    linkset = new LinkedHashMap<>();
     ul.createLinksFromSeq(seq0, linkset);
     assertEquals(3, linkset.size());
 
@@ -403,7 +404,7 @@ public class UrlLinkTest
     // Test where there are no matching dbrefs for the link
     ul = new UrlLink(DB + SEP + URL_PREFIX + DELIM + DB_ACCESSION + DELIM
             + URL_SUFFIX);
-    linkset = new LinkedHashMap<String, List<String>>();
+    linkset = new LinkedHashMap<>();
     ul.createLinksFromSeq(seq0, linkset);
     assertTrue(linkset.isEmpty());
   }
@@ -439,4 +440,25 @@ public class UrlLinkTest
 
   }
 
+  @Test(groups = { "Functional" })
+  public void testLinkComparator()
+  {
+    Comparator<String> c = UrlLink.LINK_COMPARATOR;
+    assertEquals(0, c.compare(null, null));
+    assertEquals(0, c.compare(null, "x"));
+    assertEquals(0, c.compare("y", null));
+
+    /*
+     * SEQUENCE_ID templates should come before DB_ACCESSION templates
+     */
+    String dbRefUrl = "Cath|http://www.cathdb.info/version/v4_2_0/superfamily/$DB_ACCESSION$";
+    String seqIdUrl = "EBI|https://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$";
+    assertTrue(c.compare(seqIdUrl, dbRefUrl) < 0);
+    assertTrue(c.compare(dbRefUrl, seqIdUrl) > 0);
+
+    String interpro = "Interpro|https://www.ebi.ac.uk/interpro/entry/$DB_ACCESSION$";
+    String prosite = "ProSite|https://prosite.expasy.org/PS00197";
+    assertTrue(c.compare(interpro, prosite) < 0);
+    assertTrue(c.compare(prosite, interpro) > 0);
+  }
 }