diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/cgeo/geocaching/connector/trackable/SwaggieConnectorTest.java | 29 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/connector/trackable/SwaggieParserTest.java | 34 |
2 files changed, 63 insertions, 0 deletions
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..1e63b1c --- /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 cacheUrl = ConnectorFactory.getTrackableConnector(trackableIn.getGeocode()).getUrl(trackableIn); + assertThat(cacheUrl).isNotNull(); + + final String page = Network.getResponseData(Network.getRequest(cacheUrl)); + 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"); + } +} |