aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2015-02-13 23:10:47 +0100
committerBananeweizen <bananeweizen@gmx.de>2015-02-13 23:10:47 +0100
commit0b77441d721dbd444c0a4675978fecf753ad79f6 (patch)
tree281dc5950ab800412e36c23f619d09554d59c5ab
parent1d9a1922ca9ab563d686150ca20a153b20a378d7 (diff)
downloadcgeo-0b77441d721dbd444c0a4675978fecf753ad79f6.zip
cgeo-0b77441d721dbd444c0a4675978fecf753ad79f6.tar.gz
cgeo-0b77441d721dbd444c0a4675978fecf753ad79f6.tar.bz2
some more connector tests
-rw-r--r--main/src/cgeo/geocaching/connector/WaymarkingConnector.java17
-rw-r--r--tests/src/cgeo/geocaching/connector/WaymarkingConnectorTest.java21
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java3
-rw-r--r--tests/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnectorTest.java44
4 files changed, 84 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/connector/WaymarkingConnector.java b/main/src/cgeo/geocaching/connector/WaymarkingConnector.java
index 5a6f362..3361341 100644
--- a/main/src/cgeo/geocaching/connector/WaymarkingConnector.java
+++ b/main/src/cgeo/geocaching/connector/WaymarkingConnector.java
@@ -4,6 +4,7 @@ import cgeo.geocaching.Geocache;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
class WaymarkingConnector extends AbstractConnector {
@@ -41,4 +42,20 @@ class WaymarkingConnector extends AbstractConnector {
public boolean canHandle(@NonNull final String geocode) {
return StringUtils.startsWith(geocode, "WM");
}
+
+ @Override
+ @Nullable
+ public String getGeocodeFromUrl(@NonNull final String url) {
+ // coord.info URLs
+ String code = StringUtils.substringAfterLast(url, "coord.info/");
+ if (code != null && canHandle(code)) {
+ return code;
+ }
+ // waymarking URLs http://www.waymarking.com/waymarks/WMNCDT_American_Legion_Flagpole_1983_University_of_Oregon
+ code = StringUtils.substringBetween(url, "waymarks/", "_");
+ if (code != null && canHandle(code)) {
+ return code;
+ }
+ return null;
+ }
}
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/gc/GCConnectorTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
index 24f65fd..30a9af9 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
@@ -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/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();
+ }
+
+}