diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/files')
6 files changed, 199 insertions, 191 deletions
diff --git a/tests/src/cgeo/geocaching/files/GPXImporterTest.java b/tests/src/cgeo/geocaching/files/GPXImporterTest.java index 6d7456c..02c997c 100644 --- a/tests/src/cgeo/geocaching/files/GPXImporterTest.java +++ b/tests/src/cgeo/geocaching/files/GPXImporterTest.java @@ -1,5 +1,7 @@ package cgeo.geocaching.files; +import static org.assertj.core.api.Assertions.assertThat; + import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; import cgeo.geocaching.SearchResult; @@ -46,16 +48,16 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { File gpx = new File(tempDir, gpxFileName); File wpts = new File(tempDir, wptsFileName); // the files need to exist - we create them - assertTrue(gpx.createNewFile()); - assertTrue(wpts.createNewFile()); + assertThat(gpx.createNewFile()).isTrue(); + assertThat(wpts.createNewFile()).isTrue(); // the "real" method check - assertEquals(wptsFileName, GPXImporter.getWaypointsFileNameForGpxFile(gpx)); + assertThat(GPXImporter.getWaypointsFileNameForGpxFile(gpx)).isEqualTo(wptsFileName); // they also need to be deleted, because of case sensitive tests that will not work correct on case insensitive file systems FileUtils.deleteQuietly(gpx); FileUtils.deleteQuietly(wpts); } final File gpx1 = new File(tempDir, "abc.gpx"); - assertNull(GPXImporter.getWaypointsFileNameForGpxFile(gpx1)); + assertThat(GPXImporter.getWaypointsFileNameForGpxFile(gpx1)).isNull(); } public void testImportGpx() throws IOException { @@ -67,18 +69,18 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { final GPXImporter.ImportGpxFileThread importThread = new GPXImporter.ImportGpxFileThread(gc31j2h, listId, importStepHandler, progressHandler); runImportThread(importThread); - assertEquals(4, importStepHandler.messages.size()); + assertThat(importStepHandler.messages).hasSize(4); final Iterator<Message> iMsg = importStepHandler.messages.iterator(); - assertEquals(GPXImporter.IMPORT_STEP_START, iMsg.next().what); - assertEquals(GPXImporter.IMPORT_STEP_READ_FILE, iMsg.next().what); - assertEquals(GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, iMsg.next().what); - assertEquals(GPXImporter.IMPORT_STEP_FINISHED, iMsg.next().what); + assertThat(iMsg.next().what).isEqualTo(GPXImporter.IMPORT_STEP_START); + assertThat(iMsg.next().what).isEqualTo(GPXImporter.IMPORT_STEP_READ_FILE); + assertThat(iMsg.next().what).isEqualTo(GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS); + assertThat(iMsg.next().what).isEqualTo(GPXImporter.IMPORT_STEP_FINISHED); final SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj; - assertEquals(Collections.singletonList(geocode), new ArrayList<String>(search.getGeocodes())); + assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList(geocode)); final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); assertCacheProperties(cache); - assertTrue(cache.getWaypoints().isEmpty()); + assertThat(cache.getWaypoints().isEmpty()).isTrue(); } public void testImportOcGpx() throws IOException { @@ -90,18 +92,18 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { final GPXImporter.ImportGpxFileThread importThread = new GPXImporter.ImportGpxFileThread(ocddd2, listId, importStepHandler, progressHandler); runImportThread(importThread); - assertEquals(4, importStepHandler.messages.size()); + assertThat(importStepHandler.messages).hasSize(4); final Iterator<Message> iMsg = importStepHandler.messages.iterator(); - assertEquals(GPXImporter.IMPORT_STEP_START, iMsg.next().what); - assertEquals(GPXImporter.IMPORT_STEP_READ_FILE, iMsg.next().what); - assertEquals(GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, iMsg.next().what); - assertEquals(GPXImporter.IMPORT_STEP_FINISHED, iMsg.next().what); + assertThat(iMsg.next().what).isEqualTo(GPXImporter.IMPORT_STEP_START); + assertThat(iMsg.next().what).isEqualTo(GPXImporter.IMPORT_STEP_READ_FILE); + assertThat(iMsg.next().what).isEqualTo(GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS); + assertThat(iMsg.next().what).isEqualTo(GPXImporter.IMPORT_STEP_FINISHED); final SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj; - assertEquals(Collections.singletonList(geocode), new ArrayList<String>(search.getGeocodes())); + assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList(geocode)); final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); assertCacheProperties(cache); - assertEquals("Incorrect number of waypoints imported", 4, cache.getWaypoints().size()); + assertThat(cache.getWaypoints()).as("Number of imported waypoints").hasSize(4); } private void runImportThread(GPXImporter.ImportThread importThread) { @@ -124,10 +126,10 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_READ_WPT_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED); final SearchResult search = (SearchResult) importStepHandler.messages.get(4).obj; - assertEquals(Collections.singletonList("GC31J2H"), new ArrayList<String>(search.getGeocodes())); + assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList("GC31J2H")); final Geocache cache = DataStore.loadCache("GC31J2H", LoadFlags.LOAD_CACHE_OR_DB); assertCacheProperties(cache); - assertEquals(2, cache.getWaypoints().size()); + assertThat(cache.getWaypoints()).hasSize(2); } public void testImportGpxWithLowercaseNames() throws IOException { @@ -140,13 +142,13 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED); final Geocache cache = DataStore.loadCache("AID1", LoadFlags.LOAD_CACHE_OR_DB); assertCacheProperties(cache); - assertEquals("First Aid Station #1", cache.getName()); + assertThat(cache.getName()).isEqualTo("First Aid Station #1"); } private void assertImportStepMessages(int... importSteps) { - assertEquals(importSteps.length, importStepHandler.messages.size()); + assertThat(importStepHandler.messages).hasSize(importSteps.length); for (int i = 0; i < importSteps.length; i++) { - assertEquals(importSteps[i], importStepHandler.messages.get(i).what); + assertThat(importStepHandler.messages.get(i).what).isEqualTo(importSteps[i]); } } @@ -159,15 +161,15 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED); final SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj; - assertEquals(Collections.singletonList("OC5952"), new ArrayList<String>(search.getGeocodes())); + assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList("OC5952")); final Geocache cache = DataStore.loadCache("OC5952", LoadFlags.LOAD_CACHE_OR_DB); assertCacheProperties(cache); } private static void assertCacheProperties(Geocache cache) { - assertNotNull(cache); - assertFalse(cache.getLocation().startsWith(",")); - assertTrue(cache.isReliableLatLon()); + assertThat(cache).isNotNull(); + assertThat(cache.getLocation().startsWith(",")).isFalse(); + assertThat(cache.isReliableLatLon()).isTrue(); } public void testImportGpxError() throws IOException { @@ -201,11 +203,11 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED); final SearchResult search = (SearchResult) importStepHandler.messages.get(3).obj; - assertEquals(Collections.singletonList(geocode), new ArrayList<String>(search.getGeocodes())); + assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList(geocode)); final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); assertCacheProperties(cache); - assertTrue(cache.getWaypoints().isEmpty()); + assertThat(cache.getWaypoints().isEmpty()).isTrue(); } public void testImportGpxZip() throws IOException { @@ -219,10 +221,10 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_READ_WPT_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED); final SearchResult search = (SearchResult) importStepHandler.messages.get(4).obj; - assertEquals(Collections.singletonList(geocode), new ArrayList<String>(search.getGeocodes())); + assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList(geocode)); final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); assertCacheProperties(cache); - assertEquals(1, cache.getWaypoints().size()); // this is the original pocket query result without test waypoint + assertThat(cache.getWaypoints()).hasSize(1); // this is the original pocket query result without test waypoint } public void testImportGpxZipErr() throws IOException { @@ -245,10 +247,10 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { assertImportStepMessages(GPXImporter.IMPORT_STEP_START, GPXImporter.IMPORT_STEP_READ_FILE, GPXImporter.IMPORT_STEP_READ_WPT_FILE, GPXImporter.IMPORT_STEP_STORE_STATIC_MAPS, GPXImporter.IMPORT_STEP_FINISHED); final SearchResult search = (SearchResult) importStepHandler.messages.get(4).obj; - assertEquals(Collections.singletonList(geocode), new ArrayList<String>(search.getGeocodes())); + assertThat(new ArrayList<String>(search.getGeocodes())).isEqualTo(Collections.singletonList(geocode)); final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); assertCacheProperties(cache); - assertEquals(1, cache.getWaypoints().size()); // this is the original pocket query result without test waypoint + assertThat(cache.getWaypoints()).hasSize(1); // this is the original pocket query result without test waypoint } static class TestHandler extends CancellableHandler { @@ -285,11 +287,11 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { super.setUp(); final String globalTempDir = System.getProperty("java.io.tmpdir"); - assertTrue("java.io.tmpdir is not defined", StringUtils.isNotBlank(globalTempDir)); + assertThat(StringUtils.isNotBlank(globalTempDir)).overridingErrorMessage("java.io.tmpdir is not defined").isTrue(); tempDir = new File(globalTempDir, "cgeogpxesTest"); cgeo.geocaching.utils.FileUtils.mkdirs(tempDir); - assertTrue("Could not create directory " + tempDir.getPath(), tempDir.exists()); + assertThat(tempDir).overridingErrorMessage("Could not create directory %s", tempDir.getPath()).exists(); // workaround to get storage initialized DataStore.getAllHistoryCachesCount(); listId = DataStore.createList("cgeogpxesTest"); diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java index 9297819..4cd0b6f 100644 --- a/tests/src/cgeo/geocaching/files/GPXParserTest.java +++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java @@ -1,5 +1,7 @@ package cgeo.geocaching.files; +import static org.assertj.core.api.Assertions.assertThat; + import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; import cgeo.geocaching.LogEntry; @@ -36,20 +38,20 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { private Geocache testGPXVersion(final int resourceId) throws IOException, ParserException { final List<Geocache> caches = readGPX10(resourceId); - assertNotNull(caches); - assertEquals(1, caches.size()); + assertThat(caches).isNotNull(); + assertThat(caches).hasSize(1); final Geocache cache = caches.get(0); - assertEquals("GC1BKP3", cache.getGeocode()); - assertEquals("9946f030-a514-46d8-a050-a60e92fd2e1a", cache.getGuid()); - assertEquals(CacheType.TRADITIONAL, cache.getType()); - assertEquals(false, cache.isArchived()); - assertEquals(false, cache.isDisabled()); - assertEquals("Die Schatzinsel / treasure island", cache.getName()); - assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerDisplayName()); - assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerUserId()); - assertEquals(CacheSize.MICRO, cache.getSize()); - assertEquals(1.0f, cache.getDifficulty()); - assertEquals(5.0f, cache.getTerrain()); + assertThat(cache.getGeocode()).isEqualTo("GC1BKP3"); + assertThat(cache.getGuid()).isEqualTo("9946f030-a514-46d8-a050-a60e92fd2e1a"); + assertThat(cache.getType()).isEqualTo(CacheType.TRADITIONAL); + assertThat(cache.isArchived()).isEqualTo(false); + assertThat(cache.isDisabled()).isEqualTo(false); + assertThat(cache.getName()).isEqualTo("Die Schatzinsel / treasure island"); + assertThat(cache.getOwnerDisplayName()).isEqualTo("Die unbesiegbaren Geo - Geparden"); + assertThat(cache.getOwnerUserId()).isEqualTo("Die unbesiegbaren Geo - Geparden"); + 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()); @@ -58,47 +60,47 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { public void testGPXVersion101() throws IOException, ParserException { final Geocache cache = testGPXVersion(R.raw.gc1bkp3_gpx101); - assertNotNull(cache.getAttributes()); - assertEquals(10, cache.getAttributes().size()); + assertThat(cache.getAttributes()).isNotNull(); + assertThat(cache.getAttributes()).hasSize(10); } public void testOC() throws IOException, ParserException { final List<Geocache> caches = readGPX10(R.raw.oc5952_gpx); final Geocache cache = caches.get(0); - assertEquals("OC5952", cache.getGeocode()); - assertEquals(CacheType.TRADITIONAL, cache.getType()); - assertEquals(false, cache.isArchived()); - assertEquals(false, cache.isDisabled()); - assertEquals("Die Schatzinsel / treasure island", cache.getName()); - assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerDisplayName()); - assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerUserId()); - assertEquals(CacheSize.SMALL, cache.getSize()); - assertEquals(1.0f, cache.getDifficulty()); - assertEquals(4.0f, cache.getTerrain()); + assertThat(cache.getGeocode()).isEqualTo("OC5952"); + assertThat(cache.getType()).isEqualTo(CacheType.TRADITIONAL); + assertThat(cache.isArchived()).isEqualTo(false); + assertThat(cache.isDisabled()).isEqualTo(false); + assertThat(cache.getName()).isEqualTo("Die Schatzinsel / treasure island"); + assertThat(cache.getOwnerDisplayName()).isEqualTo("Die unbesiegbaren Geo - Geparden"); + assertThat(cache.getOwnerUserId()).isEqualTo("Die unbesiegbaren Geo - Geparden"); + 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()); - assertTrue(cache.isReliableLatLon()); + assertThat(cache.isReliableLatLon()).isTrue(); } public void testGc31j2h() throws IOException, ParserException { removeCacheCompletely("GC31J2H"); final List<Geocache> caches = readGPX10(R.raw.gc31j2h); - assertEquals(1, caches.size()); + assertThat(caches).hasSize(1); final Geocache cache = caches.get(0); assertGc31j2h(cache); - assertSame(cache, caches.get(0)); + assertThat(caches.get(0)).isSameAs(cache); // no waypoints without importing waypoint file - assertEquals(0, cache.getWaypoints().size()); - assertTrue(cache.isReliableLatLon()); + assertThat(cache.getWaypoints()).isEmpty(); + assertThat(cache.isReliableLatLon()).isTrue(); } public void testGc31j2hWpts() throws IOException, ParserException { removeCacheCompletely("GC31J2H"); final List<Geocache> caches = readGPX10(R.raw.gc31j2h, R.raw.gc31j2h_wpts); - assertEquals(1, caches.size()); + assertThat(caches).hasSize(1); final Geocache cache = caches.get(0); assertGc31j2h(cache); assertGc31j2hWaypoints(cache); @@ -106,56 +108,56 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { public void testGc31j2hWptsWithoutCache() throws IOException, ParserException { final List<Geocache> caches = readGPX10(R.raw.gc31j2h_wpts); - assertEquals(0, caches.size()); + assertThat(caches).isEmpty(); } public static void testConvertWaypointSym2Type() { - assertEquals(WaypointType.WAYPOINT, GPXParser.convertWaypointSym2Type("unknown sym")); + assertThat(GPXParser.convertWaypointSym2Type("unknown sym")).isEqualTo(WaypointType.WAYPOINT); - assertEquals(WaypointType.PARKING, GPXParser.convertWaypointSym2Type("Parking area")); - assertEquals(WaypointType.STAGE, GPXParser.convertWaypointSym2Type("Stages of a multicache")); - assertEquals(WaypointType.PUZZLE, GPXParser.convertWaypointSym2Type("Question to answer")); - assertEquals(WaypointType.TRAILHEAD, GPXParser.convertWaypointSym2Type("Trailhead")); - assertEquals(WaypointType.FINAL, GPXParser.convertWaypointSym2Type("Final location")); - assertEquals(WaypointType.WAYPOINT, GPXParser.convertWaypointSym2Type("Reference point")); + assertThat(GPXParser.convertWaypointSym2Type("Parking area")).isEqualTo(WaypointType.PARKING); + assertThat(GPXParser.convertWaypointSym2Type("Stages of a multicache")).isEqualTo(WaypointType.STAGE); + assertThat(GPXParser.convertWaypointSym2Type("Question to answer")).isEqualTo(WaypointType.PUZZLE); + assertThat(GPXParser.convertWaypointSym2Type("Trailhead")).isEqualTo(WaypointType.TRAILHEAD); + assertThat(GPXParser.convertWaypointSym2Type("Final location")).isEqualTo(WaypointType.FINAL); + assertThat(GPXParser.convertWaypointSym2Type("Reference point")).isEqualTo(WaypointType.WAYPOINT); - assertEquals(WaypointType.PARKING, GPXParser.convertWaypointSym2Type(WaypointType.PARKING.getL10n())); + assertThat(GPXParser.convertWaypointSym2Type(WaypointType.PARKING.getL10n())).isEqualTo(WaypointType.PARKING); } private static void assertGc31j2h(final Geocache cache) { - assertEquals("GC31J2H", cache.getGeocode()); - assertEquals("Hockenheimer City-Brunnen", cache.getName()); - assertTrue("Hockenheimer City-Brunnen by vptsz, Multi-cache (2/1)", cache.getShortDescription().startsWith("Kurzer informativer Multi entlang der Brunnen")); - assertTrue(cache.getDescription().startsWith("Cachemobile können kostenfrei am Messplatz geparkt werden.")); - assertTrue(cache.hasTrackables()); + assertThat(cache.getGeocode()).isEqualTo("GC31J2H"); + assertThat(cache.getName()).isEqualTo("Hockenheimer City-Brunnen"); + assertThat(cache.getShortDescription()).startsWith("Kurzer informativer Multi entlang der Brunnen"); + assertThat(cache.getDescription()).startsWith("Cachemobile können kostenfrei am Messplatz geparkt werden."); + assertThat(cache.hasTrackables()).isTrue(); assertEquals(2.0f, cache.getDifficulty(), 0.01f); assertEquals(1.0f, cache.getTerrain(), 0.01f); final Geopoint refCoordinates = new Geopoint("N 49° 19.122", "E 008° 32.739"); - assertEquals(refCoordinates, cache.getCoords()); - assertEquals("vptsz", cache.getOwnerDisplayName()); - assertEquals("vptsz", cache.getOwnerUserId()); - assertEquals(CacheSize.SMALL, cache.getSize()); - assertEquals(CacheType.MULTI, cache.getType()); - assertFalse(cache.isArchived()); - assertFalse(cache.isDisabled()); - assertFalse(cache.isEventCache()); - assertFalse(cache.isPremiumMembersOnly()); - assertFalse(cache.isOwner()); - assertTrue(cache.isFound()); - assertEquals("Station3: Der zerbrochene Stein zählt doppelt.\nFinal: Oben neben dem Tor", cache.getHint()); + assertThat(cache.getCoords()).isEqualTo(refCoordinates); + assertThat(cache.getOwnerDisplayName()).isEqualTo("vptsz"); + assertThat(cache.getOwnerUserId()).isEqualTo("vptsz"); + assertThat(cache.getSize()).isEqualTo(CacheSize.SMALL); + assertThat(cache.getType()).isEqualTo(CacheType.MULTI); + assertThat(cache.isArchived()).isFalse(); + assertThat(cache.isDisabled()).isFalse(); + assertThat(cache.isEventCache()).isFalse(); + assertThat(cache.isPremiumMembersOnly()).isFalse(); + assertThat(cache.isOwner()).isFalse(); + assertThat(cache.isFound()).isTrue(); + assertThat(cache.getHint()).isEqualTo("Station3: Der zerbrochene Stein zählt doppelt.\nFinal: Oben neben dem Tor"); // logs - assertEquals(6, cache.getLogs().size()); + assertThat(cache.getLogs()).hasSize(6); final LogEntry log = cache.getLogs().get(5); - assertEquals("Geoteufel", log.author); - assertEquals(parseTime("2011-09-11T07:00:00Z"), log.date); - assertEquals(-1, log.found); + 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); - assertFalse(log.isOwn()); - assertEquals(log.log, log.getDisplayText()); - assertTrue(log.daysSinceLog() > 700); + assertThat(log.isOwn()).isFalse(); + assertThat(log.getDisplayText()).isEqualTo(log.log); + assertThat(log.daysSinceLog() > 700).isTrue(); // following info is not contained in pocket query gpx file - assertEquals(0, cache.getAttributes().size()); + assertThat(cache.getAttributes()).isEmpty(); } private static long parseTime(final String time) { @@ -167,25 +169,25 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { } private static void assertGc31j2hWaypoints(final Geocache cache) { - assertNotNull(cache.getWaypoints()); - assertEquals(2, cache.getWaypoints().size()); + assertThat(cache.getWaypoints()).isNotNull(); + assertThat(cache.getWaypoints()).hasSize(2); Waypoint wp = cache.getWaypoints().get(0); - assertEquals("GC31J2H", wp.getGeocode()); - assertEquals("00", wp.getPrefix()); - assertEquals("---", wp.getLookup()); - assertEquals("Parkplatz", wp.getName()); - assertEquals("Kostenfreies Parken (je nach Parkreihe Parkscheibe erforderlich)", wp.getNote()); - assertEquals(WaypointType.PARKING, wp.getWaypointType()); + assertThat(wp.getGeocode()).isEqualTo("GC31J2H"); + assertThat(wp.getPrefix()).isEqualTo("00"); + assertThat(wp.getLookup()).isEqualTo("---"); + assertThat(wp.getName()).isEqualTo("Parkplatz"); + assertThat(wp.getNote()).isEqualTo("Kostenfreies Parken (je nach Parkreihe Parkscheibe erforderlich)"); + assertThat(wp.getWaypointType()).isEqualTo(WaypointType.PARKING); assertEquals(49.317517, wp.getCoords().getLatitude(), 0.000001); assertEquals(8.545083, wp.getCoords().getLongitude(), 0.000001); wp = cache.getWaypoints().get(1); - assertEquals("GC31J2H", wp.getGeocode()); - assertEquals("S1", wp.getPrefix()); - assertEquals("---", wp.getLookup()); - assertEquals("Station 1", wp.getName()); + assertThat(wp.getGeocode()).isEqualTo("GC31J2H"); + 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()); - assertEquals(WaypointType.STAGE, wp.getWaypointType()); + assertThat(wp.getWaypointType()).isEqualTo(WaypointType.STAGE); assertEquals(49.317500, wp.getCoords().getLatitude(), 0.000001); assertEquals(8.545100, wp.getCoords().getLongitude(), 0.000001); } @@ -206,7 +208,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { final InputStream instream = getResourceStream(resourceId); try { Collection<Geocache> caches = parser.parse(instream, null); - assertNotNull(caches); + assertThat(caches).isNotNull(); for (Geocache cache : caches) { result.add(cache.getGeocode()); } @@ -232,24 +234,24 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { public void testSelfmadeGPXWithoutGeocodes() throws Exception { final List<Geocache> caches = readGPX11(R.raw.no_connector); - assertEquals(13, caches.size()); + assertThat(caches).hasSize(13); } public void testTexasChallenge2012() throws Exception { final List<Geocache> caches = readGPX10(R.raw.challenge); // previously these caches overwrote each other during parsing - assertEquals(130, caches.size()); + assertThat(caches).hasSize(130); } public void testGeoToad() throws Exception { final List<Geocache> caches = readGPX10(R.raw.geotoad); - assertEquals(2, caches.size()); + assertThat(caches).hasSize(2); final List<String> codes = new ArrayList<String>(); for (Geocache cache : caches) { codes.add(cache.getGeocode()); } - assertTrue(codes.contains("GC2KN6K")); - assertTrue(codes.contains("GC1T3MK")); + assertThat(codes.contains("GC2KN6K")).isTrue(); + assertThat(codes.contains("GC1T3MK")).isTrue(); } public void testLazyLogLoading() throws IOException, ParserException { @@ -257,14 +259,14 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { final String geocode = "GC31J2H"; removeCacheCompletely(geocode); final List<Geocache> caches = readGPX10(R.raw.lazy); - assertEquals(1, caches.size()); + assertThat(caches).hasSize(1); DataStore.removeAllFromCache(); // load only the minimum cache, it has several members missing final Geocache minimalCache = DataStore.loadCache(geocode, EnumSet.of(LoadFlag.LOAD_DB_MINIMAL)); // now check that we load lazy members on demand - assertFalse(minimalCache.getAttributes().isEmpty()); - assertFalse(minimalCache.getLogs().isEmpty()); + assertThat(minimalCache.getAttributes().isEmpty()).isFalse(); + assertThat(minimalCache.getLogs().isEmpty()).isFalse(); removeCacheCompletely(geocode); } @@ -275,27 +277,27 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { // first import List<Geocache> caches = readGPX10(R.raw.lazy); - assertEquals(1, caches.size()); - assertEquals(6, caches.get(0).getLogs().size()); + assertThat(caches).hasSize(1); + assertThat(caches.get(0).getLogs()).hasSize(6); // second import caches = readGPX10(R.raw.lazy); - assertEquals(1, caches.size()); - assertEquals(6, caches.get(0).getLogs().size()); + assertThat(caches).hasSize(1); + assertThat(caches.get(0).getLogs()).hasSize(6); removeCacheCompletely(geocode); } public void testWaymarking() throws Exception { final List<Geocache> caches = readGPX10(R.raw.waymarking_gpx); - assertEquals(1, caches.size()); + assertThat(caches).hasSize(1); final Geocache waymark = caches.get(0); - assertNotNull(waymark); - assertEquals("WM7BM7", waymark.getGeocode()); - assertEquals("Roman water pipe Kornwestheim", waymark.getName()); - assertTrue(StringUtils.isNotBlank(waymark.getUrl())); // connector must be able to create it - assertEquals(CacheType.UNKNOWN, waymark.getType()); - assertEquals(CacheSize.UNKNOWN, waymark.getSize()); + 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.getType()).isEqualTo(CacheType.UNKNOWN); + assertThat(waymark.getSize()).isEqualTo(CacheSize.UNKNOWN); } /** @@ -303,49 +305,49 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { */ public void testGCTour() throws Exception { final List<Geocache> caches = readGPX10(R.raw.gctour_gpx); - assertEquals(54, caches.size()); + assertThat(caches).hasSize(54); } public void testOX() throws IOException, ParserException { final List<Geocache> caches = readGPX10(R.raw.ox1ry0y_gpx); - assertEquals(1, caches.size()); + assertThat(caches).hasSize(1); final Geocache cache = caches.get(0); - assertEquals("OX1RY0Y", cache.getGeocode()); - assertEquals(CacheType.TRADITIONAL, cache.getType()); - assertEquals(false, cache.isArchived()); - assertEquals(false, cache.isDisabled()); - assertEquals("Kornwestheim und die Römer", cache.getName()); - assertEquals("Thomas&Dani", cache.getOwnerDisplayName()); - assertEquals(CacheSize.SMALL, cache.getSize()); - assertEquals(1.5f, cache.getDifficulty()); - assertEquals(1.0f, cache.getTerrain()); - assertTrue(cache.getDescription().startsWith("Dieses sind die Reste einer in Kornwestheim gefundenen")); + assertThat(cache.getGeocode()).isEqualTo("OX1RY0Y"); + assertThat(cache.getType()).isEqualTo(CacheType.TRADITIONAL); + assertThat(cache.isArchived()).isEqualTo(false); + assertThat(cache.isDisabled()).isEqualTo(false); + assertThat(cache.getName()).isEqualTo("Kornwestheim und die Römer"); + assertThat(cache.getOwnerDisplayName()).isEqualTo("Thomas&Dani"); + assertThat(cache.getSize()).isEqualTo(CacheSize.SMALL); + 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()); - assertTrue(cache.isReliableLatLon()); - assertEquals("Wasserleitung", cache.getHint()); + assertThat(cache.isReliableLatLon()).isTrue(); + assertThat(cache.getHint()).isEqualTo("Wasserleitung"); } private Geocache getFirstCache(int gpxResourceId) throws IOException, ParserException { final List<Geocache> caches = readGPX10(gpxResourceId); - assertNotNull(caches); - assertEquals(1, caches.size()); + assertThat(caches).isNotNull(); + assertThat(caches).hasSize(1); final Geocache cache = caches.get(0); return cache; } public void testGsakFavPoints() throws IOException, ParserException { final Geocache cache = getFirstCache(R.raw.gc3t1xg_gsak); - assertEquals(258, cache.getFavoritePoints()); + assertThat(cache.getFavoritePoints()).isEqualTo(258); } public void testGsakPersonalNote() throws IOException, ParserException { final Geocache cache = getFirstCache(R.raw.gc3t1xg_gsak); - assertEquals("Personal Note Test", cache.getPersonalNote()); + assertThat(cache.getPersonalNote()).isEqualTo("Personal Note Test"); } public void testGsakPremium() throws IOException, ParserException { final Geocache cache = getFirstCache(R.raw.gc3t1xg_gsak); - assertTrue(cache.isPremiumMembersOnly()); + assertThat(cache.isPremiumMembersOnly()).isTrue(); } } diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java index 3039a1f..d87b593 100644 --- a/tests/src/cgeo/geocaching/files/LocParserTest.java +++ b/tests/src/cgeo/geocaching/files/LocParserTest.java @@ -1,5 +1,7 @@ package cgeo.geocaching.files; +import static org.assertj.core.api.Assertions.assertThat; + import cgeo.geocaching.Geocache; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; @@ -20,8 +22,8 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase { final InputStream instream = getResourceStream(resourceId); try { caches = parser.parse(instream, null); - assertNotNull(caches); - assertTrue(caches.size() > 0); + assertThat(caches).isNotNull(); + assertThat(caches.size() > 0).isTrue(); } finally { instream.close(); } @@ -31,42 +33,42 @@ public class LocParserTest extends AbstractResourceInstrumentationTestCase { public void testOCLoc() throws IOException, ParserException { final List<Geocache> caches = readLoc(R.raw.oc5952_loc); - assertEquals(1, caches.size()); + assertThat(caches).hasSize(1); final Geocache cache = caches.get(0); - assertNotNull(cache); - assertEquals("OC5952", cache.getGeocode()); - assertEquals("Die Schatzinsel / treasure island", cache.getName()); - assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerUserId()); + assertThat(cache).isNotNull(); + assertThat(cache.getGeocode()).isEqualTo("OC5952"); + assertThat(cache.getName()).isEqualTo("Die Schatzinsel / treasure island"); + assertThat(cache.getOwnerUserId()).isEqualTo("Die unbesiegbaren Geo - Geparden"); assertEquals(new Geopoint(48.85968, 9.18740), cache.getCoords()); } public void testGCLoc() throws IOException, ParserException { final List<Geocache> caches = readLoc(R.raw.gc1bkp3_loc); - assertEquals(1, caches.size()); + assertThat(caches).hasSize(1); final Geocache cache = caches.get(0); - assertNotNull(cache); - assertEquals("GC1BKP3", cache.getGeocode()); - assertEquals("Die Schatzinsel / treasure island", cache.getName()); - assertEquals("Die unbesiegbaren Geo - Geparden", cache.getOwnerUserId()); + assertThat(cache).isNotNull(); + assertThat(cache.getGeocode()).isEqualTo("GC1BKP3"); + assertThat(cache.getName()).isEqualTo("Die Schatzinsel / treasure island"); + assertThat(cache.getOwnerUserId()).isEqualTo("Die unbesiegbaren Geo - Geparden"); assertEquals(new Geopoint(48.859683, 9.1874), cache.getCoords()); - assertEquals(1.0f, cache.getDifficulty()); - assertEquals(5.0f, cache.getTerrain()); - assertEquals(CacheSize.MICRO, cache.getSize()); + assertThat(cache.getDifficulty()).isEqualTo(1.0f); + assertThat(cache.getTerrain()).isEqualTo(5.0f); + assertThat(cache.getSize()).isEqualTo(CacheSize.MICRO); } public void testWaymarkingLoc() throws IOException, ParserException { final List<Geocache> waymarks = readLoc(R.raw.waymarking_loc); - assertEquals(1, waymarks.size()); + assertThat(waymarks).hasSize(1); final Geocache waymark = waymarks.get(0); - assertNotNull(waymark); - assertEquals("WM7BK7", waymark.getGeocode()); - assertEquals("Römerstrasse Kornwestheim", waymark.getName()); - assertEquals("travelling", waymark.getOwnerUserId()); + assertThat(waymark).isNotNull(); + assertThat(waymark.getGeocode()).isEqualTo("WM7BK7"); + assertThat(waymark.getName()).isEqualTo("Römerstrasse Kornwestheim"); + assertThat(waymark.getOwnerUserId()).isEqualTo("travelling"); assertEquals(new Geopoint(48.856733, 9.197683), waymark.getCoords()); // links are not yet stored for single caches - // assertEquals("http://www.waymarking.com/waymarks/WM7BK7_Rmerstrasse_Kornwestheim", waymark.getUrl()); - assertEquals(CacheSize.UNKNOWN, waymark.getSize()); - assertEquals(CacheType.UNKNOWN, waymark.getType()); + // assertThat(waymark.getUrl()).isEqualTo("http://www.waymarking.com/waymarks/WM7BK7_Rmerstrasse_Kornwestheim"); + assertThat(waymark.getSize()).isEqualTo(CacheSize.UNKNOWN); + assertThat(waymark.getType()).isEqualTo(CacheType.UNKNOWN); } } diff --git a/tests/src/cgeo/geocaching/files/LocalStorageTest.java b/tests/src/cgeo/geocaching/files/LocalStorageTest.java index 8405899..4142188 100644 --- a/tests/src/cgeo/geocaching/files/LocalStorageTest.java +++ b/tests/src/cgeo/geocaching/files/LocalStorageTest.java @@ -1,18 +1,16 @@ package cgeo.geocaching.files; -import cgeo.geocaching.files.LocalStorage; +import static org.assertj.core.api.Assertions.assertThat; import android.test.AndroidTestCase; -import junit.framework.Assert; - public class LocalStorageTest extends AndroidTestCase { public static void testGetExtension() { - Assert.assertEquals("", LocalStorage.getExtension("foo/bar/xyzzy")); - Assert.assertEquals(".jpg", LocalStorage.getExtension("foo/bar/xyzzy.jpg")); - Assert.assertEquals(".jpeg", LocalStorage.getExtension("foo/bar/xyzzy.jpeg")); - Assert.assertEquals("", LocalStorage.getExtension("foo/bar/xyzzy.mjpeg")); + assertThat(LocalStorage.getExtension("foo/bar/xyzzy")).isEqualTo(""); + assertThat(LocalStorage.getExtension("foo/bar/xyzzy.jpg")).isEqualTo(".jpg"); + assertThat(LocalStorage.getExtension("foo/bar/xyzzy.jpeg")).isEqualTo(".jpeg"); + assertThat(LocalStorage.getExtension("foo/bar/xyzzy.mjpeg")).isEqualTo(""); } } diff --git a/tests/src/cgeo/geocaching/files/ProgressInputStreamTest.java b/tests/src/cgeo/geocaching/files/ProgressInputStreamTest.java index e2ef2ba..a0aaa68 100644 --- a/tests/src/cgeo/geocaching/files/ProgressInputStreamTest.java +++ b/tests/src/cgeo/geocaching/files/ProgressInputStreamTest.java @@ -1,5 +1,7 @@ package cgeo.geocaching.files; +import static org.assertj.core.api.Assertions.assertThat; + import org.apache.commons.io.IOUtils; import junit.framework.TestCase; @@ -8,14 +10,14 @@ public class ProgressInputStreamTest extends TestCase { public static void testRead() throws Exception { ProgressInputStream stream = new ProgressInputStream(IOUtils.toInputStream("test")); - assertEquals(0, stream.getProgress()); + assertThat(stream.getProgress()).isEqualTo(0); int bytesRead = 0; while (stream.read() >= 0 && bytesRead < 10000) { bytesRead++; } - assertEquals(4, bytesRead); - assertEquals(4, stream.getProgress()); + assertThat(bytesRead).isEqualTo(4); + assertThat(stream.getProgress()).isEqualTo(4); IOUtils.closeQuietly(stream); } diff --git a/tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java b/tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java index 7607ad0..d8d099d 100644 --- a/tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java +++ b/tests/src/cgeo/geocaching/files/SimpleDirChooserUITest.java @@ -1,5 +1,7 @@ package cgeo.geocaching.files; +import static org.assertj.core.api.Assertions.assertThat; + import cgeo.geocaching.Intents; import com.robotium.solo.Solo; @@ -47,8 +49,8 @@ public class SimpleDirChooserUITest extends ActivityInstrumentationTestCase2<Sim final int lastIndex = getCurrentCheckBoxes().size() - 1; solo.clickOnCheckBox(lastIndex); - assertTrue(solo.isCheckBoxChecked(lastIndex)); - assertFalse(solo.isCheckBoxChecked(0)); + assertThat(solo.isCheckBoxChecked(lastIndex)).isTrue(); + assertThat(solo.isCheckBoxChecked(0)).isFalse(); assertChecked("Clicked last checkbox", 1); solo.scrollUp(); @@ -61,10 +63,10 @@ public class SimpleDirChooserUITest extends ActivityInstrumentationTestCase2<Sim pause(); solo.clickOnCheckBox(0); assertChecked("Clicked first checkbox", 1); - assertTrue(solo.isCheckBoxChecked(0)); + assertThat(solo.isCheckBoxChecked(0)).isTrue(); solo.clickOnCheckBox(1); assertChecked("Clicked second checkbox", 1); - assertTrue(solo.isCheckBoxChecked(1)); + assertThat(solo.isCheckBoxChecked(1)).isTrue(); } private static void pause() throws InterruptedException { @@ -73,8 +75,8 @@ public class SimpleDirChooserUITest extends ActivityInstrumentationTestCase2<Sim private void assertChecked(String message, int expectedChecked) { final ArrayList<CheckBox> boxes = getCurrentCheckBoxes(); - assertNotNull("Could not get checkboxes", boxes); - assertTrue("There are no checkboxes", boxes.size() > 1); + assertThat(boxes).as("Checkboxes").isNotNull(); + assertThat(boxes.size()).as("number of checkboxes").isGreaterThan(1); int checked = 0; for (int i = 0; i < boxes.size(); i++) { if (solo.isCheckBoxChecked(i)) { |
