Skip to content

Commit

Permalink
testing structure of main, refs #7
Browse files Browse the repository at this point in the history
wrapping service access in method to reduce coupling
  • Loading branch information
Idrinth committed Sep 4, 2017
1 parent 3c85787 commit 8419abb
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -98,4 +100,8 @@ public final void run() {
}

protected abstract void addList();

public EntityManager getEntityManager() {
return PersistenceProvider.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,7 +76,7 @@ public String getFullIdentifier() {

protected EntityManager getEntityManager() {
if (null == entityManager) {
entityManager = PersistenceProvider.get();
entityManager = queue.getEntityManager();
}
return entityManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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()));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
});
}
Expand Down
55 changes: 55 additions & 0 deletions src/test/java/de/idrinth/stellaris/modtools/MainAppTest.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 8419abb

Please sign in to comment.