aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lint.xml4
-rw-r--r--tests/proguard-project.txt56
-rw-r--r--tests/src/cgeo/geocaching/CgeoApplicationTest.java9
-rw-r--r--tests/src/cgeo/geocaching/StaticMapsProviderTest.java7
-rw-r--r--tests/src/cgeo/geocaching/apps/cache/WhereYouGoAppTest.java15
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java10
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCParserTest.java14
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java4
-rw-r--r--tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java14
-rw-r--r--tests/src/cgeo/geocaching/export/ExportTest.java4
-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
-rw-r--r--tests/src/cgeo/geocaching/filter/StateNotFoundFilterTest.java28
-rw-r--r--tests/src/cgeo/geocaching/geopoint/GeoPointFormatterTest.java2
-rw-r--r--tests/src/cgeo/geocaching/geopoint/UnitsTest.java12
-rw-r--r--tests/src/cgeo/geocaching/geopoint/ViewportTest.java4
-rw-r--r--tests/src/cgeo/geocaching/settings/TestSettings.java4
-rw-r--r--tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java7
-rw-r--r--tests/src/cgeo/geocaching/test/mock/MockedCache.java1
-rw-r--r--tests/src/cgeo/geocaching/twitter/TwitterTest.java12
-rw-r--r--tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java46
-rw-r--r--tests/src/cgeo/geocaching/utils/TextUtilsTest.java6
23 files changed, 240 insertions, 94 deletions
diff --git a/tests/lint.xml b/tests/lint.xml
new file mode 100644
index 0000000..8e1c48c
--- /dev/null
+++ b/tests/lint.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<lint>
+ <issue id="IconMissingDensityFolder" severity="ignore" />
+</lint> \ No newline at end of file
diff --git a/tests/proguard-project.txt b/tests/proguard-project.txt
index f0b04dc..20b2222 100644
--- a/tests/proguard-project.txt
+++ b/tests/proguard-project.txt
@@ -1,40 +1,20 @@
--optimizationpasses 5
--dontusemixedcaseclassnames
--dontskipnonpubliclibraryclasses
--dontpreverify
--verbose
--optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
--keep public class * extends android.app.Activity
--keep public class * extends android.app.Application
--keep public class * extends android.app.Service
--keep public class * extends android.content.BroadcastReceiver
--keep public class * extends android.content.ContentProvider
--keep public class * extends android.app.backup.BackupAgentHelper
--keep public class * extends android.preference.Preference
--keep public class com.android.vending.licensing.ILicensingService
+# Add any project specific keep options here:
--keepclasseswithmembernames class * {
- native <methods>;
-}
-
--keepclasseswithmembers class * {
- public <init>(android.content.Context, android.util.AttributeSet);
-}
-
--keepclasseswithmembers class * {
- public <init>(android.content.Context, android.util.AttributeSet, int);
-}
-
--keepclassmembers class * extends android.app.Activity {
- public void *(android.view.View);
-}
-
--keepclassmembers enum * {
- public static **[] values();
- public static ** valueOf(java.lang.String);
-}
-
--keep class * implements android.os.Parcelable {
- public static final android.os.Parcelable$Creator *;
-}
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#} \ No newline at end of file
diff --git a/tests/src/cgeo/geocaching/CgeoApplicationTest.java b/tests/src/cgeo/geocaching/CgeoApplicationTest.java
index 3e63481..ae182d7 100644
--- a/tests/src/cgeo/geocaching/CgeoApplicationTest.java
+++ b/tests/src/cgeo/geocaching/CgeoApplicationTest.java
@@ -79,8 +79,8 @@ public class CgeoApplicationTest extends CGeoTestCase {
assertThat(tb.getIconUrl()).isEqualTo("http://www.geocaching.com/images/wpttypes/21.gif");
assertThat(tb.getName()).isEqualTo("blafoo's Children Music CD");
assertThat(tb.getType()).isEqualTo("Travel Bug Dog Tag");
- assertEquals(new GregorianCalendar(2009, 8 - 1, 24).getTime(), tb.getReleased());
- assertEquals("Niedersachsen, Germany", tb.getOrigin());
+ assertThat(tb.getReleased()).isEqualTo(new GregorianCalendar(2009, 8 - 1, 24).getTime());
+ assertThat(tb.getOrigin()).isEqualTo("Niedersachsen, Germany");
assertThat(tb.getOwner()).isEqualTo("blafoo");
assertThat(tb.getOwnerGuid()).isEqualTo("0564a940-8311-40ee-8e76-7e91b2cf6284");
assertThat(tb.getGoal()).isEqualTo("Kinder erfreuen.<br /><br />Make children happy.");
@@ -158,6 +158,7 @@ public class CgeoApplicationTest extends CGeoTestCase {
public static void testSearchByGeocodeNotLoggedIn() {
withMockedLoginDo(new Runnable() {
+ @Override
public void run() {
// non premium cache
MockedCache cache = new GC2CJPF();
@@ -193,6 +194,7 @@ public class CgeoApplicationTest extends CGeoTestCase {
public static void testSearchErrorOccured() {
withMockedLoginDo(new Runnable() {
+ @Override
public void run() {
// non premium cache
final MockedCache cache = new GC1ZXX2();
@@ -342,6 +344,7 @@ public class CgeoApplicationTest extends CGeoTestCase {
public static void testSearchByViewportNotLoggedIn() {
withMockedLoginDo(new Runnable() {
+ @Override
public void run() {
final Strategy strategy = Settings.getLiveMapStrategy();
final Strategy testStrategy = Strategy.FAST; // FASTEST, FAST or DETAILED for tests
@@ -415,7 +418,7 @@ public class CgeoApplicationTest extends CGeoTestCase {
*/
public static void testSearchByGeocodeSpecialties() {
final Geocache GCV2R9 = CgeoApplicationTest.testSearchByGeocode("GCV2R9");
- assertEquals("California, United States", GCV2R9.getLocation());
+ assertThat(GCV2R9.getLocation()).isEqualTo("California, United States");
final Geocache GC1ZXEZ = CgeoApplicationTest.testSearchByGeocode("GC1ZXEZ");
assertThat(GC1ZXEZ.getOwnerUserId()).isEqualTo("Ms.Marple/Mr.Stringer");
diff --git a/tests/src/cgeo/geocaching/StaticMapsProviderTest.java b/tests/src/cgeo/geocaching/StaticMapsProviderTest.java
index 02c6660..42ad2c5 100644
--- a/tests/src/cgeo/geocaching/StaticMapsProviderTest.java
+++ b/tests/src/cgeo/geocaching/StaticMapsProviderTest.java
@@ -7,13 +7,14 @@ import cgeo.geocaching.files.LocalStorage;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.TestSettings;
+import cgeo.geocaching.utils.RxUtils;
+
+import junit.framework.TestCase;
import android.test.suitebuilder.annotation.Suppress;
import java.io.File;
-import junit.framework.TestCase;
-
@Suppress
public class StaticMapsProviderTest extends TestCase {
@@ -52,7 +53,7 @@ public class StaticMapsProviderTest extends TestCase {
assertThat(StaticMapsProvider.hasStaticMapForWaypoint(geocode, trailhead)).isFalse();
// download
- StaticMapsProvider.downloadMaps(cache);
+ RxUtils.waitForCompletion(StaticMapsProvider.downloadMaps(cache));
try {
Thread.sleep(10000);
diff --git a/tests/src/cgeo/geocaching/apps/cache/WhereYouGoAppTest.java b/tests/src/cgeo/geocaching/apps/cache/WhereYouGoAppTest.java
new file mode 100644
index 0000000..5290c35
--- /dev/null
+++ b/tests/src/cgeo/geocaching/apps/cache/WhereYouGoAppTest.java
@@ -0,0 +1,15 @@
+package cgeo.geocaching.apps.cache;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.Geocache;
+
+import junit.framework.TestCase;
+
+public class WhereYouGoAppTest extends TestCase {
+ public static void testGetWhereIGoUrl() throws Exception {
+ Geocache cache = new Geocache();
+ cache.setDescription("<p style=\"max-width:670px;\"><a href=\"http://www.wherigo.com/cartridge/details.aspx?CGUID=c4577c31-09e9-44f0-ae48-83737e57adbd\"><img class=\"InsideTable\"");
+ assertThat(WhereYouGoApp.getWhereIGoUrl(cache)).isEqualTo("http://www.wherigo.com/cartridge/details.aspx?CGUID=c4577c31-09e9-44f0-ae48-83737e57adbd");
+ }
+}
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java
index be0c4da..ef50709 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java
@@ -16,9 +16,9 @@ public class GCConstantsTest extends AndroidTestCase {
public static void testLocation() {
// GC37GFJ
- assertEquals("Bretagne, France", parseLocation(" <span id=\"ctl00_ContentBody_Location\">In Bretagne, France</span><br />"));
+ assertThat(parseLocation(" <span id=\"ctl00_ContentBody_Location\">In Bretagne, France</span><br />")).isEqualTo("Bretagne, France");
// GCV2R9
- assertEquals("California, United States", parseLocation("<span id=\"ctl00_ContentBody_Location\">In <a href=\"/map/beta/default.aspx?lat=37.4354&lng=-122.07745&z=16\" title=\"View Map\">California, United States</a></span><br />"));
+ assertThat(parseLocation("<span id=\"ctl00_ContentBody_Location\">In <a href=\"/map/beta/default.aspx?lat=37.4354&lng=-122.07745&z=16\" title=\"View Map\">California, United States</a></span><br />")).isEqualTo("California, United States");
}
private static String parseLocation(final String html) {
@@ -55,16 +55,16 @@ public class GCConstantsTest extends AndroidTestCase {
public static void testConstants() {
final String session = "userSession = new Groundspeak.Map.UserSession('aKWZ', userOptions:'XPTf', sessionToken:'123pNKwdktYGZL0xd-I7yqA6nm_JE1BDUtM4KcOkifin2TRCMutBd_PZE14Ohpffs2ZgkTnxTSnxYpBigK4hBA2', subscriberType: 3, enablePersonalization: true });";
- assertEquals("aKWZ", TextUtils.getMatch(session, GCConstants.PATTERN_USERSESSION, ""));
+ assertThat(TextUtils.getMatch(session, GCConstants.PATTERN_USERSESSION, "")).isEqualTo("aKWZ");
assertThat(TextUtils.getMatch(session, GCConstants.PATTERN_SESSIONTOKEN, "").startsWith("123pNK")).isTrue();
}
public static void testTBWithSpecialChar() {
// Incidentally, the site incorrectly escapes the "&" into "&amp;"
final String page = "<span id=\"ctl00_ContentBody_lbHeading\">Schlauchen&amp;ravestorm</span>";
- assertEquals("Schlauchen&ravestorm", Html.fromHtml(TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_NAME, "")).toString());
+ assertThat(Html.fromHtml(TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_NAME, "")).toString()).isEqualTo("Schlauchen&ravestorm");
// Test with the current incorrect form as well
final String page2 = "<span id=\"ctl00_ContentBody_lbHeading\">Schlauchen&ravestorm</span>";
- assertEquals("Schlauchen&ravestorm", Html.fromHtml(TextUtils.getMatch(page2, GCConstants.PATTERN_TRACKABLE_NAME, "")).toString());
+ assertThat(Html.fromHtml(TextUtils.getMatch(page2, GCConstants.PATTERN_TRACKABLE_NAME, "")).toString()).isEqualTo("Schlauchen&ravestorm");
}
}
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
index 2897b54..1c64568 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
@@ -36,7 +36,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
private void assertUnpublished(final int cache) {
final String page = getFileContent(cache);
- final SearchResult result = GCParser.parseCacheFromText(page, null);
+ final SearchResult result = GCParser.parseAndSaveCacheFromText(page, null);
assertThat(result).isNotNull();
assertThat(result.isEmpty()).isTrue();
assertThat(result.getError()).isEqualTo(StatusCode.UNPUBLISHED_CACHE);
@@ -52,7 +52,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
private void assertPublishedCache(final int cachePage, final String cacheName) {
final String page = getFileContent(cachePage);
- final SearchResult result = GCParser.parseCacheFromText(page, null);
+ final SearchResult result = GCParser.parseAndSaveCacheFromText(page, null);
assertThat(result).isNotNull();
assertThat(result.getCount()).isEqualTo(1);
final Geocache cache = result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
@@ -79,7 +79,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
final SearchResult searchResult;
try {
Settings.setGcCustomDate(MockedCache.getDateFormat());
- searchResult = GCParser.parseCacheFromText(mockedCache.getData(), null);
+ searchResult = GCParser.parseAndSaveCacheFromText(mockedCache.getData(), null);
} finally {
Settings.setGcCustomDate(oldCustomDate);
}
@@ -103,7 +103,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
for (MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) {
// to get the same results we have to use the date format used when the mocked data was created
Settings.setGcCustomDate(MockedCache.getDateFormat());
- SearchResult searchResult = GCParser.parseCacheFromText(mockedCache.getData(), null);
+ SearchResult searchResult = GCParser.parseAndSaveCacheFromText(mockedCache.getData(), null);
Geocache parsedCache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
assertThat(StringUtils.isNotBlank(mockedCache.getMockedDataUser())).isTrue();
Compare.assertCompareCaches(mockedCache, parsedCache, true);
@@ -158,7 +158,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
GCParser.editModifiedCoordinates(cache, new Geopoint("N51 21.544", "E07 02.566"));
cache.dropSynchronous();
final String page = GCParser.requestHtmlPage(cache.getGeocode(), null, "n", "0");
- final Geocache cache2 = GCParser.parseCacheFromText(page, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);
+ final Geocache cache2 = GCParser.parseAndSaveCacheFromText(page, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);
assertThat(cache2).isNotNull();
assert (cache2 != null); // eclipse bug
assertThat(cache2.hasUserModifiedCoords()).isTrue();
@@ -167,7 +167,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
GCParser.deleteModifiedCoordinates(cache2);
cache2.dropSynchronous();
final String page2 = GCParser.requestHtmlPage(cache.getGeocode(), null, "n", "0");
- final Geocache cache3 = GCParser.parseCacheFromText(page2, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);
+ final Geocache cache3 = GCParser.parseAndSaveCacheFromText(page2, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);
assertThat(cache3).isNotNull();
assert (cache3 != null); // eclipse bug
assertThat(cache3.hasUserModifiedCoords()).isFalse();
@@ -210,7 +210,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
private Geocache parseCache(int resourceId) {
final String page = getFileContent(resourceId);
- final SearchResult result = GCParser.parseCacheFromText(page, null);
+ final SearchResult result = GCParser.parseAndSaveCacheFromText(page, null);
assertThat(result).isNotNull();
assertThat(result.isEmpty()).isFalse();
return result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
diff --git a/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java b/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java
index c45efd7..faaedbf 100644
--- a/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java
@@ -101,9 +101,9 @@ public class TrackablesTest extends AbstractResourceInstrumentationTestCase {
assertThat(goal).isNotNull();
assertThat(goal.startsWith("Bei meinem Besitzer auf der Couch")).isTrue();
assertThat(goal.endsWith("Geocachern zusammen fotografieren.")).isTrue();
- assertEquals("Der kleine Maulwurf in etwas gr&ouml;&szlig;er :-)", trackable.getDetails());
+ assertThat(trackable.getDetails()).isEqualTo("Der kleine Maulwurf in etwas gr&ouml;&szlig;er :-)");
assertThat(trackable.getGeocode()).isEqualTo("TB54VJJ");
- assertEquals("Nordrhein-Westfalen, Germany", trackable.getOrigin());
+ assertThat(trackable.getOrigin()).isEqualTo("Nordrhein-Westfalen, Germany");
assertThat(trackable.getOwner()).isEqualTo("Lineflyer");
// the icon url is manipulated during compression
assertThat(trackable.getIconUrl().endsWith("www.geocaching.com/images/wpttypes/21.gif")).isTrue();
diff --git a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java
index 05d676b..04bb5ac 100644
--- a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java
+++ b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java
@@ -6,6 +6,7 @@ import cgeo.CGeoTestCase;
import cgeo.geocaching.DataStore;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.enumerations.LoadFlags;
+import cgeo.geocaching.enumerations.LogType;
public class OkapiClientTest extends CGeoTestCase {
@@ -22,6 +23,8 @@ public class OkapiClientTest extends CGeoTestCase {
assertThat(cache.getGeocode()).isEqualTo(geoCode);
assertThat(cache.getName()).isEqualTo("Oshkosh Municipal Tank");
assertThat(cache.isDetailed()).isTrue();
+ assertThat(cache.getOwnerDisplayName()).isNotEmpty();
+ assertThat(cache.getOwnerUserId()).isEqualTo(cache.getOwnerDisplayName());
}
public static void testOCSearchMustWorkWithoutOAuthAccessTokens() {
@@ -42,8 +45,17 @@ public class OkapiClientTest extends CGeoTestCase {
assertThat(cache.getWaypoints()).hasSize(3);
// load again
- cache.refreshSynchronous(cache.getListId(), null);
+ cache.refreshSynchronous(null);
assertThat(cache.getWaypoints()).hasSize(3);
}
+ public static void testOCWillAttendLogs() {
+ final String geoCode = "OC10CB8";
+
+ removeCacheCompletely(geoCode);
+ Geocache cache = OkapiClient.getCache(geoCode);
+ assertThat(cache).as("Cache from OKAPI").isNotNull();
+ assertThat(cache.getLogCounts().get(LogType.WILL_ATTEND)).isGreaterThan(0);
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/export/ExportTest.java b/tests/src/cgeo/geocaching/export/ExportTest.java
index a9fceec..848a1f7 100644
--- a/tests/src/cgeo/geocaching/export/ExportTest.java
+++ b/tests/src/cgeo/geocaching/export/ExportTest.java
@@ -52,10 +52,6 @@ public class ExportTest extends CGeoTestCase {
private static class GpxExportTester extends GpxExport {
- protected GpxExportTester() {
- super();
- }
-
public File testExportSync(List<Geocache> caches) throws InterruptedException, ExecutionException {
final ArrayList<String> geocodes = new ArrayList<String>(caches.size());
for (final Geocache cache : caches) {
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);
}
diff --git a/tests/src/cgeo/geocaching/filter/StateNotFoundFilterTest.java b/tests/src/cgeo/geocaching/filter/StateNotFoundFilterTest.java
new file mode 100644
index 0000000..2bf9d94
--- /dev/null
+++ b/tests/src/cgeo/geocaching/filter/StateNotFoundFilterTest.java
@@ -0,0 +1,28 @@
+package cgeo.geocaching.filter;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.CGeoTestCase;
+import cgeo.geocaching.Geocache;
+import cgeo.geocaching.filter.StateFilter.StateNotFoundFilter;
+
+public class StateNotFoundFilterTest extends CGeoTestCase {
+
+ private StateFilter.StateNotFoundFilter notFoundFilter;
+ private Geocache foundCache;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ notFoundFilter = new StateNotFoundFilter();
+ foundCache = new Geocache();
+ foundCache.setFound(true);
+ }
+
+ public void testAccepts() {
+ assertThat(notFoundFilter.accepts(foundCache)).isFalse();
+ assertThat(notFoundFilter.accepts(new Geocache())).isTrue();
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/geopoint/GeoPointFormatterTest.java b/tests/src/cgeo/geocaching/geopoint/GeoPointFormatterTest.java
index 4b25247..4392705 100644
--- a/tests/src/cgeo/geocaching/geopoint/GeoPointFormatterTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/GeoPointFormatterTest.java
@@ -12,7 +12,7 @@ public class GeoPointFormatterTest extends AndroidTestCase {
// From issue #2624: coordinate is wrong near to a confluence point
final Geopoint point = new Geopoint(49.9999999999999, 5.0);
final String format = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECDEGREE_COMMA, point);
- assertEquals("50.000000,5.000000", format);
+ assertThat(format).isEqualTo("50.000000,5.000000");
final String formatMinute = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECMINUTE_RAW, point);
assertThat(formatMinute).isEqualTo("N 50° 00.000 E 005° 00.000");
final String formatSecond = GeopointFormatter.format(GeopointFormatter.Format.LAT_LON_DECSECOND, point).replaceAll(",", ".");
diff --git a/tests/src/cgeo/geocaching/geopoint/UnitsTest.java b/tests/src/cgeo/geocaching/geopoint/UnitsTest.java
index acc964a..f208984 100644
--- a/tests/src/cgeo/geocaching/geopoint/UnitsTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/UnitsTest.java
@@ -51,13 +51,13 @@ public class UnitsTest extends CGeoTestCase {
TestSettings.setUseImperialUnits(false);
assertSpeed("123 km/h", 122.782f);
assertSpeed("123 km/h", 123.456f);
- assertSpeed("12.3 km/h", 12.3456f);
- assertSpeed("1.23 km/h", 1.23456f);
- assertSpeed("123 m/h", 0.123456f);
+ assertSpeed("12 km/h", 12.3456f);
+ assertSpeed("1 km/h", 1.23456f);
+ assertSpeed("0 km/h", 0.123456f);
TestSettings.setUseImperialUnits(true);
- assertSpeed("76.7 mph", 123.456f);
- assertSpeed("7.67 mph", 12.3456f);
- assertSpeed("0.77 mph", 1.23456f);
+ assertSpeed("77 mph", 123.456f);
+ assertSpeed("8 mph", 12.3456f);
+ assertSpeed("1 mph", 1.23456f);
} finally {
TestSettings.setUseImperialUnits(savedImperial);
}
diff --git a/tests/src/cgeo/geocaching/geopoint/ViewportTest.java b/tests/src/cgeo/geocaching/geopoint/ViewportTest.java
index ab59e79..ace0356 100644
--- a/tests/src/cgeo/geocaching/geopoint/ViewportTest.java
+++ b/tests/src/cgeo/geocaching/geopoint/ViewportTest.java
@@ -6,6 +6,7 @@ import cgeo.geocaching.ICoordinates;
import org.eclipse.jdt.annotation.NonNull;
+import android.annotation.SuppressLint;
import android.test.AndroidTestCase;
import java.util.Collections;
@@ -59,6 +60,7 @@ public class ViewportTest extends AndroidTestCase {
assertThat(vpRef.contains(new Geopoint(3.0, 4.0))).isTrue();
}
+ @SuppressLint("DefaultLocale")
public static void testSqlWhere() {
assertThat(vpRef.sqlWhere(null).toString()).isEqualTo("latitude >= -1.0 and latitude <= 3.0 and longitude >= -2.0 and longitude <= 4.0");
assertThat(vpRef.sqlWhere("t").toString()).isEqualTo("t.latitude >= -1.0 and t.latitude <= 3.0 and t.longitude >= -2.0 and t.longitude <= 4.0");
@@ -66,7 +68,7 @@ public class ViewportTest extends AndroidTestCase {
try {
current = Locale.getDefault();
Locale.setDefault(Locale.FRENCH);
- assertEquals("1,0", String.format("%.2g", 1.0d)); // Control that we are in a locale with commma separator
+ assertThat(String.format("%.2g", 1.0d)).isEqualTo("1,0"); // Control that we are in a locale with comma separator
assertThat(vpRef.sqlWhere("t").toString()).isEqualTo("t.latitude >= -1.0 and t.latitude <= 3.0 and t.longitude >= -2.0 and t.longitude <= 4.0");
} finally {
Locale.setDefault(current);
diff --git a/tests/src/cgeo/geocaching/settings/TestSettings.java b/tests/src/cgeo/geocaching/settings/TestSettings.java
index 2e6809f..279f658 100644
--- a/tests/src/cgeo/geocaching/settings/TestSettings.java
+++ b/tests/src/cgeo/geocaching/settings/TestSettings.java
@@ -48,4 +48,8 @@ public final class TestSettings extends Settings {
putString(R.string.pref_twitter_trackable_message, template);
}
+ public static void setSignature(final String signature) {
+ putString(R.string.pref_signature, signature);
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
index df8dc1f..cbad794 100644
--- a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
+++ b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
@@ -12,7 +12,9 @@ import cgeo.geocaching.files.GPX10Parser;
import cgeo.geocaching.files.ParserException;
import cgeo.geocaching.list.StoredList;
+import android.content.ContentResolver;
import android.content.res.Resources;
+import android.net.Uri;
import android.test.InstrumentationTestCase;
import java.io.File;
@@ -102,4 +104,9 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument
instream.close();
}
}
+
+ protected Uri getResourceURI(int resId) {
+ Resources resources = getInstrumentation().getContext().getResources();
+ return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(resId) + '/' + resources.getResourceTypeName(resId) + '/' + resources.getResourceEntryName(resId));
+ }
}
diff --git a/tests/src/cgeo/geocaching/test/mock/MockedCache.java b/tests/src/cgeo/geocaching/test/mock/MockedCache.java
index d06e715..cd482f8 100644
--- a/tests/src/cgeo/geocaching/test/mock/MockedCache.java
+++ b/tests/src/cgeo/geocaching/test/mock/MockedCache.java
@@ -150,6 +150,7 @@ public abstract class MockedCache implements ICache {
return getName();
}
+ @Override
public Geopoint getCoords() {
return coords;
}
diff --git a/tests/src/cgeo/geocaching/twitter/TwitterTest.java b/tests/src/cgeo/geocaching/twitter/TwitterTest.java
index 9de5e2f..a4df454 100644
--- a/tests/src/cgeo/geocaching/twitter/TwitterTest.java
+++ b/tests/src/cgeo/geocaching/twitter/TwitterTest.java
@@ -1,5 +1,7 @@
package cgeo.geocaching.twitter;
+import static org.assertj.core.api.Assertions.assertThat;
+
import cgeo.geocaching.Geocache;
import cgeo.geocaching.LogEntry;
import cgeo.geocaching.Trackable;
@@ -18,7 +20,7 @@ public class TwitterTest extends TestCase {
Trackable tb = new Trackable();
tb.setName("Travel bug");
tb.setGeocode("TB1234");
- assertEquals("I touched Travel bug (http://www.geocaching.com//track/details.aspx?tracker=TB1234). #cgeo #geocaching", Twitter.getStatusMessage(tb, null));
+ assertThat(Twitter.getStatusMessage(tb, null)).isEqualTo("I touched Travel bug (http://www.geocaching.com//track/details.aspx?tracker=TB1234). #cgeo #geocaching");
} finally {
TestSettings.setTrackableTwitterMessage(oldMessage);
}
@@ -31,7 +33,7 @@ public class TwitterTest extends TestCase {
Geocache cache = new Geocache();
cache.setGeocode("GC1234");
cache.setName("TwitterTest");
- assertEquals("I found TwitterTest (http://coord.info/GC1234). #cgeo #geocaching", Twitter.getStatusMessage(cache, null));
+ assertThat(Twitter.getStatusMessage(cache, null)).isEqualTo("I found TwitterTest (http://coord.info/GC1234). #cgeo #geocaching");
} finally {
TestSettings.setCacheTwitterMessage(oldMessage);
}
@@ -43,7 +45,7 @@ public class TwitterTest extends TestCase {
TestSettings.setCacheTwitterMessage("[LOG]");
Geocache cache = new Geocache();
LogEntry log = new LogEntry(0, LogType.FOUND_IT, "log text");
- assertEquals("log text #cgeo #geocaching", Twitter.getStatusMessage(cache, log));
+ assertThat(Twitter.getStatusMessage(cache, log)).isEqualTo("log text #cgeo #geocaching");
} finally {
TestSettings.setCacheTwitterMessage(oldMessage);
}
@@ -55,7 +57,7 @@ public class TwitterTest extends TestCase {
TestSettings.setTrackableTwitterMessage("[LOG]");
Trackable trackable = new Trackable();
LogEntry log = new LogEntry(0, LogType.FOUND_IT, "trackable log text");
- assertEquals("trackable log text #cgeo #geocaching", Twitter.getStatusMessage(trackable, log));
+ assertThat(Twitter.getStatusMessage(trackable, log)).isEqualTo("trackable log text #cgeo #geocaching");
} finally {
TestSettings.setTrackableTwitterMessage(oldMessage);
}
@@ -68,7 +70,7 @@ public class TwitterTest extends TestCase {
Geocache cache = new Geocache();
cache.setGeocode("GC1234");
cache.setName("TwitterTest");
- assertEquals("TwitterTest #cgeo #mytag #geocaching", Twitter.getStatusMessage(cache, null));
+ assertThat(Twitter.getStatusMessage(cache, null)).isEqualTo("TwitterTest #cgeo #mytag #geocaching");
} finally {
TestSettings.setCacheTwitterMessage(oldMessage);
}
diff --git a/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java b/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java
index a7dcb2b..77832b0 100644
--- a/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java
+++ b/tests/src/cgeo/geocaching/utils/LogTemplateProviderTest.java
@@ -2,6 +2,8 @@ package cgeo.geocaching.utils;
import static org.assertj.core.api.Assertions.assertThat;
+import cgeo.geocaching.settings.Settings;
+import cgeo.geocaching.settings.TestSettings;
import cgeo.geocaching.utils.LogTemplateProvider.LogContext;
import java.util.Calendar;
@@ -10,13 +12,51 @@ import junit.framework.TestCase;
public class LogTemplateProviderTest extends TestCase {
- public static void testApplyTemplates() {
+ public static void testApplyTemplatesNone() {
final String noTemplates = " no templates ";
- assertEquals(noTemplates, LogTemplateProvider.applyTemplates(noTemplates, new LogContext(null, null, true)));
+ final String signature = LogTemplateProvider.applyTemplates(noTemplates, new LogContext(null, null, true));
+ assertThat(signature).isEqualTo(noTemplates);
+ }
+ public static void testApplyTemplates() {
// This test can occasionally fail if the current year changes right after the next line.
final String currentYear = Integer.toString(Calendar.YEAR);
- assertThat(LogTemplateProvider.applyTemplates("[DATE]", new LogContext(null, null, true)).contains(currentYear)).isTrue();
+ final String signature = LogTemplateProvider.applyTemplates("[DATE]", new LogContext(null, null, true));
+ assertThat(signature).contains(currentYear);
+ }
+
+ /**
+ * signature itself can contain templates, therefore nested applying is necessary
+ */
+ public static void testApplySignature() {
+ String oldSignature = Settings.getSignature();
+ try {
+ TestSettings.setSignature("[DATE]");
+ String currentDate = LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(null, null, true));
+ final String signatureTemplate = "Signature [SIGNATURE]";
+ final String signature = LogTemplateProvider.applyTemplates(signatureTemplate, new LogContext(null, null, true));
+ assertThat(signature).isEqualTo("Signature " + currentDate);
+
+ final String currentYear = Integer.toString(Calendar.YEAR);
+ assertThat(signature).contains(currentYear);
+ } finally {
+ TestSettings.setSignature(oldSignature);
+ }
+ }
+
+ /**
+ * signature must not contain itself as template
+ */
+ public static void testApplyInvalidSignature() {
+ String oldSignature = Settings.getSignature();
+ try {
+ final String signatureTemplate = "[SIGNATURE]";
+ TestSettings.setSignature(signatureTemplate);
+ final String signature = LogTemplateProvider.applyTemplates(signatureTemplate, new LogContext(null, null, true));
+ assertThat(signature).isEqualTo("invalid signature template");
+ } finally {
+ TestSettings.setSignature(oldSignature);
+ }
}
}
diff --git a/tests/src/cgeo/geocaching/utils/TextUtilsTest.java b/tests/src/cgeo/geocaching/utils/TextUtilsTest.java
index d1dba84..29c4864 100644
--- a/tests/src/cgeo/geocaching/utils/TextUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/TextUtilsTest.java
@@ -13,7 +13,7 @@ import java.util.regex.Pattern;
public class TextUtilsTest extends AndroidTestCase {
public static void testRegEx() {
final String page = MockedCache.readCachePage("GC2CJPF");
- assertEquals(GCConstantsTest.MOCK_LOGIN_NAME, TextUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, true, "???"));
+ assertThat(TextUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, true, "???")).isEqualTo(GCConstantsTest.MOCK_LOGIN_NAME);
assertThat(page.contains("id=\"ctl00_hlRenew\"") || GCConstants.MEMBER_STATUS_PM.equals(TextUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, "???"))).isTrue();
}
@@ -23,7 +23,7 @@ public class TextUtilsTest extends AndroidTestCase {
public static void testControlCharactersCleanup() {
final Pattern patternAll = Pattern.compile("(.*)", Pattern.DOTALL);
- assertEquals("some control characters removed", TextUtils.getMatch("some" + "\u001C" + "control" + (char) 0x1D + "characters removed", patternAll, ""));
- assertEquals("newline also removed", TextUtils.getMatch("newline\nalso\nremoved", patternAll, ""));
+ assertThat(TextUtils.getMatch("some" + "\u001C" + "control" + (char) 0x1D + "characters removed", patternAll, "")).isEqualTo("some control characters removed");
+ assertThat(TextUtils.getMatch("newline\nalso\nremoved", patternAll, "")).isEqualTo("newline also removed");
}
}