JAL-3332 test to check for duplicate db sources and patch to code. crept in after...
authorJim Procter <jprocter@issues.jalview.org>
Wed, 26 Jun 2019 16:36:58 +0000 (17:36 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Wed, 26 Jun 2019 16:37:39 +0000 (17:37 +0100)
src/jalview/ws/SequenceFetcher.java
test/jalview/ws/SequenceFetcherTest.java

index a28be2c..d3aeead 100644 (file)
@@ -97,8 +97,8 @@ public class SequenceFetcher extends ASequenceFetcher
     int i = 0;
     for (int j = sorted.length - 1; j >= 0; j--, i++)
     {
-      srcs[i] = sorted[j];
+      tosort[i] = sorted[j];
     }
-    return srcs;
+    return tosort;
   }
 }
index 0b501ee..70c6266 100644 (file)
@@ -30,10 +30,14 @@ import jalview.ws.seqfetcher.ASequenceFetcher;
 import jalview.ws.seqfetcher.DbSourceProxy;
 
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Vector;
 
+import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
 
 public class SequenceFetcherTest
 {
@@ -45,6 +49,30 @@ public class SequenceFetcherTest
     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
   }
 
+  @Test(groups = "Functional")
+  public void testNoDuplicatesInFetchDbRefs()
+  {
+    Map<String, List<DbSourceProxy>> seen = new HashMap<>();
+    jalview.ws.SequenceFetcher sfetcher = new jalview.ws.SequenceFetcher();
+    String dupes = "";
+    for (String src : sfetcher.getOrderedSupportedSources())
+    {
+      List<DbSourceProxy> seenitem = seen.get(src);
+      if (seenitem != null)
+      {
+        dupes += (dupes.length() > 0 ? "," : "") + src;
+      }
+      else
+      {
+        seen.put(src, sfetcher.getSourceProxy(src));
+      }
+    }
+    if (dupes.length() > 0)
+    {
+      Assert.fail("Duplicate sources : " + dupes);
+    }
+  }
+
   /**
    * simple run method to test dbsources.
    *