aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching/connector
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/cgeo/geocaching/connector')
-rw-r--r--tests/src/cgeo/geocaching/connector/WaymarkingConnectorTest.java21
-rw-r--r--tests/src/cgeo/geocaching/connector/ec/ECConnectorTest.java4
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java4
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java7
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java10
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java32
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCParserTest.java28
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java1
-rw-r--r--tests/src/cgeo/geocaching/connector/oc/OCCZConnectorTest.java14
-rw-r--r--tests/src/cgeo/geocaching/connector/oc/OCConnectorTest.java11
-rw-r--r--tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java13
-rw-r--r--tests/src/cgeo/geocaching/connector/ox/OXConnectorTest.java6
-rw-r--r--tests/src/cgeo/geocaching/connector/trackable/SwaggieConnectorTest.java29
-rw-r--r--tests/src/cgeo/geocaching/connector/trackable/SwaggieParserTest.java34
-rw-r--r--tests/src/cgeo/geocaching/connector/trackable/TravelBugConnectorTest.java6
-rw-r--r--tests/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnectorTest.java44
16 files changed, 239 insertions, 25 deletions
diff --git a/tests/src/cgeo/geocaching/connector/WaymarkingConnectorTest.java b/tests/src/cgeo/geocaching/connector/WaymarkingConnectorTest.java
new file mode 100644
index 0000000..c4eacc5
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/WaymarkingConnectorTest.java
@@ -0,0 +1,21 @@
+package cgeo.geocaching.connector;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import junit.framework.TestCase;
+
+public class WaymarkingConnectorTest extends TestCase {
+
+ public static void testGetGeocodeFromUrl() {
+ assertThat(ConnectorFactory.getGeocodeFromURL("http://coord.info/WM1234")).isEqualTo("WM1234");
+ assertThat(ConnectorFactory.getGeocodeFromURL("http://www.waymarking.com/waymarks/WMNCDT_American_Legion_Flagpole_1983_University_of_Oregon")).isEqualTo("WMNCDT");
+
+ final IConnector wmConnector = ConnectorFactory.getConnector("WM1234");
+ assertThat(wmConnector).isNotNull();
+
+ assertThat(wmConnector.getGeocodeFromUrl("http://coord.info/WM1234")).isEqualTo("WM1234");
+ assertThat(wmConnector.getGeocodeFromUrl("http://www.waymarking.com/waymarks/WMNCDT_American_Legion_Flagpole_1983_University_of_Oregon")).isEqualTo("WMNCDT");
+
+ assertThat(wmConnector.getGeocodeFromUrl("http://coord.info/GC12ABC")).isNull();
+ assertThat(wmConnector.getGeocodeFromUrl("http://coord.info/TB1234")).isNull();
+ }
+}
diff --git a/tests/src/cgeo/geocaching/connector/ec/ECConnectorTest.java b/tests/src/cgeo/geocaching/connector/ec/ECConnectorTest.java
index aa6a185..f4073a9 100644
--- a/tests/src/cgeo/geocaching/connector/ec/ECConnectorTest.java
+++ b/tests/src/cgeo/geocaching/connector/ec/ECConnectorTest.java
@@ -32,4 +32,8 @@ public class ECConnectorTest extends TestCase {
return geocache;
}
+ public static void testGetGeocodeFromUrl() throws Exception {
+ assertThat(ECConnector.getInstance().getGeocodeFromUrl("http://extremcaching.com/index.php/output-2/738")).isEqualTo("EC738");
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java b/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java
index 63924ab..f7dbe72 100644
--- a/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java
@@ -2,8 +2,8 @@ package cgeo.geocaching.connector.gc;
import static org.assertj.core.api.Assertions.assertThat;
-import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.Viewport;
+import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.location.Viewport;
import java.util.Set;
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
index 811c0e4..30a9af9 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
@@ -6,8 +6,8 @@ import cgeo.geocaching.SearchResult;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.trackable.TravelBugConnector;
import cgeo.geocaching.enumerations.CacheType;
-import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.Viewport;
+import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.location.Viewport;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.TestSettings;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
@@ -82,7 +82,7 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase {
assertTileAt(7536, 4915, new Tile(new Geopoint("S 33° 50.326 E 151° 12.426"), 13));
}
- private static void assertTileAt(int x, int y, final Tile tile) {
+ private static void assertTileAt(final int x, final int y, final Tile tile) {
assertThat(tile.getX()).isEqualTo(x);
assertThat(tile.getY()).isEqualTo(y);
}
@@ -96,5 +96,6 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase {
assertThat(GCConnector.getInstance().getGeocodeFromUrl("http://coord.info/TB1234")).isNull();
assertThat(GCConnector.getInstance().getGeocodeFromUrl("http://www.coord.info/TB1234")).isNull();
+ assertThat(GCConnector.getInstance().getGeocodeFromUrl("http://www.coord.info/WM1234")).isNull();
}
}
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java
index ef50709..57e494a 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java
@@ -11,8 +11,8 @@ import android.text.Html;
public class GCConstantsTest extends AndroidTestCase {
// adapt the following after downloading new mock html files
- public static final String MOCK_LOGIN_NAME = "JoSaMaJa";
- public static final int MOCK_CACHES_FOUND = 484;
+ public static final String MOCK_LOGIN_NAME = "Bananeweizen";
+ public static final int MOCK_CACHES_FOUND = 743;
public static void testLocation() {
// GC37GFJ
@@ -26,15 +26,15 @@ public class GCConstantsTest extends AndroidTestCase {
}
public static void testCacheCount() {
- assertCacheCount(1510, "<strong style=\"display:block\"> 1.510 Caches Found</strong>");
- assertCacheCount(1510, "<strong style=\"display:block\"> 1,510 Caches Found</strong>");
+ assertCacheCount(1510, "<span>1.510 Finds</span>");
+ assertCacheCount(1510, "<span>1,510 Finds</span>");
assertCacheCount(MOCK_CACHES_FOUND, MockedCache.readCachePage("GC2CJPF"));
}
private static void assertCacheCount(final int count, final String html) {
try {
assertEquals(count, Integer.parseInt(TextUtils.getMatch(html, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", "")));
- } catch (NumberFormatException e) {
+ } catch (final NumberFormatException e) {
fail();
}
}
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java b/tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java
new file mode 100644
index 0000000..6022e59
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java
@@ -0,0 +1,32 @@
+package cgeo.geocaching.connector.gc;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.enumerations.StatusCode;
+
+import org.apache.commons.lang3.StringUtils;
+
+import android.test.suitebuilder.annotation.Suppress;
+
+import junit.framework.TestCase;
+
+public class GCLoginTest extends TestCase {
+
+ final GCLogin instance = GCLogin.getInstance();
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ assertThat(instance.login()).isEqualTo(StatusCode.NO_ERROR);
+ }
+
+ public static void testHomeLocation() {
+ assertThat(StringUtils.isNotBlank(GCLogin.retrieveHomeLocation())).isTrue();
+ }
+
+ @Suppress // It currently fails on CI
+ public void testAvatar() {
+ assertThat(instance.downloadAvatar()).isNotNull();
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
index be96cf3..81838e6 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
@@ -11,7 +11,7 @@ import cgeo.geocaching.Waypoint;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.enumerations.WaypointType;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
@@ -57,7 +57,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
assertThat(result.getCount()).isEqualTo(1);
final Geocache cache = result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
assertThat(cache).isNotNull();
- assert (cache != null); // eclipse bug
+ assert cache != null; // eclipse bug
assertThat(cache.getName()).isEqualTo(cacheName);
}
@@ -71,7 +71,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
assertThat(spoiler.getDescription()).as("First spoiler image description").isNull();
}
- private static Geocache createCache(int index) {
+ private static Geocache createCache(final int index) {
final MockedCache mockedCache = RegExPerformanceTest.MOCKED_CACHES.get(index);
// to get the same results we have to use the date format used when the mocked data was created
final String oldCustomDate = Settings.getGcCustomDate();
@@ -93,19 +93,25 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
}
/**
- * Test {@link GCParser#parseCacheFromText(String, int, CancellableHandler)} with "mocked" data
+ * Test {@link GCParser#parseAndSaveCacheFromText(String, CancellableHandler)} with "mocked" data
*
*/
@MediumTest
public static void testParseCacheFromTextWithMockedData() {
final String gcCustomDate = Settings.getGcCustomDate();
try {
- for (MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) {
+ for (final 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.parseAndSaveCacheFromText(mockedCache.getData(), null);
- Geocache parsedCache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
+ final SearchResult searchResult = GCParser.parseAndSaveCacheFromText(mockedCache.getData(), null);
+ final Geocache parsedCache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB);
+ assertThat(parsedCache).isNotNull();
+ assert parsedCache != null; // To keep editors happy
assertThat(StringUtils.isNotBlank(mockedCache.getMockedDataUser())).isTrue();
+ // Workaround for issue #3777
+ if (mockedCache.getGeocode().equals("GC3XX5J") && Settings.getUsername().equals("mucek4")) {
+ parsedCache.setFound(true);
+ }
Compare.assertCompareCaches(mockedCache, parsedCache, true);
}
} finally {
@@ -160,7 +166,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
final String page = GCParser.requestHtmlPage(cache.getGeocode(), null, "n");
final Geocache cache2 = GCParser.parseAndSaveCacheFromText(page, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);
assertThat(cache2).isNotNull();
- assert (cache2 != null); // eclipse bug
+ assert cache2 != null; // eclipse bug
assertThat(cache2.hasUserModifiedCoords()).isTrue();
assertEquals(new Geopoint("N51 21.544", "E07 02.566"), cache2.getCoords());
// delete coordinates
@@ -169,11 +175,11 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
final String page2 = GCParser.requestHtmlPage(cache.getGeocode(), null, "n");
final Geocache cache3 = GCParser.parseAndSaveCacheFromText(page2, null).getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY);
assertThat(cache3).isNotNull();
- assert (cache3 != null); // eclipse bug
+ assert cache3 != null; // eclipse bug
assertThat(cache3.hasUserModifiedCoords()).isFalse();
}
- private static void assertWaypointsFromNote(final Geocache cache, Geopoint[] expected, String note) {
+ private static void assertWaypointsFromNote(final Geocache cache, final Geopoint[] expected, final String note) {
cache.setPersonalNote(note);
cache.setWaypoints(new ArrayList<Waypoint>(), false);
cache.parseWaypointsFromNote();
@@ -208,7 +214,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase {
assertThat(waypoints.get(2).getWaypointType()).isEqualTo(WaypointType.WAYPOINT);
}
- private Geocache parseCache(int resourceId) {
+ private Geocache parseCache(final int resourceId) {
final String page = getFileContent(resourceId);
final SearchResult result = GCParser.parseAndSaveCacheFromText(page, null);
assertThat(result).isNotNull();
diff --git a/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java b/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java
index 89eada3..bf185b3 100644
--- a/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java
@@ -18,6 +18,7 @@ public class TrackablesTest extends AbstractResourceInstrumentationTestCase {
public void testLogPageWithTrackables() {
final List<TrackableLog> tbLogs = GCParser.parseTrackableLog(getFileContent(R.raw.log_with_2tb));
assertThat(tbLogs).isNotNull();
+ assert tbLogs != null;
assertThat(tbLogs).hasSize(2);
final TrackableLog log = tbLogs.get(0);
assertThat(log.name).isEqualTo("Steffen's Kaiserwagen");
diff --git a/tests/src/cgeo/geocaching/connector/oc/OCCZConnectorTest.java b/tests/src/cgeo/geocaching/connector/oc/OCCZConnectorTest.java
new file mode 100644
index 0000000..52fc5c8
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/oc/OCCZConnectorTest.java
@@ -0,0 +1,14 @@
+package cgeo.geocaching.connector.oc;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import junit.framework.TestCase;
+
+public class OCCZConnectorTest extends TestCase {
+
+ public static void testGetGeocodeFromUrl() throws Exception {
+ final OCCZConnector connector = new OCCZConnector();
+ assertThat(connector.getGeocodeFromUrl("http://opencaching.cz/viewcache.php?cacheid=610")).isEqualTo("OZ0262");
+ assertThat(connector.getGeocodeFromUrl("http://www.opencaching.de/viewcache.php?cacheid=151223")).isNull();
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/connector/oc/OCConnectorTest.java b/tests/src/cgeo/geocaching/connector/oc/OCConnectorTest.java
index 0aad3aa..697b8d8 100644
--- a/tests/src/cgeo/geocaching/connector/oc/OCConnectorTest.java
+++ b/tests/src/cgeo/geocaching/connector/oc/OCConnectorTest.java
@@ -24,4 +24,15 @@ public class OCConnectorTest extends TestCase {
return ocConnector;
}
+ public static void testGetGeocodeFromUrlDe() throws Exception {
+ final IConnector connector = ConnectorFactory.getConnector("OC0028");
+ assertThat(connector.getGeocodeFromUrl("http://opencaching.de/OC0028")).isEqualTo("OC0028");
+ assertThat(connector.getGeocodeFromUrl("http://www.opencaching.de/OC0028")).isEqualTo("OC0028");
+ }
+
+ public static void testGetGeocodeFromUrlUs() throws Exception {
+ final IConnector connector = ConnectorFactory.getConnector("OU07A0");
+ assertThat(connector.getGeocodeFromUrl("http://www.opencaching.us/viewcache.php?wp=OU07A0")).isEqualTo("OU07A0");
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java
index 20a51b8..22b2dbe 100644
--- a/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java
+++ b/tests/src/cgeo/geocaching/connector/oc/OkapiClientTest.java
@@ -19,6 +19,7 @@ public class OkapiClientTest extends CGeoTestCase {
assertThat(cache.isDetailed()).isTrue();
// cache should be stored to DB (to listID 0) when loaded above
cache = DataStore.loadCache(geoCode, LoadFlags.LOAD_ALL_DB_ONLY);
+ assert cache != null;
assertThat(cache).isNotNull();
assertThat(cache.getGeocode()).isEqualTo(geoCode);
assertThat(cache.getName()).isEqualTo("Oshkosh Municipal Tank");
@@ -29,7 +30,7 @@ public class OkapiClientTest extends CGeoTestCase {
public static void testOCSearchMustWorkWithoutOAuthAccessTokens() {
final String geoCode = "OC1234";
- Geocache cache = OkapiClient.getCache(geoCode);
+ final Geocache cache = OkapiClient.getCache(geoCode);
assertThat(cache).overridingErrorMessage("You must have a valid OKAPI key installed for running this test (but you do not need to set credentials in the app).").isNotNull();
assertThat(cache.getName()).isEqualTo("Wupper-Schein");
}
@@ -41,6 +42,7 @@ public class OkapiClientTest extends CGeoTestCase {
assertThat(cache).as("Cache from OKAPI").isNotNull();
// cache should be stored to DB (to listID 0) when loaded above
cache = DataStore.loadCache(geoCode, LoadFlags.LOAD_ALL_DB_ONLY);
+ assert cache != null;
assertThat(cache).isNotNull();
assertThat(cache.getWaypoints()).hasSize(3);
@@ -53,9 +55,16 @@ public class OkapiClientTest extends CGeoTestCase {
final String geoCode = "OC6465";
removeCacheCompletely(geoCode);
- Geocache cache = OkapiClient.getCache(geoCode);
+ final Geocache cache = OkapiClient.getCache(geoCode);
assertThat(cache).as("Cache from OKAPI").isNotNull();
assertThat(cache.getLogCounts().get(LogType.WILL_ATTEND)).isGreaterThan(0);
}
+ public static void testGetAllLogs() {
+ final String geoCode = "OC10CB8";
+ final Geocache cache = OkapiClient.getCache(geoCode);
+ final int defaultLogCount = 10;
+ assertThat(cache.getLogs().size()).isGreaterThan(defaultLogCount);
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/connector/ox/OXConnectorTest.java b/tests/src/cgeo/geocaching/connector/ox/OXConnectorTest.java
index 5433387..11f2d66 100644
--- a/tests/src/cgeo/geocaching/connector/ox/OXConnectorTest.java
+++ b/tests/src/cgeo/geocaching/connector/ox/OXConnectorTest.java
@@ -14,4 +14,10 @@ public class OXConnectorTest extends TestCase {
assertThat(oxConnector.canHandle("OX_")).isFalse();
}
+ public static void testGetGeocodeFromUrl() {
+ final OXConnector connector = new OXConnector();
+ assertThat(connector.getGeocodeFromUrl("http://www.opencaching.com/de/#!geocache/OX1R421")).isEqualTo("OX1R421");
+ assertThat(connector.getGeocodeFromUrl("http://www.opencaching.com/#!geocache/OX1R421")).isEqualTo("OX1R421");
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/connector/trackable/SwaggieConnectorTest.java b/tests/src/cgeo/geocaching/connector/trackable/SwaggieConnectorTest.java
new file mode 100644
index 0000000..54c3319
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/trackable/SwaggieConnectorTest.java
@@ -0,0 +1,29 @@
+package cgeo.geocaching.connector.trackable;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.Trackable;
+
+import junit.framework.TestCase;
+
+public class SwaggieConnectorTest extends TestCase {
+
+ public static void testCanHandleTrackable() {
+ assertThat(new SwaggieConnector().canHandleTrackable("SW0001")).isTrue();
+ assertThat(new SwaggieConnector().canHandleTrackable("SWABCD")).isFalse();
+ assertThat(new SwaggieConnector().canHandleTrackable("GK82A2")).isFalse();
+ assertThat(new SwaggieConnector().canHandleTrackable("TB1234")).isFalse();
+ assertThat(new SwaggieConnector().canHandleTrackable("UNKNOWN")).isFalse();
+ }
+
+ public static void testGetTrackableCodeFromUrl() throws Exception {
+ assertThat(new SwaggieConnector().getTrackableCodeFromUrl("http://geocaching.com.au/swaggie/sw0017")).isEqualTo("SW0017");
+ }
+
+ public static void testGetUrl() throws Exception {
+ final Trackable trackable = new Trackable();
+ trackable.setGeocode("SW0017");
+ assertThat(new SwaggieConnector().getUrl(trackable)).isEqualTo("http://geocaching.com.au/swaggie/SW0017");
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/connector/trackable/SwaggieParserTest.java b/tests/src/cgeo/geocaching/connector/trackable/SwaggieParserTest.java
new file mode 100644
index 0000000..2661fb3
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/trackable/SwaggieParserTest.java
@@ -0,0 +1,34 @@
+package cgeo.geocaching.connector.trackable;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.Trackable;
+import cgeo.geocaching.connector.ConnectorFactory;
+import cgeo.geocaching.network.Network;
+
+import junit.framework.TestCase;
+
+public class SwaggieParserTest extends TestCase {
+
+ public static void testParse() {
+ final Trackable trackableIn = new Trackable();
+ trackableIn.setGeocode("SW0017");
+
+ final String trackableUrl = ConnectorFactory.getTrackableConnector(trackableIn.getGeocode()).getUrl(trackableIn);
+ assertThat(trackableUrl).isNotNull();
+
+ final String page = Network.getResponseData(Network.getRequest(trackableUrl));
+ assertThat(page).isNotNull();
+
+ assert page != null;
+ final Trackable trackable = SwaggieParser.parse(page);
+ assertThat(trackable).isNotNull();
+ assert trackable != null;
+
+ assertThat(trackable.getName()).isEqualTo("Law and Order 1");
+ assertThat(trackable.getGeocode()).isEqualTo("SW0017");
+ assertThat(trackable.getDetails()).isEqualTo("A mini CD that may or may not contain a DivX .AVI of the Law and Order: CSI episode that features geocaching as part of the storyline.");
+ assertThat(trackable.getType()).isEqualTo("Swaggie");
+ assertThat(trackable.getOwner()).isEqualTo("Bear_Left");
+ }
+}
diff --git a/tests/src/cgeo/geocaching/connector/trackable/TravelBugConnectorTest.java b/tests/src/cgeo/geocaching/connector/trackable/TravelBugConnectorTest.java
index 8d80822..7123e87 100644
--- a/tests/src/cgeo/geocaching/connector/trackable/TravelBugConnectorTest.java
+++ b/tests/src/cgeo/geocaching/connector/trackable/TravelBugConnectorTest.java
@@ -26,14 +26,16 @@ public class TravelBugConnectorTest extends TestCase {
}
public static void testOnlineSearchBySecretCode() {
- Trackable trackable = getConnector().searchTrackable("GST9HV", null, null);
+ final Trackable trackable = getConnector().searchTrackable("GST9HV", null, null);
assertThat(trackable).isNotNull();
+ assert trackable != null;
assertThat(trackable.getName()).isEqualTo("Deutschland");
}
public static void testOnlineSearchByPublicCode() {
- Trackable trackable = getConnector().searchTrackable("TB4JD36", null, null);
+ final Trackable trackable = getConnector().searchTrackable("TB4JD36", null, null);
assertThat(trackable).isNotNull();
+ assert trackable != null;
assertThat(trackable.getName()).isEqualTo("Mein Kilometerzähler");
}
diff --git a/tests/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnectorTest.java b/tests/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnectorTest.java
new file mode 100644
index 0000000..ded0a1a
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnectorTest.java
@@ -0,0 +1,44 @@
+package cgeo.geocaching.connector.trackable;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.Trackable;
+
+import junit.framework.TestCase;
+
+public class UnknownTrackableConnectorTest extends TestCase {
+
+ private static UnknownTrackableConnector getConnector() {
+ return new UnknownTrackableConnector();
+ }
+
+ public static void testCanHandleTrackable() throws Exception {
+ assertThat(getConnector().canHandleTrackable("TB1234")).isFalse();
+ }
+
+ public static void testGetUrl() throws Exception {
+ try {
+ getConnector().getUrl(new Trackable());
+ fail("IllegalStateException expected");
+ } catch (final IllegalStateException e) {
+ // empty
+ }
+ }
+
+ public static void testSearchTrackable() throws Exception {
+ assertThat(getConnector().searchTrackable("TB1234", null, null)).isNull();
+ }
+
+ public static void testIsLoggable() throws Exception {
+ assertThat(getConnector().isLoggable()).isFalse();
+ }
+
+ public static void testGetTrackableCodeFromUrl() throws Exception {
+ assertThat(getConnector().getTrackableCodeFromUrl("http://www.sometrackable.com/1234")).isNull();
+ }
+
+ public static void testGetUserActions() throws Exception {
+ assertThat(getConnector().getUserActions()).isEmpty();
+ }
+
+}