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

Flere tester

parent aeb7cdc5
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,23 @@ public class App {
return null;
}
public Collection<GeoLocations> getGeoLocations(String... names) {
Collection<GeoLocations> result = new ArrayList<GeoLocations>();
if (geoLocations != null) {
if (names != null) {
for (String name : names) {
GeoLocations gl = getGeoLocations(name);
if (gl != null) {
result.add(gl);
}
}
} else {
result.addAll(geoLocations);
}
}
return result;
}
//
private DocumentStorageImpl<Collection<GeoLocations>, File> documentStorage = new DocumentStorageImpl<Collection<GeoLocations>, File>() {
......
package tdt4140.gr1800.app.core;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class AppTest {
private App app;
@Before
public void setUp() {
app = new App();
}
@Test
public void testLoadDocument() {
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 {
documentStorage.openDocument(file);
} catch (IOException e) {
Assert.fail("Couldn't open " + file);
}
Assert.assertEquals(file, documentStorage.getDocumentLocation());
GeoLocationsPersistenceTest.testGeoLocationsDotJson(app.getGeoLocations((String[]) null));
}
}
......@@ -2,7 +2,6 @@ package tdt4140.gr1800.app.core;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
......@@ -24,19 +23,19 @@ public class GeoLocationsPersistenceTest {
@Test
public void testLoadLocations() {
testLoadLocations(getClass().getResourceAsStream("geoLocations.json"));
try {
Collection<GeoLocations> geoLocations = persistence.loadLocations(getClass().getResourceAsStream("geoLocations.json"));
testGeoLocationsDotJson(geoLocations);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
private void testLoadLocations(InputStream inputStream) {
try {
Collection<GeoLocations> geoLocations = persistence.loadLocations(inputStream);
public static void testGeoLocationsDotJson(Collection<GeoLocations> geoLocations) {
Assert.assertEquals(2, geoLocations.size());
Iterator<GeoLocations> it = geoLocations.iterator();
GeoLocationsTest.assertGeoLocations(it.next(), new LatLong(63, 10), new LatLong(63.1, 10.1));
GeoLocationsTest.assertGeoLocations(it.next(), new LatLong(64, 11), new LatLong(64.1, 11.1));
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
@Test
......@@ -48,7 +47,8 @@ public class GeoLocationsPersistenceTest {
try {
persistence.saveLocations(geoLocations, outputStream);
outputStream.close();
testLoadLocations(new ByteArrayInputStream(outputStream.toByteArray()));
Collection<GeoLocations> geoLocations2 = persistence.loadLocations(new ByteArrayInputStream(outputStream.toByteArray()));
testGeoLocationsDotJson(geoLocations2);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment