Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / ws / SequenceFetcher.java
index 48aafca..35a237e 100644 (file)
@@ -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;
@@ -40,8 +42,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