From 933ef8cbe299bfcbe146835d789932d66b0827ea Mon Sep 17 00:00:00 2001 From: hansonr Date: Sun, 6 Oct 2019 20:56:57 +0200 Subject: [PATCH] JAL-3453 Some tests require different Desktop constructor --- src/jalview/bin/ApplicationSingletonProvider.java | 8 ++++++-- src/jalview/gui/Desktop.java | 17 +++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/jalview/bin/ApplicationSingletonProvider.java b/src/jalview/bin/ApplicationSingletonProvider.java index eb82104..45ec8ab 100644 --- a/src/jalview/bin/ApplicationSingletonProvider.java +++ b/src/jalview/bin/ApplicationSingletonProvider.java @@ -140,11 +140,15 @@ public class ApplicationSingletonProvider * store the new singleton; note that a * null value is saved if construction failed */ - getContextMap().put(c, o); - + setInstance(c, o); return o; } + public static void setInstance(Class c, + ApplicationSingletonI o) + { + getContextMap().put(c, o); + } /** * Removes the current singleton instance of the given class from the current * application context. This has the effect of ensuring that a new instance is diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 85ec3aecf..226efdf 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -242,7 +242,7 @@ public class Desktop extends GDesktop * JInternalFrame objects when in that mode. * */ - private boolean instanceOnly; + boolean instanceOnly; class MyDesktopManager implements DesktopManager { @@ -384,17 +384,16 @@ public class Desktop extends GDesktop } /** - * For testing purposes, this constructor can be utilized to allow the creation - * of a singleton Desktop instance without the formation of frames. The Cache is - * initialized, but that is all. - * - * It is not currently used. + * For TestNG, this constructor can be utilized to allow the creation of a + * singleton Desktop instance without the formation of frames and, especially, + * not involving dialogs. Cache.log is also initialized for some tests that + * require it despite there being no Desktop. * * @param forInstance */ public Desktop(boolean forInstance) { - + ApplicationSingletonProvider.setInstance(Desktop.class, this); Cache.initLogger(); instanceOnly = true; } @@ -3317,7 +3316,9 @@ public class Desktop extends GDesktop { } } - if (instanceOnly) + System.out.println("Desktop headless or instanceonly" + instanceOnly + + " " + Jalview.isHeadlessMode()); + if (instanceOnly || Jalview.isHeadlessMode()) { return; } -- 1.7.10.2