aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/files
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/cgeo/geocaching/files')
-rw-r--r--tests/src/cgeo/geocaching/files/FileTypeDetectorTest.java52
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java22
-rw-r--r--tests/src/cgeo/geocaching/files/InvalidXMLCharacterFilterReaderTest.java1
3 files changed, 63 insertions, 12 deletions
diff --git a/tests/src/cgeo/geocaching/files/FileTypeDetectorTest.java b/tests/src/cgeo/geocaching/files/FileTypeDetectorTest.java
new file mode 100644
index 0000000..5dbf3c2
--- /dev/null
+++ b/tests/src/cgeo/geocaching/files/FileTypeDetectorTest.java
@@ -0,0 +1,52 @@
+package cgeo.geocaching.files;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
+import cgeo.geocaching.test.R;
+
+import org.eclipse.jdt.annotation.NonNull;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.net.Uri;
+
+public class FileTypeDetectorTest extends AbstractResourceInstrumentationTestCase {
+
+ private static class FileContentResolver extends ContentResolver {
+
+ public FileContentResolver(Context context) {
+ super(context);
+ }
+ }
+
+ public void testUnknown() throws Exception {
+ assertFileType(R.raw.gc2cjpf_html, FileType.UNKNOWN);
+ assertFileType(R.raw.map1, FileType.UNKNOWN);
+ }
+
+ public void testLoc() throws Exception {
+ assertFileType(R.raw.gc1bkp3_loc, FileType.LOC);
+ assertFileType(R.raw.oc5952_loc, FileType.LOC);
+ assertFileType(R.raw.waymarking_loc, FileType.LOC);
+ }
+
+ public void testGpx() throws Exception {
+ assertFileType(R.raw.gc1bkp3_gpx100, FileType.GPX);
+ assertFileType(R.raw.gc1bkp3_gpx101, FileType.GPX);
+ assertFileType(R.raw.oc5952_gpx, FileType.GPX);
+ assertFileType(R.raw.renamed_waypoints_wpts, FileType.GPX);
+ assertFileType(R.raw.waymarking_gpx, FileType.GPX);
+ }
+
+ public void testZip() throws Exception {
+ assertFileType(R.raw.pq_error, FileType.ZIP);
+ assertFileType(R.raw.pq7545915, FileType.ZIP);
+ }
+
+ private void assertFileType(final int resourceId, final @NonNull FileType fileType) {
+ final Uri resourceURI = getResourceURI(resourceId);
+ final FileContentResolver contentResolver = new FileContentResolver(getInstrumentation().getContext());
+ assertThat(new FileTypeDetector(resourceURI, contentResolver).getFileType()).isEqualTo(fileType);
+ }
+}
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index bb91243..1f97fa3 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -16,8 +16,6 @@ import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
import cgeo.geocaching.utils.SynchronizedDateFormat;
-import org.apache.commons.lang3.StringUtils;
-
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
@@ -52,9 +50,9 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertThat(cache.getSize()).isEqualTo(CacheSize.MICRO);
assertThat(cache.getDifficulty()).isEqualTo(1.0f);
assertThat(cache.getTerrain()).isEqualTo(5.0f);
- assertEquals("Baden-Württemberg, Germany", cache.getLocation());
- assertEquals("Ein alter Kindheitstraum, ein Schatz auf einer unbewohnten Insel.\nA old dream of my childhood, a treasure on a lonely island.", cache.getShortDescription());
- assertEquals(new Geopoint(48.859683, 9.1874), cache.getCoords());
+ assertThat(cache.getLocation()).isEqualTo("Baden-Württemberg, Germany");
+ assertThat(cache.getShortDescription()).isEqualTo("Ein alter Kindheitstraum, ein Schatz auf einer unbewohnten Insel.\nA old dream of my childhood, a treasure on a lonely island.");
+ assertThat(cache.getCoords()).isEqualTo(new Geopoint(48.859683, 9.1874));
return cache;
}
@@ -77,9 +75,9 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertThat(cache.getSize()).isEqualTo(CacheSize.SMALL);
assertThat(cache.getDifficulty()).isEqualTo(1.0f);
assertThat(cache.getTerrain()).isEqualTo(4.0f);
- assertEquals("Baden-Württemberg, Germany", cache.getLocation());
- assertEquals("Ein alter Kindheitstraum, ein Schatz auf einer unbewohnten Insel. A old dream of my childhood, a treasure on a lonely is", cache.getShortDescription());
- assertEquals(new Geopoint(48.85968, 9.18740), cache.getCoords());
+ assertThat(cache.getLocation()).isEqualTo("Baden-Württemberg, Germany");
+ assertThat(cache.getShortDescription()).isEqualTo("Ein alter Kindheitstraum, ein Schatz auf einer unbewohnten Insel. A old dream of my childhood, a treasure on a lonely is");
+ assertThat(cache.getCoords()).isEqualTo(new Geopoint(48.85968, 9.18740));
assertThat(cache.isReliableLatLon()).isTrue();
}
@@ -176,7 +174,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertThat(log.author).isEqualTo("Geoteufel");
assertThat(log.date).isEqualTo(parseTime("2011-09-11T07:00:00Z"));
assertThat(log.found).isEqualTo(-1);
- assertEquals("Sehr schöne Runde und wir haben wieder etwas Neues über Hockenheim gelernt. Super Tarnung.\nTFTC, Geoteufel", log.log);
+ assertThat(log.log).isEqualTo("Sehr schöne Runde und wir haben wieder etwas Neues über Hockenheim gelernt. Super Tarnung.\nTFTC, Geoteufel");
assertThat(log.isOwn()).isFalse();
assertThat(log.getDisplayText()).isEqualTo(log.log);
assertThat(log.daysSinceLog() > 700).isTrue();
@@ -211,7 +209,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertThat(wp.getPrefix()).isEqualTo("S1");
assertThat(wp.getLookup()).isEqualTo("---");
assertThat(wp.getName()).isEqualTo("Station 1");
- assertEquals("Ein zweiter Wegpunkt, der nicht wirklich existiert sondern nur zum Testen gedacht ist.", wp.getNote());
+ assertThat(wp.getNote()).isEqualTo("Ein zweiter Wegpunkt, der nicht wirklich existiert sondern nur zum Testen gedacht ist.");
assertThat(wp.getWaypointType()).isEqualTo(WaypointType.STAGE);
assertEquals(49.317500, wp.getCoords().getLatitude(), 0.000001);
assertEquals(8.545100, wp.getCoords().getLongitude(), 0.000001);
@@ -320,7 +318,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertThat(waymark).isNotNull();
assertThat(waymark.getGeocode()).isEqualTo("WM7BM7");
assertThat(waymark.getName()).isEqualTo("Roman water pipe Kornwestheim");
- assertThat(StringUtils.isNotBlank(waymark.getUrl())).isTrue(); // connector must be able to create it
+ assertThat(waymark.getUrl()).isNotEmpty(); // connector must be able to create it
assertThat(waymark.getType()).isEqualTo(CacheType.UNKNOWN);
assertThat(waymark.getSize()).isEqualTo(CacheSize.UNKNOWN);
}
@@ -347,7 +345,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
assertThat(cache.getDifficulty()).isEqualTo(1.5f);
assertThat(cache.getTerrain()).isEqualTo(1.0f);
assertThat(cache.getDescription().startsWith("Dieses sind die Reste einer in Kornwestheim gefundenen")).isTrue();
- assertEquals(new Geopoint(48.8642167, 9.1836), cache.getCoords());
+ assertThat(cache.getCoords()).isEqualTo(new Geopoint(48.8642167, 9.1836));
assertThat(cache.isReliableLatLon()).isTrue();
assertThat(cache.getHint()).isEqualTo("Wasserleitung");
}
diff --git a/tests/src/cgeo/geocaching/files/InvalidXMLCharacterFilterReaderTest.java b/tests/src/cgeo/geocaching/files/InvalidXMLCharacterFilterReaderTest.java
index 0641b5d..515d8a6 100644
--- a/tests/src/cgeo/geocaching/files/InvalidXMLCharacterFilterReaderTest.java
+++ b/tests/src/cgeo/geocaching/files/InvalidXMLCharacterFilterReaderTest.java
@@ -17,6 +17,7 @@ public class InvalidXMLCharacterFilterReaderTest extends AndroidTestCase {
final AtomicReference<String> description = new AtomicReference<String>();
root.setEndTextElementListener(new EndTextElementListener() {
+ @Override
public void end(String body) {
description.set(body);
}