Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…tems.
  • Loading branch information...
commit b4a989bf5a751ef00f140c1d1aad06b68d775ebc 1 parent 2207b82
@kayahr authored
Showing with 53 additions and 39 deletions.
  1. +9 −2 src/main/java/de/ailis/xadrian/Main.java
  2. +16 −13 src/main/java/de/ailis/xadrian/data/Game.java
  3. +1 −1  src/main/java/de/ailis/xadrian/data/factories/FactoryFactory.java
  4. +1 −1  src/main/java/de/ailis/xadrian/data/factories/GameFactory.java
  5. +1 −1  src/main/java/de/ailis/xadrian/data/factories/RaceFactory.java
  6. +1 −1  src/main/java/de/ailis/xadrian/data/factories/SectorFactory.java
  7. +1 −1  src/main/java/de/ailis/xadrian/data/factories/StationFactory.java
  8. +1 −1  src/main/java/de/ailis/xadrian/data/factories/SunFactory.java
  9. +1 −1  src/main/java/de/ailis/xadrian/data/factories/WareFactory.java
  10. +1 −1  src/main/java/de/ailis/xadrian/dialogs/AboutDialog.java
  11. +1 −1  src/main/java/de/ailis/xadrian/dialogs/AddFactoryDialog.java
  12. +1 −1  src/main/java/de/ailis/xadrian/dialogs/ChangePricesDialog.java
  13. +1 −1  src/main/java/de/ailis/xadrian/dialogs/ChangeQuantityDialog.java
  14. +1 −1  src/main/java/de/ailis/xadrian/dialogs/ChangeSunsDialog.java
  15. +1 −1  src/main/java/de/ailis/xadrian/dialogs/OpenComplexDialog.java
  16. +1 −1  src/main/java/de/ailis/xadrian/dialogs/PreferencesDialog.java
  17. +1 −1  src/main/java/de/ailis/xadrian/dialogs/SaveComplexDialog.java
  18. +1 −1  src/main/java/de/ailis/xadrian/dialogs/SelectGameDialog.java
  19. +1 −1  src/main/java/de/ailis/xadrian/dialogs/SelectSectorDialog.java
  20. +11 −7 src/main/java/de/ailis/xadrian/frames/SplashFrame.java
View
11 src/main/java/de/ailis/xadrian/Main.java
@@ -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();
View
29 src/main/java/de/ailis/xadrian/data/Game.java
@@ -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;
}
View
2  src/main/java/de/ailis/xadrian/data/factories/FactoryFactory.java
@@ -71,7 +71,7 @@ public FactoryFactory(final Game game)
{
this.game = game;
readData();
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
View
2  src/main/java/de/ailis/xadrian/data/factories/GameFactory.java
@@ -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;
View
2  src/main/java/de/ailis/xadrian/data/factories/RaceFactory.java
@@ -55,7 +55,7 @@ public RaceFactory(final Game game)
{
this.game = game;
readData();
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
View
2  src/main/java/de/ailis/xadrian/data/factories/SectorFactory.java
@@ -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();
}
/**
View
2  src/main/java/de/ailis/xadrian/data/factories/StationFactory.java
@@ -37,7 +37,7 @@
public StationFactory(final Game game)
{
this.game = game;
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
View
2  src/main/java/de/ailis/xadrian/data/factories/SunFactory.java
@@ -55,7 +55,7 @@ public SunFactory(final Game game)
{
this.game = game;
readData();
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
View
2  src/main/java/de/ailis/xadrian/data/factories/WareFactory.java
@@ -53,7 +53,7 @@ public WareFactory(final Game game)
{
this.game = game;
readData();
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
View
2  src/main/java/de/ailis/xadrian/dialogs/AboutDialog.java
@@ -44,7 +44,7 @@
private AboutDialog()
{
init("about", Result.OK);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
View
2  src/main/java/de/ailis/xadrian/dialogs/AddFactoryDialog.java
@@ -82,7 +82,7 @@ public AddFactoryDialog(final Game game)
{
this.game = game;
init("addFactory", Result.OK, Result.CANCEL);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
View
2  src/main/java/de/ailis/xadrian/dialogs/ChangePricesDialog.java
@@ -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();
}
/**
View
2  src/main/java/de/ailis/xadrian/dialogs/ChangeQuantityDialog.java
@@ -42,7 +42,7 @@
private ChangeQuantityDialog()
{
init("changeQuantity", Result.OK, Result.CANCEL);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
View
2  src/main/java/de/ailis/xadrian/dialogs/ChangeSunsDialog.java
@@ -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();
}
/**
View
2  src/main/java/de/ailis/xadrian/dialogs/OpenComplexDialog.java
@@ -36,7 +36,7 @@ private OpenComplexDialog()
.getString("dialog.openComplex.filter"), "x3c"));
setMultiSelectionEnabled(false);
setFileSelectionMode(FILES_ONLY);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
View
2  src/main/java/de/ailis/xadrian/dialogs/PreferencesDialog.java
@@ -84,7 +84,7 @@
private PreferencesDialog()
{
init("preferences", Result.OK, Result.CANCEL);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
View
2  src/main/java/de/ailis/xadrian/dialogs/SaveComplexDialog.java
@@ -36,7 +36,7 @@ private SaveComplexDialog()
.getString("dialog.saveComplex.filter"), "x3c"));
setMultiSelectionEnabled(false);
setFileSelectionMode(FILES_ONLY);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
View
2  src/main/java/de/ailis/xadrian/dialogs/SelectGameDialog.java
@@ -48,7 +48,7 @@
private SelectGameDialog()
{
init("selectGame", Result.OK, Result.CANCEL);
- SplashFrame.getInstance().advanceProgress();
+ SplashFrame.advanceProgress();
}
/**
View
2  src/main/java/de/ailis/xadrian/dialogs/SelectSectorDialog.java
@@ -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();
}
/**
View
18 src/main/java/de/ailis/xadrian/frames/SplashFrame.java
@@ -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,9 +142,10 @@ 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);
}
/**
@@ -151,12 +153,13 @@ public void setNumberOfGames(int numberOfGames)
*/
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
Please sign in to comment.
Something went wrong with that request. Please try again.