diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2015-01-06 19:46:25 +0100 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2015-01-06 19:46:25 +0100 |
commit | 00c84745766c14a4d74e593fdf1cc7d66e6e6b3c (patch) | |
tree | 81e34dd9f73f2ef9ba3fc3d4451d16368eca49ef /tests | |
parent | 2676f997e9b42f142926ec04285662d99ec068fc (diff) | |
download | cgeo-00c84745766c14a4d74e593fdf1cc7d66e6e6b3c.zip cgeo-00c84745766c14a4d74e593fdf1cc7d66e6e6b3c.tar.gz cgeo-00c84745766c14a4d74e593fdf1cc7d66e6e6b3c.tar.bz2 |
Cherry-picked and merged test fixes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/cgeo/geocaching/connector/gc/GCParserTest.java | 18 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/utils/RxUtilsTest.java | 12 | ||||
-rw-r--r-- | tests/src/cgeo/test/Compare.java | 6 |
3 files changed, 26 insertions, 10 deletions
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java index 058163a..81838e6 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java @@ -71,7 +71,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { assertThat(spoiler.getDescription()).as("First spoiler image description").isNull(); } - private static Geocache createCache(int index) { + private static Geocache createCache(final int index) { final MockedCache mockedCache = RegExPerformanceTest.MOCKED_CACHES.get(index); // to get the same results we have to use the date format used when the mocked data was created final String oldCustomDate = Settings.getGcCustomDate(); @@ -100,12 +100,18 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { public static void testParseCacheFromTextWithMockedData() { final String gcCustomDate = Settings.getGcCustomDate(); try { - for (MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) { + for (final MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) { // to get the same results we have to use the date format used when the mocked data was created Settings.setGcCustomDate(MockedCache.getDateFormat()); - SearchResult searchResult = GCParser.parseAndSaveCacheFromText(mockedCache.getData(), null); - Geocache parsedCache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); + final SearchResult searchResult = GCParser.parseAndSaveCacheFromText(mockedCache.getData(), null); + final Geocache parsedCache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); + assertThat(parsedCache).isNotNull(); + assert parsedCache != null; // To keep editors happy assertThat(StringUtils.isNotBlank(mockedCache.getMockedDataUser())).isTrue(); + // Workaround for issue #3777 + if (mockedCache.getGeocode().equals("GC3XX5J") && Settings.getUsername().equals("mucek4")) { + parsedCache.setFound(true); + } Compare.assertCompareCaches(mockedCache, parsedCache, true); } } finally { @@ -173,7 +179,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { assertThat(cache3.hasUserModifiedCoords()).isFalse(); } - private static void assertWaypointsFromNote(final Geocache cache, Geopoint[] expected, String note) { + private static void assertWaypointsFromNote(final Geocache cache, final Geopoint[] expected, final String note) { cache.setPersonalNote(note); cache.setWaypoints(new ArrayList<Waypoint>(), false); cache.parseWaypointsFromNote(); @@ -208,7 +214,7 @@ public class GCParserTest extends AbstractResourceInstrumentationTestCase { assertThat(waypoints.get(2).getWaypointType()).isEqualTo(WaypointType.WAYPOINT); } - private Geocache parseCache(int resourceId) { + private Geocache parseCache(final int resourceId) { final String page = getFileContent(resourceId); final SearchResult result = GCParser.parseAndSaveCacheFromText(page, null); assertThat(result).isNotNull(); diff --git a/tests/src/cgeo/geocaching/utils/RxUtilsTest.java b/tests/src/cgeo/geocaching/utils/RxUtilsTest.java index 5259998..2487184 100644 --- a/tests/src/cgeo/geocaching/utils/RxUtilsTest.java +++ b/tests/src/cgeo/geocaching/utils/RxUtilsTest.java @@ -6,13 +6,23 @@ import rx.Observable; import rx.Subscription; import rx.functions.Func1; import rx.subjects.PublishSubject; +import rx.subjects.ReplaySubject; import android.test.AndroidTestCase; public class RxUtilsTest extends AndroidTestCase { + // Observable.range(int, int) is not kept in the application by proguard. Use an explicit range here. + private static final ReplaySubject<Integer> range = ReplaySubject.createWithSize(10); + static { + for (int i = 1; i <= 10; i++) { + range.onNext(i); + } + range.onCompleted(); + } + public static void testTakeUntil() { - final Observable<Integer> observable = Observable.range(1, 10).lift(RxUtils.operatorTakeUntil(new Func1<Integer, Boolean>() { + final Observable<Integer> observable = range.lift(RxUtils.operatorTakeUntil(new Func1<Integer, Boolean>() { @Override public Boolean call(final Integer value) { return value > 6; diff --git a/tests/src/cgeo/test/Compare.java b/tests/src/cgeo/test/Compare.java index c6d38ae..788a191 100644 --- a/tests/src/cgeo/test/Compare.java +++ b/tests/src/cgeo/test/Compare.java @@ -12,7 +12,7 @@ import java.util.Date; public abstract class Compare { - public static void assertCompareCaches(Geocache expected, Geocache actual, boolean all) { + public static void assertCompareCaches(final Geocache expected, final Geocache actual, final boolean all) { final String geocode = expected.getGeocode(); final String cacheStr = "Cache " + geocode + ": "; assertThat(actual).isNotNull(); @@ -47,10 +47,10 @@ public abstract class Compare { assertThat(actual.isFavorite()).as(cacheStr + "favorite status").isEqualTo(expected.isFavorite()); assertThat(actual.isOnWatchlist()).as(cacheStr + "watchlist status").isEqualTo(expected.isOnWatchlist()); - for (String attribute : expected.getAttributes()) { + for (final String attribute : expected.getAttributes()) { assertThat(actual.getAttributes()).as("attributes of " + actual.getGeocode()).contains(attribute); } - for (LogType logType : expected.getLogCounts().keySet()) { + for (final LogType logType : expected.getLogCounts().keySet()) { assertThat(actual.getLogCounts().get(logType)).as("logcount of " + geocode + " for type " + logType.toString()).isGreaterThanOrEqualTo(expected.getLogCounts().get(logType)); } |