diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2015-04-28 20:53:43 +0200 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2015-04-28 20:53:43 +0200 |
commit | 9a262f37a252105e77760ea2e9415ad712e2da93 (patch) | |
tree | 5c8e092e78dfb53db553b94d883b1efe1fb91909 | |
parent | aa87f3d65d1afe46c4002a2ff3986a7ba28f92c4 (diff) | |
download | cgeo-9a262f37a252105e77760ea2e9415ad712e2da93.zip cgeo-9a262f37a252105e77760ea2e9415ad712e2da93.tar.gz cgeo-9a262f37a252105e77760ea2e9415ad712e2da93.tar.bz2 |
refactoring: use more AssertJ API
28 files changed, 143 insertions, 179 deletions
diff --git a/tests/src/cgeo/geocaching/CgeoApplicationTest.java b/tests/src/cgeo/geocaching/CgeoApplicationTest.java index 6763d7b..dd4d554 100644 --- a/tests/src/cgeo/geocaching/CgeoApplicationTest.java +++ b/tests/src/cgeo/geocaching/CgeoApplicationTest.java @@ -115,8 +115,7 @@ public class CgeoApplicationTest extends CGeoTestCase { final SearchResult search = Geocache.searchByGeocode(geocode, null, 0, true, null); assertThat(search).isNotNull(); if (Settings.isGCPremiumMember() || search.getError() == null) { - assertThat(search.getGeocodes()).hasSize(1); - assertThat(search.getGeocodes()).contains(geocode); + assertThat(search.getGeocodes()).containsExactly(geocode); return DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); } assertThat(search.getGeocodes()).isEmpty(); @@ -167,8 +166,7 @@ public class CgeoApplicationTest extends CGeoTestCase { SearchResult search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST.id, true, null); assertThat(search).isNotNull(); - assertThat(search.getGeocodes()).hasSize(1); - assertThat(search.getGeocodes().contains(cache.getGeocode())).isTrue(); + assertThat(search.getGeocodes()).containsExactly(cache.getGeocode()); final Geocache searchedCache = search.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); // coords must be null if the user is not logged in assertThat(searchedCache).isNotNull(); @@ -241,8 +239,8 @@ public class CgeoApplicationTest extends CGeoTestCase { public void run() { final SearchResult search = GCParser.searchByCoords(new Geopoint("N 50° 06.654 E 008° 39.777"), CacheType.MYSTERY, false, null); assertThat(search).isNotNull(); - assertThat(20 <= search.getGeocodes().size()).isTrue(); - assertThat(search.getGeocodes().contains("GC1HBMY")).isTrue(); + assertThat(search.getGeocodes().size()).isGreaterThanOrEqualTo(20); + assertThat(search.getGeocodes()).contains("GC1HBMY"); } }); } @@ -259,7 +257,7 @@ public class CgeoApplicationTest extends CGeoTestCase { final SearchResult search = GCParser.searchByOwner("blafoo", CacheType.MYSTERY, false, null); assertThat(search).isNotNull(); assertThat(search.getGeocodes()).hasSize(3); - assertThat(search.getGeocodes().contains("GC36RT6")).isTrue(); + assertThat(search.getGeocodes()).contains("GC36RT6"); } }); } @@ -276,7 +274,7 @@ public class CgeoApplicationTest extends CGeoTestCase { final SearchResult search = GCParser.searchByUsername("blafoo", CacheType.WEBCAM, false, null); assertThat(search).isNotNull(); assertThat(search.getTotalCountGC()).isEqualTo(5); - assertThat(search.getGeocodes().contains("GCP0A9")).isTrue(); + assertThat(search.getGeocodes()).contains("GCP0A9"); } }); } @@ -309,7 +307,7 @@ public class CgeoApplicationTest extends CGeoTestCase { Settings.setLiveMapStrategy(LivemapStrategy.DETAILED); SearchResult search = ConnectorFactory.searchByViewport(viewport, tokens); assertThat(search).isNotNull(); - assertThat(search.getGeocodes().contains(mockedCache.getGeocode())).isTrue(); + assertThat(search.getGeocodes()).contains(mockedCache.getGeocode()); Geocache parsedCache = DataStore.loadCache(mockedCache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB); assert parsedCache != null; assertThat(parsedCache).isNotNull(); @@ -323,7 +321,7 @@ public class CgeoApplicationTest extends CGeoTestCase { search = ConnectorFactory.searchByViewport(viewport, tokens); assertThat(search).isNotNull(); - assertThat(search.getGeocodes().contains(mockedCache.getGeocode())).isTrue(); + assertThat(search.getGeocodes()).contains(mockedCache.getGeocode()); parsedCache = DataStore.loadCache(mockedCache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB); assert parsedCache != null; assertThat(parsedCache).isNotNull(); @@ -366,7 +364,7 @@ public class CgeoApplicationTest extends CGeoTestCase { SearchResult search = ConnectorFactory.searchByViewport(viewport, INVALID_TOKEN); assertThat(search).isNotNull(); - assertThat(search.getGeocodes().contains(cache.getGeocode())).isTrue(); + assertThat(search.getGeocodes()).contains(cache.getGeocode()); // coords differ final Geocache cacheFromViewport = DataStore.loadCache(cache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB); assert cacheFromViewport != null; @@ -386,7 +384,7 @@ public class CgeoApplicationTest extends CGeoTestCase { assertThat(search).isNotNull(); // In the meantime, premium-member caches are also shown on map when not logged in - assertThat(search.getGeocodes().contains(cache.getGeocode())).isTrue(); + assertThat(search.getGeocodes()).contains(cache.getGeocode()); } finally { Settings.setLiveMapStrategy(strategy); diff --git a/tests/src/cgeo/geocaching/DataStoreTest.java b/tests/src/cgeo/geocaching/DataStoreTest.java index 9ef5dda..0177ad9 100644 --- a/tests/src/cgeo/geocaching/DataStoreTest.java +++ b/tests/src/cgeo/geocaching/DataStoreTest.java @@ -39,10 +39,10 @@ public class DataStoreTest extends CGeoTestCase { // create lists listId1 = DataStore.createList("DataStore Test"); - assertThat(listId1 > StoredList.STANDARD_LIST_ID).isTrue(); + assertThat(listId1).isGreaterThan(StoredList.STANDARD_LIST_ID); listId2 = DataStore.createList("DataStoreTest"); - assertThat(listId2 > StoredList.STANDARD_LIST_ID).isTrue(); - assertThat(DataStore.getLists().size() >= 2).isTrue(); + assertThat(listId2).isGreaterThan(StoredList.STANDARD_LIST_ID); + assertThat(DataStore.getLists().size()).isGreaterThanOrEqualTo(2); cache1.setDetailed(true); cache1.setListId(listId1); @@ -52,7 +52,7 @@ public class DataStoreTest extends CGeoTestCase { // save caches to DB (cache1=listId1, cache2=listId1) DataStore.saveCache(cache1, LoadFlags.SAVE_ALL); DataStore.saveCache(cache2, LoadFlags.SAVE_ALL); - assertThat(DataStore.getAllCachesCount() >= 2).isTrue(); + assertThat(DataStore.getAllCachesCount()).isGreaterThanOrEqualTo(2); // rename list (cache1=listId1, cache2=listId1) assertEquals(1, DataStore.renameList(listId1, "DataStore Test (renamed)")); @@ -173,8 +173,8 @@ public class DataStoreTest extends CGeoTestCase { public static void testLoadCacheHistory() { int sumCaches = 0; int allCaches = 0; - for (CacheType cacheType : CacheType.values()) { - SearchResult historyOfType = DataStore.getHistoryOfCaches(false, cacheType); + for (final CacheType cacheType : CacheType.values()) { + final SearchResult historyOfType = DataStore.getHistoryOfCaches(false, cacheType); assertThat(historyOfType).isNotNull(); if (cacheType != CacheType.ALL) { sumCaches += historyOfType.getCount(); @@ -221,13 +221,9 @@ public class DataStoreTest extends CGeoTestCase { final SearchResult search = new SearchResult(main); - Set<String> filteredGeoCodes = DataStore.getCachedMissingFromSearch(search, tiles, GCConnector.getInstance(), Tile.ZOOMLEVEL_MIN_PERSONALIZED - 1); - - assertThat(filteredGeoCodes.contains(inTileLowZoom.getGeocode())).isTrue(); - assertThat(filteredGeoCodes.contains(inTileHighZoom.getGeocode())).isFalse(); - assertThat(filteredGeoCodes.contains(otherConnector.getGeocode())).isFalse(); - assertThat(filteredGeoCodes.contains(outTile.getGeocode())).isFalse(); - assertThat(filteredGeoCodes.contains(main.getGeocode())).isFalse(); + final Set<String> filteredGeoCodes = DataStore.getCachedMissingFromSearch(search, tiles, GCConnector.getInstance(), Tile.ZOOMLEVEL_MIN_PERSONALIZED - 1); + assertThat(filteredGeoCodes).contains(inTileLowZoom.getGeocode()); + assertThat(filteredGeoCodes).doesNotContain(inTileHighZoom.getGeocode(), otherConnector.getGeocode(), outTile.getGeocode(), main.getGeocode()); } } diff --git a/tests/src/cgeo/geocaching/SearchResultTest.java b/tests/src/cgeo/geocaching/SearchResultTest.java index ffc024d..20ce29d 100644 --- a/tests/src/cgeo/geocaching/SearchResultTest.java +++ b/tests/src/cgeo/geocaching/SearchResultTest.java @@ -16,7 +16,7 @@ public class SearchResultTest extends AndroidTestCase { final SearchResult searchResult = new SearchResult(geocodes); assertThat(searchResult.getCount()).isEqualTo(2); assertThat(searchResult.getTotalCountGC()).isEqualTo(2); - assertThat(searchResult.getGeocodes().contains("GC12345")).isTrue(); + assertThat(searchResult.getGeocodes()).contains("GC12345"); } public static void testParcel() { @@ -30,7 +30,7 @@ public class SearchResultTest extends AndroidTestCase { geocodes.add("GC56789"); search.addFilteredGeocodes(geocodes); - Parcel parcel = Parcel.obtain(); + final Parcel parcel = Parcel.obtain(); search.writeToParcel(parcel, 0); // reset to ready for reading parcel.setDataPosition(0); @@ -42,11 +42,9 @@ public class SearchResultTest extends AndroidTestCase { assertThat(receive.getCount()).isEqualTo(3); assertThat(receive.getFilteredGeocodes()).hasSize(2); - assertThat(receive.getGeocodes().contains("GC12345")).isTrue(); - assertThat(receive.getGeocodes().contains("GC45678")).isFalse(); + assertThat(receive.getGeocodes()).contains("GC12345").doesNotContain("GC45678"); - assertThat(receive.getFilteredGeocodes().contains("GC12345")).isFalse(); - assertThat(receive.getFilteredGeocodes().contains("GC45678")).isTrue(); + assertThat(receive.getFilteredGeocodes()).contains("GC45678").doesNotContain("GC12345"); } public static void testAddSearchResult() { @@ -67,11 +65,8 @@ public class SearchResultTest extends AndroidTestCase { assertThat(newSearch.getCount()).isEqualTo(4); assertThat(newSearch.getFilteredGeocodes()).hasSize(2); - assertThat(newSearch.getGeocodes().contains("GC12345")).isTrue(); - assertThat(newSearch.getGeocodes().contains("GC01234")).isTrue(); - assertThat(newSearch.getGeocodes().contains("GC45678")).isFalse(); + assertThat(newSearch.getGeocodes()).contains("GC12345", "GC01234").doesNotContain("GC45678"); - assertThat(newSearch.getFilteredGeocodes().contains("GC12345")).isFalse(); - assertThat(newSearch.getFilteredGeocodes().contains("GC45678")).isTrue(); + assertThat(newSearch.getFilteredGeocodes()).contains("GC45678").doesNotContain("GC12345"); } } diff --git a/tests/src/cgeo/geocaching/WaypointTest.java b/tests/src/cgeo/geocaching/WaypointTest.java index 9e14146..fe98a86 100644 --- a/tests/src/cgeo/geocaching/WaypointTest.java +++ b/tests/src/cgeo/geocaching/WaypointTest.java @@ -38,8 +38,8 @@ public class WaypointTest extends AndroidTestCase { assertOrdered(parking, trailhead); } - private static void assertOrdered(Waypoint first, Waypoint second) { - assertThat(Waypoint.WAYPOINT_COMPARATOR.compare(first, second) < 0).isTrue(); + private static void assertOrdered(final Waypoint first, final Waypoint second) { + assertThat(Waypoint.WAYPOINT_COMPARATOR.compare(first, second)).isLessThan(0); } public static void testGeocode() { @@ -61,7 +61,7 @@ public class WaypointTest extends AndroidTestCase { "M 7\n" + "N 5\n" + "5 IFG 257"; - assertThat(Waypoint.parseWaypointsFromNote(note).isEmpty()).isTrue(); + assertThat(Waypoint.parseWaypointsFromNote(note)).isEmpty(); } public static void testParseWaypointFromNote() { diff --git a/tests/src/cgeo/geocaching/connector/ConnectorFactoryTest.java b/tests/src/cgeo/geocaching/connector/ConnectorFactoryTest.java index 22866eb..05ca6e4 100644 --- a/tests/src/cgeo/geocaching/connector/ConnectorFactoryTest.java +++ b/tests/src/cgeo/geocaching/connector/ConnectorFactoryTest.java @@ -25,27 +25,27 @@ public class ConnectorFactoryTest extends AbstractResourceInstrumentationTestCas } public static void testGeocodeOpenCaching() { - assertThat(ConnectorFactory.getConnector("OZ12345") instanceof OCConnector).isTrue(); // opencaching CZ - assertThat(ConnectorFactory.getConnector("OC12345") instanceof OCConnector).isTrue(); // opencaching DE - assertThat(ConnectorFactory.getConnector("OU12345") instanceof OCConnector).isTrue(); // opencaching US - assertThat(ConnectorFactory.getConnector("OK12345") instanceof OCConnector).isTrue(); // opencaching UK - assertThat(ConnectorFactory.getConnector("OJ12345") instanceof OCConnector).isTrue(); // opencaching JP - assertThat(ConnectorFactory.getConnector("OS12345") instanceof OCConnector).isTrue(); // opencaching NO - assertThat(ConnectorFactory.getConnector("OB12345") instanceof OCConnector).isTrue(); // opencaching NL - assertThat(ConnectorFactory.getConnector("OP12345") instanceof OCConnector).isTrue(); // opencaching PL + assertThat(ConnectorFactory.getConnector("OZ12345")).isInstanceOf(OCConnector.class); // opencaching CZ + assertThat(ConnectorFactory.getConnector("OC12345")).isInstanceOf(OCConnector.class); // opencaching DE + assertThat(ConnectorFactory.getConnector("OU12345")).isInstanceOf(OCConnector.class); // opencaching US + assertThat(ConnectorFactory.getConnector("OK12345")).isInstanceOf(OCConnector.class); // opencaching UK + assertThat(ConnectorFactory.getConnector("OJ12345")).isInstanceOf(OCConnector.class); // opencaching JP + assertThat(ConnectorFactory.getConnector("OS12345")).isInstanceOf(OCConnector.class); // opencaching NO + assertThat(ConnectorFactory.getConnector("OB12345")).isInstanceOf(OCConnector.class); // opencaching NL + assertThat(ConnectorFactory.getConnector("OP12345")).isInstanceOf(OCConnector.class); // opencaching PL } public static void testGeocodeInvalidFormat() { // all codes are invalid - assertThat(ConnectorFactory.getConnector("GC") instanceof UnknownConnector).isTrue(); - assertThat(ConnectorFactory.getConnector("OC") instanceof UnknownConnector).isTrue(); - assertThat(ConnectorFactory.getConnector("OX") instanceof UnknownConnector).isTrue(); - assertThat(ConnectorFactory.getConnector("GC 1234") instanceof UnknownConnector).isTrue(); - assertThat(ConnectorFactory.getConnector("OC 1234") instanceof UnknownConnector).isTrue(); - assertThat(ConnectorFactory.getConnector("OX 1234") instanceof UnknownConnector).isTrue(); - assertThat(ConnectorFactory.getConnector("GC-1234") instanceof UnknownConnector).isTrue(); - assertThat(ConnectorFactory.getConnector("OC-1234") instanceof UnknownConnector).isTrue(); - assertThat(ConnectorFactory.getConnector("OX-1234") instanceof UnknownConnector).isTrue(); + assertThat(ConnectorFactory.getConnector("GC")).isInstanceOf(UnknownConnector.class); + assertThat(ConnectorFactory.getConnector("OC")).isInstanceOf(UnknownConnector.class); + assertThat(ConnectorFactory.getConnector("OX")).isInstanceOf(UnknownConnector.class); + assertThat(ConnectorFactory.getConnector("GC 1234")).isInstanceOf(UnknownConnector.class); + assertThat(ConnectorFactory.getConnector("OC 1234")).isInstanceOf(UnknownConnector.class); + assertThat(ConnectorFactory.getConnector("OX 1234")).isInstanceOf(UnknownConnector.class); + assertThat(ConnectorFactory.getConnector("GC-1234")).isInstanceOf(UnknownConnector.class); + assertThat(ConnectorFactory.getConnector("OC-1234")).isInstanceOf(UnknownConnector.class); + assertThat(ConnectorFactory.getConnector("OX-1234")).isInstanceOf(UnknownConnector.class); } public static void testGetConnectorCgCache() { @@ -59,8 +59,8 @@ public class ConnectorFactoryTest extends AbstractResourceInstrumentationTestCas } public static void testTrim() { - assertThat(ConnectorFactory.getConnector(" OZ12345 ") instanceof OCConnector).isTrue(); // opencaching CZ - assertThat(ConnectorFactory.getConnector(" OZ 12345 ") instanceof UnknownConnector).isTrue(); + assertThat(ConnectorFactory.getConnector(" OZ12345 ")).isInstanceOf(OCConnector.class); // opencaching CZ + assertThat(ConnectorFactory.getConnector(" OZ 12345 ")).isInstanceOf(UnknownConnector.class); } public static void testGetGeocodeFromUrl() { diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java index 9ada969..b9f959c 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java @@ -31,7 +31,7 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase { final SearchResult searchResult = ConnectorFactory.searchByViewport(viewport, tokens); assertThat(searchResult).isNotNull(); assertThat(searchResult.isEmpty()).isFalse(); - assertThat(searchResult.getGeocodes().contains("GC4ER5H")).isTrue(); + assertThat(searchResult.getGeocodes()).contains("GC4ER5H"); // 22.10.13: Changed from GC211WG (archived) to GC4ER5H in same area } @@ -39,7 +39,7 @@ public class GCConnectorTest extends AbstractResourceInstrumentationTestCase { final Viewport viewport = new Viewport(new Geopoint("N 52° 24.000 E 9° 34.500"), new Geopoint("N 52° 26.000 E 9° 38.500")); final SearchResult searchResult = ConnectorFactory.searchByViewport(viewport, tokens); assertThat(searchResult).isNotNull(); - assertThat(searchResult.getGeocodes().contains("GC4ER5H")).isTrue(); + assertThat(searchResult.getGeocodes()).contains("GC4ER5H"); } } finally { // restore user settings diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java index 57e494a..f84f7b5 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java @@ -50,7 +50,7 @@ public class GCConstantsTest extends AndroidTestCase { GCLogin.getInstance().logout(); GCLogin.getInstance().setActualCachesFound(0); GCLogin.getInstance().login(); - assertThat(GCLogin.getInstance().getActualCachesFound() > 0).isTrue(); + assertThat(GCLogin.getInstance().getActualCachesFound()).isGreaterThan(0); } public static void testConstants() { diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java index 81838e6..5bbd013 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java @@ -186,7 +186,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { final List<Waypoint> waypoints = cache.getWaypoints(); assertThat(waypoints).hasSize(expected.length); for (int i = 0; i < expected.length; i++) { - assertThat(expected[i].equals(waypoints.get(i).getCoords())).isTrue(); + assertThat(waypoints.get(i).getCoords()).isEqualTo(expected[i]); } } diff --git a/tests/src/cgeo/geocaching/connector/oc/OCConnectorTest.java b/tests/src/cgeo/geocaching/connector/oc/OCConnectorTest.java index 697b8d8..0a2b248 100644 --- a/tests/src/cgeo/geocaching/connector/oc/OCConnectorTest.java +++ b/tests/src/cgeo/geocaching/connector/oc/OCConnectorTest.java @@ -20,7 +20,7 @@ public class OCConnectorTest extends TestCase { private static IConnector getOcDeConnector() { final IConnector ocConnector = ConnectorFactory.getConnector("OCXXX"); - assertThat(ocConnector.getHost().contains(".de")).isTrue(); + assertThat(ocConnector.getHost()).contains(".de"); return ocConnector; } diff --git a/tests/src/cgeo/geocaching/enumerations/CacheAttributeTest.java b/tests/src/cgeo/geocaching/enumerations/CacheAttributeTest.java index f9e25bf..840eb01 100644 --- a/tests/src/cgeo/geocaching/enumerations/CacheAttributeTest.java +++ b/tests/src/cgeo/geocaching/enumerations/CacheAttributeTest.java @@ -9,19 +9,19 @@ import android.test.AndroidTestCase; public class CacheAttributeTest extends AndroidTestCase { public static void testTrimAttributeName() { - for (CacheAttribute attribute : CacheAttribute.values()) { + for (final CacheAttribute attribute : CacheAttribute.values()) { final String rawName = attribute.rawName; assertThat(CacheAttribute.trimAttributeName(rawName)).as("attribute name").isEqualTo(rawName); } } public static void testIds() { - for (CacheAttribute attribute : CacheAttribute.values()) { + for (final CacheAttribute attribute : CacheAttribute.values()) { if (attribute != CacheAttribute.UNKNOWN) { assertThat(StringUtils.isNotEmpty(attribute.rawName)).isTrue(); - assertThat(attribute.drawableId != 0).isTrue(); - assertThat(attribute.stringIdYes != 0).isTrue(); - assertThat(attribute.stringIdNo != 0).isTrue(); + assertThat(attribute.drawableId).isNotEqualTo(0); + assertThat(attribute.stringIdYes).isNotEqualTo(0); + assertThat(attribute.stringIdNo).isNotEqualTo(0); } } } diff --git a/tests/src/cgeo/geocaching/enumerations/CacheSizeTest.java b/tests/src/cgeo/geocaching/enumerations/CacheSizeTest.java index 6e02b85..8acd5c3 100644 --- a/tests/src/cgeo/geocaching/enumerations/CacheSizeTest.java +++ b/tests/src/cgeo/geocaching/enumerations/CacheSizeTest.java @@ -9,9 +9,9 @@ import java.util.Locale; public class CacheSizeTest extends AndroidTestCase { public static void testOrder() { - assertThat(CacheSize.MICRO.comparable < CacheSize.SMALL.comparable).isTrue(); - assertThat(CacheSize.SMALL.comparable < CacheSize.REGULAR.comparable).isTrue(); - assertThat(CacheSize.REGULAR.comparable < CacheSize.LARGE.comparable).isTrue(); + assertThat(CacheSize.MICRO.comparable).isLessThan(CacheSize.SMALL.comparable); + assertThat(CacheSize.SMALL.comparable).isLessThan(CacheSize.REGULAR.comparable); + assertThat(CacheSize.REGULAR.comparable).isLessThan(CacheSize.LARGE.comparable); } public static void testGetById() { @@ -23,7 +23,7 @@ public class CacheSizeTest extends AndroidTestCase { } public static void testGetByIdComplete() { - for (CacheSize size : CacheSize.values()) { + for (final CacheSize size : CacheSize.values()) { assertThat(CacheSize.getById(size.id)).isEqualTo(size); assertThat(CacheSize.getById(size.id.toLowerCase(Locale.US))).isEqualTo(size); assertThat(CacheSize.getById(size.id.toUpperCase(Locale.US))).isEqualTo(size); diff --git a/tests/src/cgeo/geocaching/export/GpxSerializerTest.java b/tests/src/cgeo/geocaching/export/GpxSerializerTest.java index b20b066..6aa5cda 100644 --- a/tests/src/cgeo/geocaching/export/GpxSerializerTest.java +++ b/tests/src/cgeo/geocaching/export/GpxSerializerTest.java @@ -63,7 +63,7 @@ public class GpxSerializerTest extends AbstractResourceInstrumentationTestCase { final String gpxFirst = getGPXFromCache(geocode); - assertThat(gpxFirst.length() > 0).isTrue(); + assertThat(gpxFirst.length()).isGreaterThan(0); final GPX10Parser parser = new GPX10Parser(StoredList.TEMPORARY_LIST.id); diff --git a/tests/src/cgeo/geocaching/files/GPXImporterTest.java b/tests/src/cgeo/geocaching/files/GPXImporterTest.java index 86fa90d..333f6e2 100644 --- a/tests/src/cgeo/geocaching/files/GPXImporterTest.java +++ b/tests/src/cgeo/geocaching/files/GPXImporterTest.java @@ -28,8 +28,8 @@ import java.util.Iterator; import java.util.List; public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { - private TestHandler importStepHandler = new TestHandler(); - private TestHandler progressHandler = new TestHandler(); + private final TestHandler importStepHandler = new TestHandler(); + private final TestHandler progressHandler = new TestHandler(); private int listId; private File tempDir; private boolean importCacheStaticMaps; @@ -43,10 +43,10 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { "1234567-wpts.GPX", "gpx.gpx-wpts.gpx", "-wpts.gpx", "1234567_query-wpts.gpx", "123-wpts-4.gpx", "123-wpts(5).gpx" }; for (int i = 0; i < gpxFiles.length; i++) { - String gpxFileName = gpxFiles[i]; - String wptsFileName = wptsFiles[i]; - File gpx = new File(tempDir, gpxFileName); - File wpts = new File(tempDir, wptsFileName); + final String gpxFileName = gpxFiles[i]; + final String wptsFileName = wptsFiles[i]; + final File gpx = new File(tempDir, gpxFileName); + final File wpts = new File(tempDir, wptsFileName); // the files need to exist - we create them assertThat(gpx.createNewFile()).isTrue(); assertThat(wpts.createNewFile()).isTrue(); @@ -82,7 +82,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { assertThat(cache).isNotNull(); assertCacheProperties(cache); - assertThat(cache.getWaypoints().isEmpty()).isTrue(); + assertThat(cache.getWaypoints()).isEmpty(); } public void testImportOcGpx() throws IOException { @@ -110,11 +110,11 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { assertThat(cache.getWaypoints()).as("Number of imported waypoints").hasSize(4); } - private void runImportThread(GPXImporter.ImportThread importThread) { + private void runImportThread(final GPXImporter.ImportThread importThread) { importThread.start(); try { importThread.join(); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { Log.e("GPXImporterTest.runImportThread", e); } importStepHandler.waitForCompletion(); @@ -174,7 +174,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { assertCacheProperties(cache); } - private static void assertCacheProperties(Geocache cache) { + private static void assertCacheProperties(final Geocache cache) { assertThat(cache).isNotNull(); assertThat(cache.getLocation().startsWith(",")).isFalse(); assertThat(cache.isReliableLatLon()).isTrue(); @@ -217,7 +217,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { assertThat(cache).isNotNull(); assertCacheProperties(cache); - assertThat(cache.getWaypoints().isEmpty()).isTrue(); + assertThat(cache.getWaypoints()).isEmpty(); } public void testImportGpxZip() throws IOException { @@ -272,7 +272,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { private long lastMessage = System.currentTimeMillis(); @Override - public synchronized void handleRegularMessage(Message msg) { + public synchronized void handleRegularMessage(final Message msg) { final Message msg1 = Message.obtain(); msg1.copyFrom(msg); messages.add(msg1); @@ -285,13 +285,13 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase { while (System.currentTimeMillis() - lastMessage <= milliseconds && !hasTerminatingMessage()) { wait(milliseconds); } - } catch (InterruptedException e) { + } catch (final InterruptedException e) { // intentionally left blank } } private boolean hasTerminatingMessage() { - Message recentMessage = messages.get(messages.size() - 1); + final Message recentMessage = messages.get(messages.size() - 1); return recentMessage.what == GPXImporter.IMPORT_STEP_CANCELED || recentMessage.what == GPXImporter.IMPORT_STEP_FINISHED || recentMessage.what == GPXImporter.IMPORT_STEP_FINISHED_WITH_ERROR; } diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java index 8364e28..84622b5 100644 --- a/tests/src/cgeo/geocaching/files/GPXParserTest.java +++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java @@ -179,7 +179,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { assertThat(log.log).isEqualTo("Sehr schöne Runde und wir haben wieder etwas Neues über Hockenheim gelernt. Super Tarnung.\nTFTC, Geoteufel"); assertThat(log.isOwn()).isFalse(); assertThat(log.getDisplayText()).isEqualTo(log.log); - assertThat(CalendarUtils.daysSince(log.date) > 700).isTrue(); + assertThat(CalendarUtils.daysSince(log.date)).isGreaterThan(700); // following info is not contained in pocket query gpx file assertThat(cache.getAttributes()).isEmpty(); @@ -275,8 +275,7 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { for (final Geocache cache : caches) { codes.add(cache.getGeocode()); } - assertThat(codes.contains("GC2KN6K")).isTrue(); - assertThat(codes.contains("GC1T3MK")).isTrue(); + assertThat(codes).contains("GC2KN6K", "GC1T3MK"); } public void testLazyLogLoading() throws IOException, ParserException { diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java index 7d5ccee..59d6ca0 100644 --- a/tests/src/cgeo/geocaching/files/LocParserTest.java +++ b/tests/src/cgeo/geocaching/files/LocParserTest.java @@ -16,14 +16,14 @@ import java.util.Collection; import java.util.List; public class LocParserTest extends AbstractResourceInstrumentationTestCase { - private List<Geocache> readLoc(int resourceId) throws IOException, ParserException { + private List<Geocache> readLoc(final int resourceId) throws IOException, ParserException { final LocParser parser = new LocParser(getTemporaryListId()); Collection<Geocache> caches = null; final InputStream instream = getResourceStream(resourceId); try { caches = parser.parse(instream, null); assertThat(caches).isNotNull(); - assertThat(caches.size() > 0).isTrue(); + assertThat(caches).isNotEmpty(); } finally { instream.close(); } diff --git a/tests/src/cgeo/geocaching/filter/DifficultyFilterTest.java b/tests/src/cgeo/geocaching/filter/DifficultyFilterTest.java index 58eeaa4..336de42 100644 --- a/tests/src/cgeo/geocaching/filter/DifficultyFilterTest.java +++ b/tests/src/cgeo/geocaching/filter/DifficultyFilterTest.java @@ -21,6 +21,6 @@ public class DifficultyFilterTest extends CGeoTestCase { } public static void testAllFilters() { - assertThat(new DifficultyFilter.Factory().getFilters().size() == 5).isTrue(); // difficulty ranges from 1 to 5 + assertThat(new DifficultyFilter.Factory().getFilters()).hasSize(5); // difficulty ranges from 1 to 5 } } diff --git a/tests/src/cgeo/geocaching/filter/TypeFilterTest.java b/tests/src/cgeo/geocaching/filter/TypeFilterTest.java index 03519ec..ba211a6 100644 --- a/tests/src/cgeo/geocaching/filter/TypeFilterTest.java +++ b/tests/src/cgeo/geocaching/filter/TypeFilterTest.java @@ -41,8 +41,7 @@ public class TypeFilterTest extends CGeoTestCase { assertThat(list).hasSize(2); traditionalFilter.filter(list); - assertThat(list).hasSize(1); - assertThat(list.contains(traditional)).isTrue(); + assertThat(list).containsExactly(traditional); } diff --git a/tests/src/cgeo/geocaching/list/StoredListTest.java b/tests/src/cgeo/geocaching/list/StoredListTest.java index 50e4b5d..c5de109 100644 --- a/tests/src/cgeo/geocaching/list/StoredListTest.java +++ b/tests/src/cgeo/geocaching/list/StoredListTest.java @@ -28,6 +28,6 @@ public class StoredListTest extends TestCase { } public static void testTitleAndCountContainsTitle() { - assertThat(getStandardList().getTitleAndCount().startsWith(getStandardList().getTitle())).isTrue(); + assertThat(getStandardList().getTitleAndCount()).startsWith(getStandardList().getTitle()); } } diff --git a/tests/src/cgeo/geocaching/location/GeoPointParserTest.java b/tests/src/cgeo/geocaching/location/GeoPointParserTest.java index a2b916d..1c2a732 100644 --- a/tests/src/cgeo/geocaching/location/GeoPointParserTest.java +++ b/tests/src/cgeo/geocaching/location/GeoPointParserTest.java @@ -21,13 +21,13 @@ public class GeoPointParserTest extends AndroidTestCase { public static void testFullCoordinates() { final Geopoint goal = new Geopoint(refLatitude, refLongitude); - assertEquals(goal, GeopointParser.parse("N 49° 56.031 | E 8° 38.564"), 1e-6); + assertEquals(goal, GeopointParser.parse("N 49° 56.031 | E 8° 38.564"), (float) 1e-6); } - private static void assertEquals(final Geopoint expected, Geopoint actual, double tolerance) { + private static void assertEquals(final Geopoint expected, final Geopoint actual, final float tolerance) { assertThat(expected).isNotNull(); assertThat(actual).isNotNull(); - assertThat(expected.distanceTo(actual) <= tolerance).isTrue(); + assertThat(expected.distanceTo(actual)).isLessThanOrEqualTo(tolerance); } public static void testCoordinateMissingPart() { @@ -35,7 +35,7 @@ public class GeoPointParserTest extends AndroidTestCase { Geopoint point = null; try { point = GeopointParser.parse("N 49° 56.031"); - } catch (Geopoint.ParseException e) { + } catch (final Geopoint.ParseException e) { // expected } assertThat(point).isNull(); @@ -62,13 +62,13 @@ public class GeoPointParserTest extends AndroidTestCase { public static void testVariousFormats() { final Geopoint goal1 = GeopointParser.parse("N 49° 43' 57\" | E 2 12' 35"); final Geopoint goal2 = GeopointParser.parse("N 49 43.95 E2°12.5833333333"); - assertEquals(goal1, goal2, 1e-6); + assertEquals(goal1, goal2, (float) 1e-6); } public static void testParseOurOwnSeparator() { final Geopoint separator = GeopointParser.parse("N 49° 43' 57\"" + Formatter.SEPARATOR + "E 2 12' 35"); final Geopoint noSeparator = GeopointParser.parse("N 49 43.95 E2°12.5833333333"); - assertEquals(separator, noSeparator, 1e-6); + assertEquals(separator, noSeparator, (float) 1e-6); } public static void testInSentence() { @@ -83,7 +83,7 @@ public class GeoPointParserTest extends AndroidTestCase { Geopoint point = null; try { point = GeopointParser.parse("N51 21.523 and some words in between, so there is no relation E07 02.680"); - } catch (Geopoint.ParseException e) { + } catch (final Geopoint.ParseException e) { // expected } assertThat(point).isNull(); diff --git a/tests/src/cgeo/geocaching/location/GeopointTest.java b/tests/src/cgeo/geocaching/location/GeopointTest.java index 6f5dd78..0c0a37a 100644 --- a/tests/src/cgeo/geocaching/location/GeopointTest.java +++ b/tests/src/cgeo/geocaching/location/GeopointTest.java @@ -3,8 +3,6 @@ package cgeo.geocaching.location; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.offset; -import cgeo.geocaching.location.Geopoint; - import android.os.Build; import android.os.Bundle; import android.test.AndroidTestCase; @@ -120,7 +118,7 @@ public class GeopointTest extends AndroidTestCase { checkTolerance(gp4, gp4a, 5e-5); } - private static void checkDDD(Geopoint gp, char latDir, int latDeg, int latDegFrac, char lonDir, int lonDeg, int lonDegFrac) { + private static void checkDDD(final Geopoint gp, final char latDir, final int latDeg, final int latDegFrac, final char lonDir, final int lonDeg, final int lonDegFrac) { assertThat(gp.getLatDir()).isEqualTo(latDir); assertThat(gp.getLatDeg()).isEqualTo(latDeg); assertThat(gp.getLatDegFrac()).isEqualTo(latDegFrac); @@ -129,9 +127,9 @@ public class GeopointTest extends AndroidTestCase { assertThat(gp.getLonDegFrac()).isEqualTo(lonDegFrac); } - private static void checkTolerance(Geopoint gp1, Geopoint gp2, double tolerance) { - assertThat(Math.abs(gp1.getLatitude() - gp2.getLatitude()) <= tolerance).isTrue(); - assertThat(Math.abs(gp1.getLongitude() - gp2.getLongitude()) <= tolerance).isTrue(); + private static void checkTolerance(final Geopoint gp1, final Geopoint gp2, final double tolerance) { + assertThat(Math.abs(gp1.getLatitude() - gp2.getLatitude())).isLessThanOrEqualTo(tolerance); + assertThat(Math.abs(gp1.getLongitude() - gp2.getLongitude())).isLessThanOrEqualTo(tolerance); } public static void testDMM() { @@ -176,7 +174,7 @@ public class GeopointTest extends AndroidTestCase { checkTolerance(gp4, gp4a, 5e-5); } - private static void checkDMM(Geopoint gp, char latDir, int latDeg, int latMin, int latMinFrac, char lonDir, int lonDeg, int lonMin, int lonMinFrac) { + private static void checkDMM(final Geopoint gp, final char latDir, final int latDeg, final int latMin, final int latMinFrac, final char lonDir, final int lonDeg, final int lonMin, final int lonMinFrac) { assertThat(gp.getLatDir()).isEqualTo(latDir); assertThat(gp.getLatDeg()).isEqualTo(latDeg); assertThat(gp.getLatMin()).isEqualTo(latMin); @@ -229,7 +227,7 @@ public class GeopointTest extends AndroidTestCase { checkTolerance(gp4, gp4a, 5e-6); } - private static void checkDMS(Geopoint gp, char latDir, int latDeg, int latMin, int latSec, int latSecFrac, char lonDir, int lonDeg, int lonMin, int lonSec, int lonSecFrac) { + private static void checkDMS(final Geopoint gp, final char latDir, final int latDeg, final int latMin, final int latSec, final int latSecFrac, final char lonDir, final int lonDeg, final int lonMin, final int lonSec, final int lonSecFrac) { assertThat(gp.getLatDir()).isEqualTo(latDir); assertThat(gp.getLatDeg()).isEqualTo(latDeg); assertThat(gp.getLatMin()).isEqualTo(latMin); @@ -242,11 +240,11 @@ public class GeopointTest extends AndroidTestCase { assertThat(gp.getLonSecFrac()).isEqualTo(lonSecFrac); } - private static void assertParseException(Runnable runnable) { + private static void assertParseException(final Runnable runnable) { try { runnable.run(); fail("Should have thrown Geopoint.ParseException"); - } catch (Geopoint.ParseException e) { + } catch (final Geopoint.ParseException e) { //success } } diff --git a/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java b/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java index 6d4fa46..84afcae 100644 --- a/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java +++ b/tests/src/cgeo/geocaching/sorting/NameComparatorTest.java @@ -56,10 +56,10 @@ public class NameComparatorTest extends AndroidTestCase { } private void assertSorted(final Geocache cache1, final Geocache cache2) { - assertThat(comp.compare(cache1, cache2) < 0).isTrue(); + assertThat(comp.compare(cache1, cache2)).isLessThan(0); } private void assertNotSorted(final Geocache cache1, final Geocache cache2) { - assertThat(comp.compare(cache1, cache2) > 0).isTrue(); + assertThat(comp.compare(cache1, cache2)).isGreaterThan(0); } } diff --git a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java index 2a22895..469400f 100644 --- a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java +++ b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java @@ -34,18 +34,18 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument DataStore.removeCache(geocode, flags); } - protected InputStream getResourceStream(int resourceId) { + protected InputStream getResourceStream(final int resourceId) { final Resources res = getInstrumentation().getContext().getResources(); return res.openRawResource(resourceId); } - protected String getFileContent(int resourceId) { + protected String getFileContent(final int resourceId) { Scanner scanner = null; try { final InputStream ins = getResourceStream(resourceId); scanner = new Scanner(ins); return scanner.useDelimiter("\\A").next(); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } finally { if (scanner != null) { @@ -55,7 +55,7 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument return null; } - protected void copyResourceToFile(int resourceId, File file) throws IOException { + protected void copyResourceToFile(final int resourceId, final File file) throws IOException { final InputStream is = getResourceStream(resourceId); final FileOutputStream os = new FileOutputStream(file); @@ -75,8 +75,8 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument protected void setUp() throws Exception { super.setUp(); temporaryListId = DataStore.createList("Temporary unit testing"); - assertThat(temporaryListId != StoredList.TEMPORARY_LIST.id).isTrue(); - assertThat(temporaryListId != StoredList.STANDARD_LIST_ID).isTrue(); + assertThat(temporaryListId).isNotEqualTo(StoredList.TEMPORARY_LIST.id); + assertThat(temporaryListId).isNotEqualTo(StoredList.STANDARD_LIST_ID); } @Override @@ -92,11 +92,11 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument return temporaryListId; } - final protected Geocache loadCacheFromResource(int resourceId) throws IOException, ParserException { + final protected Geocache loadCacheFromResource(final int resourceId) throws IOException, ParserException { final InputStream instream = getResourceStream(resourceId); try { - GPX10Parser parser = new GPX10Parser(StoredList.TEMPORARY_LIST.id); - Collection<Geocache> caches = parser.parse(instream, null); + final GPX10Parser parser = new GPX10Parser(StoredList.TEMPORARY_LIST.id); + final Collection<Geocache> caches = parser.parse(instream, null); assertThat(caches).isNotNull(); assertThat(caches.isEmpty()).isFalse(); return caches.iterator().next(); @@ -105,8 +105,8 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument } } - protected Uri getResourceURI(int resId) { - Resources resources = getInstrumentation().getContext().getResources(); + protected Uri getResourceURI(final int resId) { + final Resources resources = getInstrumentation().getContext().getResources(); return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(resId) + '/' + resources.getResourceTypeName(resId) + '/' + resources.getResourceEntryName(resId)); } } diff --git a/tests/src/cgeo/geocaching/test/EmulatorStateTest.java b/tests/src/cgeo/geocaching/test/EmulatorStateTest.java index c35fbe3..704aad2 100644 --- a/tests/src/cgeo/geocaching/test/EmulatorStateTest.java +++ b/tests/src/cgeo/geocaching/test/EmulatorStateTest.java @@ -10,6 +10,6 @@ public class EmulatorStateTest extends TestCase { public static void testWritableMedia() { // check the emulator running our tests - assertThat(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)).isTrue(); + assertThat(Environment.getExternalStorageState()).isEqualTo(Environment.MEDIA_MOUNTED); } } diff --git a/tests/src/cgeo/geocaching/utils/AbstractLRUTest.java b/tests/src/cgeo/geocaching/utils/AbstractLRUTest.java deleted file mode 100644 index 83a796b..0000000 --- a/tests/src/cgeo/geocaching/utils/AbstractLRUTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package cgeo.geocaching.utils; - -import org.apache.commons.lang3.StringUtils; - -import android.test.AndroidTestCase; - -import java.util.ArrayList; -import java.util.Collection; - -public abstract class AbstractLRUTest extends AndroidTestCase { - - protected static String colToStr(Collection<?> col) { - final ArrayList<String> list = new ArrayList<String>(col.size()); - for (Object o : col) { - list.add(o.toString()); - } - return StringUtils.join(list, ", "); - } - -}
\ No newline at end of file diff --git a/tests/src/cgeo/geocaching/utils/FileUtilsTest.java b/tests/src/cgeo/geocaching/utils/FileUtilsTest.java index 79a8aef..108880b 100644 --- a/tests/src/cgeo/geocaching/utils/FileUtilsTest.java +++ b/tests/src/cgeo/geocaching/utils/FileUtilsTest.java @@ -41,10 +41,10 @@ public class FileUtilsTest extends TestCase { public void testCreateRemoveDirectories() { FileUtils.deleteDirectory(testDir); - assertThat(testDir.exists()).isFalse(); + assertThat(testDir).doesNotExist(); FileUtils.mkdirs(testDir); - assertThat(testDir.exists()).isTrue(); + assertThat(testDir).exists(); FileUtils.deleteDirectory(testDir); - assertThat(testDir.exists()).isFalse(); + assertThat(testDir).doesNotExist(); } } diff --git a/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java b/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java index 9338d10..9d76e58 100644 --- a/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java +++ b/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java @@ -18,12 +18,12 @@ public class LazyInitializedListTest extends TestCase { public static void testAccess() { final LazyInitializedList<String> list = new MockedLazyInitializedList(); - assertThat(list.isEmpty()).isTrue(); + assertThat(list).isEmpty(); list.add("Test"); - assertThat(list.isEmpty()).isFalse(); + assertThat(list).isNotEmpty(); assertThat(list).hasSize(1); int iterations = 0; - for (String element : list) { + for (final String element : list) { assertThat(element).isEqualTo("Test"); iterations++; } diff --git a/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java b/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java index 76b275e..0edb3da 100644 --- a/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java +++ b/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedMapTest.java @@ -4,9 +4,11 @@ import static org.assertj.core.api.Assertions.assertThat; import cgeo.geocaching.Geocache; +import android.test.AndroidTestCase; + import java.util.Map; -public class LeastRecentlyUsedMapTest extends AbstractLRUTest { +public class LeastRecentlyUsedMapTest extends AndroidTestCase { public static void testLruMode() { final Map<String, String> map = new LeastRecentlyUsedMap.LruCache<String, String>(4); @@ -24,7 +26,7 @@ public class LeastRecentlyUsedMapTest extends AbstractLRUTest { map.put("five", "5"); map.put("seven", "7"); - assertEquals("six, one, five, seven", colToStr(map.keySet())); + assertThat(map.keySet()).containsExactly("six", "one", "five", "seven"); } public static void testBoundedMode() { @@ -43,7 +45,7 @@ public class LeastRecentlyUsedMapTest extends AbstractLRUTest { map.put("six", "6"); map.put("seven", "7"); - assertEquals("four, three, five, six, seven", colToStr(map.keySet())); + assertThat(map.keySet()).containsExactly("four", "three", "five", "six", "seven"); } public static void testRemoveEldestEntry() { @@ -55,20 +57,20 @@ public class LeastRecentlyUsedMapTest extends AbstractLRUTest { assertThat(cache.put("2", second)).isNull(); assertThat(cache).hasSize(2); - assertThat(cache.containsKey("1")).isTrue(); - assertThat(cache.containsValue(first)).isTrue(); - assertThat(cache.containsKey("2")).isTrue(); - assertThat(cache.containsValue(second)).isTrue(); + assertThat(cache).containsKey("1"); + assertThat(cache).containsValue(first); + assertThat(cache).containsKey("2"); + assertThat(cache).containsValue(second); for (int i = 3; i <= 10; i++) { assertThat(cache.put(Integer.toString(i), new Geocache())).isNull(); } assertThat(cache).hasSize(10); - assertThat(cache.containsKey("1")).isTrue(); - assertThat(cache.containsValue(first)).isTrue(); - assertThat(cache.containsKey("2")).isTrue(); - assertThat(cache.containsValue(second)).isTrue(); + assertThat(cache).containsKey("1"); + assertThat(cache).containsValue(first); + assertThat(cache).containsKey("2"); + assertThat(cache).containsValue(second); assertThat(cache.remove("1")).isNotNull(); // just replacing the old entry would not work assertThat(cache.put("1", new Geocache())).isNull(); @@ -77,11 +79,11 @@ public class LeastRecentlyUsedMapTest extends AbstractLRUTest { assertThat(cache).hasSize(10); // first has been overwritten by new value, but key must be in, because it is very new - assertThat(cache.containsKey("1")).isTrue(); + assertThat(cache).containsKey("1"); // second has been overwritten by 11 - assertThat(cache.containsKey("2")).isFalse(); - assertThat(cache.containsKey("11")).isTrue(); + assertThat(cache).containsKey("2"); + assertThat(cache).containsKey("11"); } } diff --git a/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java b/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java index f8517de..36a8faa 100644 --- a/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java +++ b/tests/src/cgeo/geocaching/utils/LeastRecentlyUsedSetTest.java @@ -4,9 +4,11 @@ import static org.assertj.core.api.Assertions.assertThat; import cgeo.geocaching.Geocache; +import android.test.AndroidTestCase; + import java.util.Set; -public class LeastRecentlyUsedSetTest extends AbstractLRUTest { +public class LeastRecentlyUsedSetTest extends AndroidTestCase { public static void testLruMode() { final Set<String> set = new LeastRecentlyUsedSet<String>(5); @@ -14,17 +16,17 @@ public class LeastRecentlyUsedSetTest extends AbstractLRUTest { set.add("two"); set.add("three"); // read does not change anything - assertThat(set.contains("one")).isTrue(); + assertThat(set).contains("one"); set.add("four"); // re-put should update the order set.add("three"); set.add("five"); // read does not change anything - assertThat(set.contains("one")).isTrue(); + assertThat(set).contains("one"); set.add("six"); set.add("seven"); - assertEquals("four, three, five, six, seven", colToStr(set)); + assertThat(set).containsExactly("four", "three", "five", "six", "seven"); } public static void testRemoveEldestEntry() { @@ -37,9 +39,7 @@ public class LeastRecentlyUsedSetTest extends AbstractLRUTest { second.setGeocode("2"); assertThat(caches.add(second)).isTrue(); - assertThat(caches).hasSize(2); - assertThat(caches.contains(first)).isTrue(); - assertThat(caches.contains(second)).isTrue(); + assertThat(caches).contains(first, second); // adding first cache again does not change set assertThat(caches.add(first)).isFalse(); @@ -51,9 +51,7 @@ public class LeastRecentlyUsedSetTest extends AbstractLRUTest { assertThat(caches.add(cache)).isTrue(); } - assertThat(caches).hasSize(10); - assertThat(caches.contains(first)).isTrue(); - assertThat(caches.contains(second)).isTrue(); + assertThat(caches).hasSize(10).contains(first, second); final Geocache c11 = new Geocache(); c11.setGeocode("11"); @@ -62,7 +60,6 @@ public class LeastRecentlyUsedSetTest extends AbstractLRUTest { assertThat(caches).hasSize(10); // first was used again, there second is the oldest and has been overwritten by 11 - assertThat(caches.contains(first)).isTrue(); - assertThat(caches.contains(second)).isFalse(); + assertThat(caches).contains(first).doesNotContain(second); } }
\ No newline at end of file |