diff --git a/src/main/java/de/idrinth/stellaris/modtools/process/AbstractQueue.java b/src/main/java/de/idrinth/stellaris/modtools/process/AbstractQueue.java index 4e97f67..adfc404 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process/AbstractQueue.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process/AbstractQueue.java @@ -17,6 +17,7 @@ package de.idrinth.stellaris.modtools.process; import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; +import de.idrinth.stellaris.modtools.service.PersistenceProvider; import java.util.ArrayList; import java.util.ConcurrentModificationException; import java.util.List; @@ -26,6 +27,7 @@ import java.util.concurrent.Future; import java.util.logging.Level; import java.util.logging.Logger; +import javax.persistence.EntityManager; abstract public class AbstractQueue implements ProcessHandlingQueue { @@ -98,4 +100,8 @@ public final void run() { } protected abstract void addList(); + + public EntityManager getEntityManager() { + return PersistenceProvider.get(); + } } diff --git a/src/main/java/de/idrinth/stellaris/modtools/process/ProcessHandlingQueue.java b/src/main/java/de/idrinth/stellaris/modtools/process/ProcessHandlingQueue.java index 039bc0a..b7cc4c5 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process/ProcessHandlingQueue.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process/ProcessHandlingQueue.java @@ -16,7 +16,10 @@ */ package de.idrinth.stellaris.modtools.process; +import javax.persistence.EntityManager; + public interface ProcessHandlingQueue extends Runnable { void add(Task task); + EntityManager getEntityManager(); } diff --git a/src/main/java/de/idrinth/stellaris/modtools/process/Task.java b/src/main/java/de/idrinth/stellaris/modtools/process/Task.java index 7b24a6e..2c1f2a2 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process/Task.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process/Task.java @@ -17,7 +17,6 @@ package de.idrinth.stellaris.modtools.process; import de.idrinth.stellaris.modtools.entity.TaskCompletion; -import de.idrinth.stellaris.modtools.service.PersistenceProvider; import java.io.IOException; import java.util.ArrayList; import java.util.Date; @@ -77,7 +76,7 @@ public String getFullIdentifier() { protected EntityManager getEntityManager() { if (null == entityManager) { - entityManager = PersistenceProvider.get(); + entityManager = queue.getEntityManager(); } return entityManager; } diff --git a/src/main/java/de/idrinth/stellaris/modtools/process2prepatchcleaning/Queue.java b/src/main/java/de/idrinth/stellaris/modtools/process2prepatchcleaning/Queue.java index c570e25..9bf7a4a 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process2prepatchcleaning/Queue.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process2prepatchcleaning/Queue.java @@ -20,7 +20,6 @@ import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; import de.idrinth.stellaris.modtools.process.AbstractQueue; import de.idrinth.stellaris.modtools.process.FillerThread; -import de.idrinth.stellaris.modtools.service.PersistenceProvider; public class Queue extends AbstractQueue { @@ -30,7 +29,7 @@ public Queue(FillerThread c, ProgressElementGroup progress) { @Override protected void addList() { - PersistenceProvider.get().createNamedQuery("originals", Original.class).getResultList().forEach((o) -> { + getEntityManager().createNamedQuery("originals", Original.class).getResultList().forEach((o) -> { add(new RemoveOverwrittenFilePatch(o.getAid())); }); } diff --git a/src/main/java/de/idrinth/stellaris/modtools/process3filepatch/Queue.java b/src/main/java/de/idrinth/stellaris/modtools/process3filepatch/Queue.java index bb527a3..c7b39d9 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process3filepatch/Queue.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process3filepatch/Queue.java @@ -19,7 +19,6 @@ import de.idrinth.stellaris.modtools.entity.Patch; import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; import de.idrinth.stellaris.modtools.process.AbstractQueue; -import de.idrinth.stellaris.modtools.service.PersistenceProvider; import java.util.concurrent.Callable; public class Queue extends AbstractQueue { @@ -30,7 +29,7 @@ public Queue(Callable callable, ProgressElementGroup progress) { @Override protected void addList() { - PersistenceProvider.get().createNamedQuery("patch.any", Patch.class).getResultList().forEach((o) -> { + getEntityManager().createNamedQuery("patch.any", Patch.class).getResultList().forEach((o) -> { add(new GenerateFilePatch(o.getAid())); }); } diff --git a/src/main/java/de/idrinth/stellaris/modtools/process4applypatch/Queue.java b/src/main/java/de/idrinth/stellaris/modtools/process4applypatch/Queue.java index f998ea6..18c725d 100644 --- a/src/main/java/de/idrinth/stellaris/modtools/process4applypatch/Queue.java +++ b/src/main/java/de/idrinth/stellaris/modtools/process4applypatch/Queue.java @@ -19,7 +19,6 @@ import de.idrinth.stellaris.modtools.entity.Original; import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; import de.idrinth.stellaris.modtools.process.AbstractQueue; -import de.idrinth.stellaris.modtools.service.PersistenceProvider; import java.util.concurrent.Callable; public class Queue extends AbstractQueue { @@ -30,7 +29,7 @@ public Queue(Callable callable, ProgressElementGroup progress) { @Override protected void addList() { - PersistenceProvider.get().createNamedQuery("originals", Original.class).getResultList().forEach((o) -> { + getEntityManager().createNamedQuery("originals", Original.class).getResultList().forEach((o) -> { add(new PatchFile(o.getAid(), this)); }); } diff --git a/src/test/java/de/idrinth/stellaris/modtools/MainAppTest.java b/src/test/java/de/idrinth/stellaris/modtools/MainAppTest.java new file mode 100644 index 0000000..f4bb2f1 --- /dev/null +++ b/src/test/java/de/idrinth/stellaris/modtools/MainAppTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2017 Börn Büttner + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.idrinth.stellaris.modtools; + +import javafx.stage.Stage; +import junit.framework.Assert; +import org.junit.Test; + +public class MainAppTest { + + /** + * Test of start method, of class MainApp. + * @throws java.lang.NoSuchMethodException + */ + @Test + public void testStart() throws NoSuchMethodException { + System.out.println("start"); + Assert.assertNotNull("Can't find start method", MainApp.class.getMethod("start",Stage.class)); + } + + /** + * Test of stop method, of class MainApp. + * @throws java.lang.NoSuchMethodException + */ + @Test + public void testStop() throws NoSuchMethodException { + System.out.println("stop"); + Assert.assertNotNull("Can't find stop method", MainApp.class.getMethod("stop")); + } + + /** + * Test of main method, of class MainApp. + * @throws java.lang.NoSuchMethodException + */ + @Test + public void testMain() throws NoSuchMethodException { + System.out.println("main"); + Assert.assertNotNull("Can't find main method", MainApp.class.getMethod("main",String[].class)); + } + +} diff --git a/src/test/java/de/idrinth/stellaris/modtools/process/AbstractQueueTest.java b/src/test/java/de/idrinth/stellaris/modtools/process/AbstractQueueTest.java index d0ae75b..931454a 100644 --- a/src/test/java/de/idrinth/stellaris/modtools/process/AbstractQueueTest.java +++ b/src/test/java/de/idrinth/stellaris/modtools/process/AbstractQueueTest.java @@ -17,7 +17,9 @@ package de.idrinth.stellaris.modtools.process; import de.idrinth.stellaris.modtools.gui.ProgressElementGroup; +import de.idrinth.stellaris.modtools.service.PersistenceProvider; import java.util.concurrent.Callable; +import javax.persistence.EntityManager; import junit.framework.Assert; import org.junit.Test; @@ -49,6 +51,14 @@ public void testRun() { Assert.assertEquals(1, queue.increment); } + /** + * Test of getEntityManager method, of class AbstractQueue. + */ + @Test + public void testGetEntityManager() { + System.out.println("getEntityManager"); + Assert.assertTrue("getEntityManager does not return an EntityManager", EntityManager.class.isAssignableFrom(new AbstractQueueImpl().getEntityManager().getClass())); + } private class AbstractQueueImpl extends AbstractQueue { public volatile int increment=0; public AbstractQueueImpl() {