Commit c917ab20 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

Flere tester

parent aeb7cdc5
......@@ -51,7 +51,24 @@ 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,20 +23,20 @@ public class GeoLocationsPersistenceTest {
@Test
public void testLoadLocations() {
testLoadLocations(getClass().getResourceAsStream("geoLocations.json"));
}
private void testLoadLocations(InputStream inputStream) {
try {
Collection<GeoLocations> geoLocations = persistence.loadLocations(inputStream);
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));
Collection<GeoLocations> geoLocations = persistence.loadLocations(getClass().getResourceAsStream("geoLocations.json"));
testGeoLocationsDotJson(geoLocations);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
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));
}
@Test
public void testSaveLocations() {
......@@ -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());
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment