Permalink
Browse files

Decoupled unit tests from Swing so they can be run in headless CI sys…

…tems.
  • Loading branch information...
1 parent 2207b82 commit b4a989bf5a751ef00f140c1d1aad06b68d775ebc @kayahr committed May 19, 2012
@@ -11,6 +11,7 @@
import de.ailis.oneinstance.OneInstance;
import de.ailis.oneinstance.OneInstanceListener;
+import de.ailis.xadrian.data.Game;
import de.ailis.xadrian.data.factories.GameFactory;
import de.ailis.xadrian.dialogs.AboutDialog;
import de.ailis.xadrian.dialogs.ChangeQuantityDialog;
@@ -87,13 +88,19 @@ public void run()
SplashFrame.open();
// Preload everything
- GameFactory.getInstance().getGames();
+ for (Game game: GameFactory.getInstance().getGames())
+ {
+ game.getAddFactoryDialog();
+ game.getChangePricesDialog();
+ game.getChangeSunsDialog();
+ game.getSelectSectorDialog();
+ }
AboutDialog.getInstance();
OpenComplexDialog.getInstance();
SaveComplexDialog.getInstance();
ChangeQuantityDialog.getInstance();
PreferencesDialog.getInstance();
- SelectGameDialog.getInstance();
+ SelectGameDialog.getInstance();
// Close the splash screen
SplashFrame.close();
@@ -60,16 +60,16 @@
private final WareFactory wareFactory;
/** The add factory dialog. */
- private final AddFactoryDialog addFactoryDialog;
+ private AddFactoryDialog addFactoryDialog;
/** The select sector dialog. */
- private final SelectSectorDialog selectSectorDialog;
+ private SelectSectorDialog selectSectorDialog;
/** The change suns dialog. */
- private final ChangeSunsDialog changeSunsDialog;
+ private ChangeSunsDialog changeSunsDialog;
/** The change prices dialog. */
- private final ChangePricesDialog changePricesDialog;
+ private ChangePricesDialog changePricesDialog;
/**
* Constructor.
@@ -90,11 +90,6 @@ public Game(final int nid, final String id)
this.sectorFactory = new SectorFactory(this);
this.stationFactory = new StationFactory(this);
this.factoryFactory = new FactoryFactory(this);
-
- this.addFactoryDialog = new AddFactoryDialog(this);
- this.selectSectorDialog = new SelectSectorDialog(this);
- this.changeSunsDialog = new ChangeSunsDialog(this);
- this.changePricesDialog = new ChangePricesDialog(this);
}
/**
@@ -232,8 +227,10 @@ public WareFactory getWareFactory()
*
* @return The add factory dialog.
*/
- public AddFactoryDialog getAddFactoryDialog()
+ public synchronized AddFactoryDialog getAddFactoryDialog()
{
+ if (this.addFactoryDialog == null)
+ this.addFactoryDialog = new AddFactoryDialog(this);
return this.addFactoryDialog;
}
@@ -242,8 +239,10 @@ public AddFactoryDialog getAddFactoryDialog()
*
* @return The select sector dialog.
*/
- public SelectSectorDialog getSelectSectorDialog()
+ public synchronized SelectSectorDialog getSelectSectorDialog()
{
+ if (this.selectSectorDialog == null)
+ this.selectSectorDialog = new SelectSectorDialog(this);
return this.selectSectorDialog;
}
@@ -252,8 +251,10 @@ public SelectSectorDialog getSelectSectorDialog()
*
* @return The change suns dialog.
*/
- public ChangeSunsDialog getChangeSunsDialog()
+ public synchronized ChangeSunsDialog getChangeSunsDialog()
{
+ if (this.changeSunsDialog == null)
+ this.changeSunsDialog = new ChangeSunsDialog(this);
return this.changeSunsDialog;
}
@@ -262,8 +263,10 @@ public ChangeSunsDialog getChangeSunsDialog()
*
* @return The change prices dialog.
*/
- public ChangePricesDialog getChangePricesDialog()
+ public synchronized ChangePricesDialog getChangePricesDialog()
{
+ if (this.changePricesDialog == null)
+ this.changePricesDialog = new ChangePricesDialog(this);
return this.changePricesDialog;
}
@@ -71,7 +71,7 @@ public FactoryFactory(final Game game)
{
this.game = game;
readData();
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -76,7 +76,7 @@ private void readData()
{
final Document document = reader.read(url);
List<Object> games = document.getRootElement().elements("game");
- SplashFrame.getInstance().setNumberOfGames(games.size());
+ SplashFrame.setNumberOfGames(games.size());
for (final Object item : games)
{
final Element element = (Element) item;
@@ -55,7 +55,7 @@ public RaceFactory(final Game game)
{
this.game = game;
readData();
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -78,7 +78,7 @@ public SectorFactory(final Game game)
throw new IllegalArgumentException("game must be set");
this.game = game;
readData();
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -37,7 +37,7 @@
public StationFactory(final Game game)
{
this.game = game;
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -55,7 +55,7 @@ public SunFactory(final Game game)
{
this.game = game;
readData();
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -53,7 +53,7 @@ public WareFactory(final Game game)
{
this.game = game;
readData();
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -44,7 +44,7 @@
private AboutDialog()
{
init("about", Result.OK);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -82,7 +82,7 @@ public AddFactoryDialog(final Game game)
{
this.game = game;
init("addFactory", Result.OK, Result.CANCEL);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -82,7 +82,7 @@ public ChangePricesDialog(final Game game)
throw new IllegalArgumentException("game must be set");
this.game = game;
init("changePrices", Result.OK, Result.CANCEL);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -42,7 +42,7 @@
private ChangeQuantityDialog()
{
init("changeQuantity", Result.OK, Result.CANCEL);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -49,7 +49,7 @@ public ChangeSunsDialog(final Game game)
if (game == null) throw new IllegalArgumentException("game must be set");
this.game = game;
init("changeSuns", Result.OK, Result.CANCEL);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -36,7 +36,7 @@ private OpenComplexDialog()
.getString("dialog.openComplex.filter"), "x3c"));
setMultiSelectionEnabled(false);
setFileSelectionMode(FILES_ONLY);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -84,7 +84,7 @@
private PreferencesDialog()
{
init("preferences", Result.OK, Result.CANCEL);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -36,7 +36,7 @@ private SaveComplexDialog()
.getString("dialog.saveComplex.filter"), "x3c"));
setMultiSelectionEnabled(false);
setFileSelectionMode(FILES_ONLY);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -48,7 +48,7 @@
private SelectGameDialog()
{
init("selectGame", Result.OK, Result.CANCEL);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -63,7 +63,7 @@ public SelectSectorDialog(final Game game)
throw new IllegalArgumentException("game must be set");
this.game = game;
init("selectSector", Result.OK, Result.CANCEL);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
@@ -35,7 +35,7 @@
private static final long serialVersionUID = -1;
/** The singleton instance. */
- private static final SplashFrame instance = new SplashFrame();
+ private static SplashFrame instance;
/** The progress bar. */
private JProgressBar progressBar;
@@ -117,6 +117,7 @@ private SplashFrame()
*/
public static SplashFrame getInstance()
{
+ if (instance == null) instance = new SplashFrame();
return instance;
}
@@ -141,22 +142,24 @@ public void setVisible(boolean visible)
* @param numberOfGames
* The number of games.
*/
- public void setNumberOfGames(int numberOfGames)
+ public static void setNumberOfGames(int numberOfGames)
{
- this.progressBar.setMaximum(numberOfGames * 10 + 6);
+ if (instance == null) return;
+ instance.progressBar.setMaximum(numberOfGames * 10 + 6);
}
/**
* Opens the splash screen.
*/
public static void open()
{
+ final SplashFrame instance = getInstance();
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
- getInstance().setVisible(true);
+ instance.setVisible(true);
}
});
}
@@ -170,7 +173,7 @@ public static void close()
{
@Override
public void run()
- {
+ {
getInstance().setVisible(false);
}
});
@@ -179,9 +182,10 @@ public void run()
/**
* Advances the progress by one step.
*/
- public void advanceProgress()
+ public static void advanceProgress()
{
- final JProgressBar progressBar = this.progressBar;
+ if (instance == null) return;
+ final JProgressBar progressBar = instance.progressBar;
SwingUtilities.invokeLater(new Runnable()
{
@Override

0 comments on commit b4a989b

Please sign in to comment.