diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2012-05-05 10:31:30 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2012-05-05 10:31:30 +0200 |
| commit | 057f24b4f57dadeeba92a04c83e3bcd790e983b1 (patch) | |
| tree | 23464d3fd6a16c6ede3206bc39ed4b2e16d0419c /tests/src/cgeo/geocaching/connector/gc | |
| parent | 84c6bd6cc358b2cde2926a62990e4c151c47d6d1 (diff) | |
| download | cgeo-057f24b4f57dadeeba92a04c83e3bcd790e983b1.zip cgeo-057f24b4f57dadeeba92a04c83e3bcd790e983b1.tar.gz cgeo-057f24b4f57dadeeba92a04c83e3bcd790e983b1.tar.bz2 | |
refactoring: more cleanup in connector interfaces
* switch from method overrides to interface detection for connector
features
* remove GCBase and put code into other classes
* reduce GC specific code being used in general activities
Diffstat (limited to 'tests/src/cgeo/geocaching/connector/gc')
3 files changed, 88 insertions, 9 deletions
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java b/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java index 88873a1..91ff2f9 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java @@ -22,20 +22,19 @@ public class GCBaseTest extends TestCase { } private static void assertKey(String key, int x, int y) { - UTFGridPosition pos = UTFGridPosition.fromString(key); + final UTFGridPosition pos = UTFGridPosition.fromString(key); assertEquals(x, pos.getX()); assertEquals(y, pos.getY()); } - public static void testSearchByGeocodes() { + public static void testSearchFromMap() { + final MockedCache mockedCache = new GC2CJPF(); - MockedCache mockedCache = new GC2CJPF(); - - Set<String> geocodes = new HashSet<String>(); + final Set<String> geocodes = new HashSet<String>(); geocodes.add(mockedCache.getGeocode()); - SearchResult result = GCBase.searchByGeocodes(geocodes); - cgCache parsedCache = result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY); + final SearchResult result = GCMap.searchByGeocodes(geocodes); + final cgCache parsedCache = result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY); Compare.assertCompareCaches(mockedCache, parsedCache, false); diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java index f85a697..065589b 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java @@ -11,7 +11,7 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase { public static void testGetViewport() { Login.login(); - String[] tokens = GCBase.getTokens(); + String[] tokens = Login.getMapTokens(); { final Viewport viewport = new Viewport(new Geopoint("N 52° 25.369 E 9° 35.499"), new Geopoint("N 52° 25.600 E 9° 36.200")); @@ -31,7 +31,7 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase { } public static void testBaseCodings() { - assertEquals(2045702, GCBase.gccodeToGCId("GC2MEGA")); + assertEquals(2045702, GCConstants.gccodeToGCId("GC2MEGA")); } /** Tile computation with different zoom levels */ diff --git a/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java b/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java new file mode 100644 index 0000000..ace7c7a --- /dev/null +++ b/tests/src/cgeo/geocaching/connector/gc/TrackablesTest.java @@ -0,0 +1,80 @@ +package cgeo.geocaching.connector.gc; + +import cgeo.geocaching.LogEntry; +import cgeo.geocaching.TrackableLog; +import cgeo.geocaching.cgTrackable; +import cgeo.geocaching.connector.gc.GCParser; +import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; +import cgeo.geocaching.test.R; +import cgeo.geocaching.utils.BaseUtils; + +import java.util.List; + +public class TrackablesTest extends AbstractResourceInstrumentationTestCase { + + public void testLogPageWithTrackables() { + List<TrackableLog> tbLogs = GCParser.parseTrackableLog(getFileContent(R.raw.log_with_2tb)); + assertNotNull(tbLogs); + assertEquals(2, tbLogs.size()); + TrackableLog log = tbLogs.get(0); + assertEquals("Steffen's Kaiserwagen", log.name); + assertEquals("1QG1EE", log.trackCode); + } + + public void testLogPageWithoutTrackables() { + List<TrackableLog> tbLogs = GCParser.parseTrackableLog(getFileContent(R.raw.log_without_tb)); + assertNotNull(tbLogs); + assertEquals(0, tbLogs.size()); + } + + public void testTrackable() { + final cgTrackable trackable = getTB2R124(); + assertEquals("TB2R124", trackable.getGeocode()); + assertEquals("Bor. Dortmund - FC Schalke 04", trackable.getName()); + assertEquals("Spiridon Lui", trackable.getOwner()); + } + + public void testTrackableWithoutImage() { + final cgTrackable trackable = getTB2R124(); + assertNull(trackable.getImage()); + assertNotNull(trackable.getDetails()); + } + + public void testTrackableWithLogImages() { + final cgTrackable trackable = getTBXATG(); + assertEquals("TBXATG", trackable.getGeocode()); + + List<LogEntry> log = trackable.getLogs(); + // second log entry has several images; just check first two + assertEquals("http://img.geocaching.com/track/log/large/f2e24c50-394c-4d74-8fb4-87298d8bff1d.jpg", log.get(1).getLogImages().get(0).getUrl()); + assertEquals("7b Welcome to Geowoodstock", log.get(1).getLogImages().get(0).getTitle()); + assertEquals("http://img.geocaching.com/track/log/large/b57c29c3-134e-4202-a2a1-69ce8920b055.jpg", log.get(1).getLogImages().get(1).getUrl()); + assertEquals("8 Crater Lake Natl Park Oregon", log.get(1).getLogImages().get(1).getTitle()); + + // third log entry has one image + assertEquals("http://img.geocaching.com/track/log/large/0096b42d-4d10-45fa-9be2-2d08c0d5cc61.jpg", log.get(2).getLogImages().get(0).getUrl()); + assertEquals("Traverski's GC Univ coin on tour", log.get(2).getLogImages().get(0).getTitle()); + } + + public void testParseTrackableWithoutReleaseDate() { + cgTrackable trackable = GCParser.parseTrackable(getFileContent(R.raw.tb14wfv), null); + assertNotNull(trackable); + assertEquals("The Brickster", trackable.getName()); + assertEquals("Adrian C", trackable.getOwner()); + assertTrue(trackable.getGoal().startsWith("I'm on the run from the law.")); + assertTrue(trackable.getGoal().endsWith("what I've seen.")); + assertTrue(trackable.getDistance() >= 11663.5f); + // the next two items are normally available for trackables, but not for this one, so explicitly test for null + assertNull(trackable.getReleased()); + assertNull(trackable.getOrigin()); + } + + private cgTrackable getTB2R124() { + return GCParser.parseTrackable(BaseUtils.replaceWhitespace(getFileContent(R.raw.trackable_tb2r124)), null); + } + + private cgTrackable getTBXATG() { + return GCParser.parseTrackable(BaseUtils.replaceWhitespace(getFileContent(R.raw.trackable_tbxatg)), null); + } + +} |
