From: BobHanson Date: Tue, 9 Jun 2020 06:24:40 +0000 (-0500) Subject: JAL-3446 from JAL-3253-applet SequenceFetcher.getInstance() X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f7a9bd13163fdc193b070ce7576ead8d3d584e17;p=jalview.git JAL-3446 from JAL-3253-applet SequenceFetcher.getInstance() --- diff --git a/src/jalview/analysis/CrossRef.java b/src/jalview/analysis/CrossRef.java index c54357e..b70e9f7 100644 --- a/src/jalview/analysis/CrossRef.java +++ b/src/jalview/analysis/CrossRef.java @@ -31,6 +31,7 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.util.DBRefUtils; import jalview.util.MapList; +import jalview.ws.SequenceFetcher; import jalview.ws.SequenceFetcherFactory; import jalview.ws.seqfetcher.ASequenceFetcher; @@ -402,7 +403,6 @@ public class CrossRef private void retrieveCrossRef(List sourceRefs, SequenceI seq, List xrfs, boolean fromDna, AlignedCodonFrame cf) { - ASequenceFetcher sftch = SequenceFetcherFactory.getSequenceFetcher(); SequenceI[] retrieved = null; SequenceI dss = seq.getDatasetSequence() == null ? seq : seq.getDatasetSequence(); @@ -418,7 +418,7 @@ public class CrossRef } try { - retrieved = sftch.getSequences(sourceRefs, !fromDna); + retrieved = SequenceFetcher.getInstance().getSequences(sourceRefs, !fromDna); } catch (Exception e) { System.err.println( diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java index a480176..5c94faf 100644 --- a/src/jalview/ws/SequenceFetcher.java +++ b/src/jalview/ws/SequenceFetcher.java @@ -20,6 +20,8 @@ */ package jalview.ws; +import jalview.bin.ApplicationSingletonProvider; +import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; import jalview.ext.ensembl.EnsemblGene; import jalview.ws.dbsources.EmblCdsSource; import jalview.ws.dbsources.EmblSource; @@ -39,8 +41,39 @@ import java.util.List; * This implements the run-time discovery of sequence database clients. * */ -public class SequenceFetcher extends ASequenceFetcher +public class SequenceFetcher extends ASequenceFetcher implements ApplicationSingletonI { + /* + * set a mock fetcher here for testing only - reset to null afterwards + */ + private static SequenceFetcher mockFetcher; + + /** + * Set the instance object to use (intended for unit testing with mock + * objects). + * + * Be sure to reset to null in the tearDown method of any tests! + * + * @param sf + */ + public static void setMockFetcher(SequenceFetcher sf) + { + mockFetcher = sf; + } + + /** + * Returns a new SequenceFetcher singleton, or a mock object if one has been + * set. + * + * @return + */ + public static SequenceFetcher getInstance() + { + return mockFetcher != null ? mockFetcher + : (SequenceFetcher) ApplicationSingletonProvider + .getInstance(SequenceFetcher.class); + } + /** * Thread safe construction of database proxies TODO: extend to a configurable * database plugin mechanism where classes are instantiated by reflection and diff --git a/src/jalview/ws/SequenceFetcherFactory.java b/src/jalview/ws/SequenceFetcherFactory.java index 9cc4960..25144fc 100644 --- a/src/jalview/ws/SequenceFetcherFactory.java +++ b/src/jalview/ws/SequenceFetcherFactory.java @@ -24,29 +24,33 @@ import jalview.ws.seqfetcher.ASequenceFetcher; public class SequenceFetcherFactory { - - private static SequenceFetcher instance; - - /** - * Returns a new SequenceFetcher object, or a mock object if one has been set - * - * @return - */ - public static ASequenceFetcher getSequenceFetcher() - { - return instance == null ? new SequenceFetcher() : instance; - } - - /** - * Set the instance object to use (intended for unit testing with mock - * objects). - * - * Be sure to reset to null in the tearDown method of any tests! - * - * @param sf - */ - public static void setSequenceFetcher(SequenceFetcher sf) - { - instance = sf; - } + // BH the two methods in this class merged into SequenceFetcher } +//public class SequenceFetcherFactory +//{ +// +// private static SequenceFetcher instance; +// +// /** +// * Returns a new SequenceFetcher object, or a mock object if one has been set +// * +// * @return +// */ +// public static ASequenceFetcher getSequenceFetcher() +// { +// return instance == null ? new SequenceFetcher() : instance; +// } +// +// /** +// * Set the instance object to use (intended for unit testing with mock +// * objects). +// * +// * Be sure to reset to null in the tearDown method of any tests! +// * +// * @param sf +// */ +// public static void setSequenceFetcher(SequenceFetcher sf) +// { +// instance = sf; +// } +//} diff --git a/test/jalview/analysis/CrossRefTest.java b/test/jalview/analysis/CrossRefTest.java index 2ca112f..0123551 100644 --- a/test/jalview/analysis/CrossRefTest.java +++ b/test/jalview/analysis/CrossRefTest.java @@ -443,7 +443,7 @@ public class CrossRefTest return new SequenceI[] { pep1, pep2 }; } }; - SequenceFetcherFactory.setSequenceFetcher(mockFetcher); + SequenceFetcher.setMockFetcher(mockFetcher); /* * find UNIPROT xrefs for nucleotide sequence @@ -459,7 +459,7 @@ public class CrossRefTest @AfterClass(alwaysRun = true) public void tearDown() { - SequenceFetcherFactory.setSequenceFetcher(null); + SequenceFetcher.setMockFetcher(null); } /** @@ -521,7 +521,7 @@ public class CrossRefTest return new SequenceI[] { pep1, pep2 }; } }; - SequenceFetcherFactory.setSequenceFetcher(mockFetcher); + SequenceFetcher.setMockFetcher(mockFetcher); /* * find UNIPROT xrefs for gene and transcripts @@ -681,7 +681,7 @@ public class CrossRefTest } } }; - SequenceFetcherFactory.setSequenceFetcher(mockFetcher); + SequenceFetcher.setMockFetcher(mockFetcher); /* * find EMBL xrefs for Uniprot seqs and verify that