From e7e569d85f161d6f508851d861ab3e76e2b4bbf9 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 26 Jun 2019 17:36:58 +0100 Subject: [PATCH] JAL-3332 test to check for duplicate db sources and patch to code. crept in after das source removal --- src/jalview/ws/SequenceFetcher.java | 4 ++-- test/jalview/ws/SequenceFetcherTest.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java index a28be2c..d3aeead 100644 --- a/src/jalview/ws/SequenceFetcher.java +++ b/src/jalview/ws/SequenceFetcher.java @@ -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; } } diff --git a/test/jalview/ws/SequenceFetcherTest.java b/test/jalview/ws/SequenceFetcherTest.java index 0b501ee..70c6266 100644 --- a/test/jalview/ws/SequenceFetcherTest.java +++ b/test/jalview/ws/SequenceFetcherTest.java @@ -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> seen = new HashMap<>(); + jalview.ws.SequenceFetcher sfetcher = new jalview.ws.SequenceFetcher(); + String dupes = ""; + for (String src : sfetcher.getOrderedSupportedSources()) + { + List 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. * -- 1.7.10.2