Skip to content
Snippets Groups Projects
Commit decd6a50 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

Litt flere tester.

parent 9a6fbf56
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,11 @@ public abstract class DocumentStorageImpl<D, L> implements IDocumentStorage<L> { ...@@ -16,6 +16,11 @@ public abstract class DocumentStorageImpl<D, L> implements IDocumentStorage<L> {
this.documentLocation = documentLocation; this.documentLocation = documentLocation;
} }
protected void setDocumentAndLocation(D document, L documentLocation) {
setDocument(document);
setDocumentLocation(documentLocation);
}
protected abstract D getDocument(); protected abstract D getDocument();
protected abstract void setDocument(D document); protected abstract void setDocument(D document);
...@@ -25,13 +30,12 @@ public abstract class DocumentStorageImpl<D, L> implements IDocumentStorage<L> { ...@@ -25,13 +30,12 @@ public abstract class DocumentStorageImpl<D, L> implements IDocumentStorage<L> {
@Override @Override
public void newDocument() { public void newDocument() {
setDocument(createDocument()); setDocumentAndLocation(createDocument(), null);
} }
@Override @Override
public void openDocument(L storage) throws IOException { public void openDocument(L storage) throws IOException {
setDocument(loadDocument(storage)); setDocumentAndLocation(loadDocument(storage), storage);
setDocumentLocation(storage);
} }
@Override @Override
......
...@@ -18,11 +18,15 @@ public class AppTest { ...@@ -18,11 +18,15 @@ public class AppTest {
} }
@Test @Test
public void testLoadDocument() { public void testNewDocument() {
IDocumentStorage<File> documentStorage = app.getDocumentStorage();
documentStorage.newDocument();
Assert.assertFalse(app.getGeoLocationNames().iterator().hasNext());
Assert.assertNull(documentStorage.getDocumentLocation());
}
protected void testLoadDocument(File file) {
IDocumentStorage<File> documentStorage = app.getDocumentStorage(); IDocumentStorage<File> documentStorage = app.getDocumentStorage();
URL url = getClass().getResource("geoLocations.json");
Assert.assertEquals("Not file URL", "file", url.getProtocol());
File file = new File(url.getPath());
try { try {
documentStorage.openDocument(file); documentStorage.openDocument(file);
} catch (IOException e) { } catch (IOException e) {
...@@ -31,4 +35,27 @@ public class AppTest { ...@@ -31,4 +35,27 @@ public class AppTest {
Assert.assertEquals(file, documentStorage.getDocumentLocation()); Assert.assertEquals(file, documentStorage.getDocumentLocation());
GeoLocationsPersistenceTest.testGeoLocationsDotJson(app.getGeoLocations((String[]) null)); GeoLocationsPersistenceTest.testGeoLocationsDotJson(app.getGeoLocations((String[]) null));
} }
@Test
public void testLoadDocument() {
URL url = getClass().getResource("geoLocations.json");
Assert.assertEquals("Not file URL", "file", url.getProtocol());
File file = new File(url.getPath());
testLoadDocument(file);
}
@Test
public void testSaveDocument() {
testLoadDocument();
try {
IDocumentStorage<File> documentStorage = app.getDocumentStorage();
File tempFile = File.createTempFile("geoLocations", ".json");
tempFile.deleteOnExit();
documentStorage.setDocumentLocation(tempFile);
documentStorage.saveDocument();
testLoadDocument(tempFile);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
}
} }
...@@ -3,6 +3,7 @@ package tdt4140.gr1800.app.core; ...@@ -3,6 +3,7 @@ package tdt4140.gr1800.app.core;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
...@@ -31,6 +32,13 @@ public class GeoLocationsPersistenceTest { ...@@ -31,6 +32,13 @@ public class GeoLocationsPersistenceTest {
} }
} }
public static Collection<GeoLocations> createGeoLocationsDotJson() {
return Arrays.asList(
new GeoLocations("1", new LatLong(63, 10), new LatLong(63.1, 10.1)),
new GeoLocations("2", new LatLong(64, 11), new LatLong(64.1, 11.1))
);
}
public static void testGeoLocationsDotJson(Collection<GeoLocations> geoLocations) { public static void testGeoLocationsDotJson(Collection<GeoLocations> geoLocations) {
Assert.assertEquals(2, geoLocations.size()); Assert.assertEquals(2, geoLocations.size());
Iterator<GeoLocations> it = geoLocations.iterator(); Iterator<GeoLocations> it = geoLocations.iterator();
...@@ -40,9 +48,7 @@ public class GeoLocationsPersistenceTest { ...@@ -40,9 +48,7 @@ public class GeoLocationsPersistenceTest {
@Test @Test
public void testSaveLocations() { public void testSaveLocations() {
Collection<GeoLocations> geoLocations = new ArrayList<GeoLocations>(); Collection<GeoLocations> geoLocations = createGeoLocationsDotJson();
geoLocations.add(new GeoLocations("1", new LatLong(63, 10), new LatLong(63.1, 10.1)));
geoLocations.add(new GeoLocations("2", new LatLong(64, 11), new LatLong(64.1, 11.1)));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try { try {
persistence.saveLocations(geoLocations, outputStream); persistence.saveLocations(geoLocations, outputStream);
......
...@@ -9,6 +9,31 @@ ...@@ -9,6 +9,31 @@
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
<profiles>
<profile>
<id>gitlab-ci</id>
<activation>
<property>
<name>gitlab-ci</name>
<value>true</value>
</property>
</activation>
<!--
<properties>
<skip-ui-tests>true</skip-ui-tests>
</properties>
-->
<dependencies>
<dependency>
<groupId>org.testfx</groupId>
<artifactId>openjfx-monocle</artifactId>
<version>8u76-b04</version> <!-- jdk-9+181 for Java 9 -->
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>tdt4140-gr18nn</groupId> <groupId>tdt4140-gr18nn</groupId>
......
package tdt4140.gr18nn.app.ui; package tdt4140.gr18nn.app.ui;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.testfx.framework.junit.ApplicationTest; import org.testfx.framework.junit.ApplicationTest;
...@@ -10,6 +11,21 @@ import javafx.stage.Stage; ...@@ -10,6 +11,21 @@ import javafx.stage.Stage;
public class FxAppTest extends ApplicationTest { public class FxAppTest extends ApplicationTest {
@BeforeClass
public static void headless() {
if (Boolean.valueOf(System.getProperty("gitlab-ci", "false"))) {
System.setProperty("prism.verbose", "true"); // optional
System.setProperty("java.awt.headless", "true");
System.setProperty("testfx.robot", "glass");
System.setProperty("testfx.headless", "true");
System.setProperty("glass.platform", "Monocle");
System.setProperty("monocle.platform", "Headless");
System.setProperty("prism.order", "sw");
System.setProperty("prism.text", "t2k");
System.setProperty("testfx.setup.timeout", "2500");
}
}
@Override @Override
public void start(Stage stage) throws Exception { public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FxApp.fxml")); Parent root = FXMLLoader.load(getClass().getResource("FxApp.fxml"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment