diff options
Diffstat (limited to 'tests/src')
| -rw-r--r-- | tests/src/cgeo/geocaching/TrackablesTest.java | 11 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/cgDataTest.java | 7 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/cgeoApplicationTest.java | 25 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java | 4 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/connector/gc/GCParserTest.java (renamed from tests/src/cgeo/geocaching/cgBaseTest.java) | 130 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/filter/AbstractFilterTestCase.java | 2 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/geopoint/GeopointTest.java | 4 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/utils/BaseUtilsTest.java | 26 | ||||
| -rw-r--r-- | tests/src/cgeo/test/Compare.java | 57 |
9 files changed, 145 insertions, 121 deletions
diff --git a/tests/src/cgeo/geocaching/TrackablesTest.java b/tests/src/cgeo/geocaching/TrackablesTest.java index 1d3d165..e8a1505 100644 --- a/tests/src/cgeo/geocaching/TrackablesTest.java +++ b/tests/src/cgeo/geocaching/TrackablesTest.java @@ -1,5 +1,6 @@ package cgeo.geocaching; +import cgeo.geocaching.connector.gc.GCParser; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; import cgeo.geocaching.test.R; import cgeo.geocaching.utils.BaseUtils; @@ -9,7 +10,7 @@ import java.util.List; public class TrackablesTest extends AbstractResourceInstrumentationTestCase { public void testLogPageWithTrackables() { - List<cgTrackableLog> tbLogs = cgBase.parseTrackableLog(getFileContent(R.raw.log_with_2tb)); + List<cgTrackableLog> tbLogs = GCParser.parseTrackableLog(getFileContent(R.raw.log_with_2tb)); assertNotNull(tbLogs); assertEquals(2, tbLogs.size()); cgTrackableLog log = tbLogs.get(0); @@ -18,7 +19,7 @@ public class TrackablesTest extends AbstractResourceInstrumentationTestCase { } public void testLogPageWithoutTrackables() { - List<cgTrackableLog> tbLogs = cgBase.parseTrackableLog(getFileContent(R.raw.log_without_tb)); + List<cgTrackableLog> tbLogs = GCParser.parseTrackableLog(getFileContent(R.raw.log_without_tb)); assertNotNull(tbLogs); assertEquals(0, tbLogs.size()); } @@ -53,7 +54,7 @@ public class TrackablesTest extends AbstractResourceInstrumentationTestCase { } public void testParseTrackableWithoutReleaseDate() { - cgTrackable trackable = cgBase.parseTrackable(getFileContent(R.raw.tb14wfv), null, null); + cgTrackable trackable = GCParser.parseTrackable(getFileContent(R.raw.tb14wfv), null, null); assertNotNull(trackable); assertEquals("The Brickster", trackable.getName()); assertEquals("Adrian C", trackable.getOwner()); @@ -66,11 +67,11 @@ public class TrackablesTest extends AbstractResourceInstrumentationTestCase { } private cgTrackable getTB2R124() { - return cgBase.parseTrackable(BaseUtils.replaceWhitespace(getFileContent(R.raw.trackable_tb2r124)), null, null); + return GCParser.parseTrackable(BaseUtils.replaceWhitespace(getFileContent(R.raw.trackable_tb2r124)), null, null); } private cgTrackable getTBXATG() { - return cgBase.parseTrackable(BaseUtils.replaceWhitespace(getFileContent(R.raw.trackable_tbxatg)), null, null); + return GCParser.parseTrackable(BaseUtils.replaceWhitespace(getFileContent(R.raw.trackable_tbxatg)), null, null); } } diff --git a/tests/src/cgeo/geocaching/cgDataTest.java b/tests/src/cgeo/geocaching/cgDataTest.java index 0625585..a1c6b1b 100644 --- a/tests/src/cgeo/geocaching/cgDataTest.java +++ b/tests/src/cgeo/geocaching/cgDataTest.java @@ -29,9 +29,10 @@ public class cgDataTest extends ApplicationTestCase<cgeoapplication> { int listId2 = StoredList.STANDARD_LIST_ID; // create caches - final cgCache cache1 = cgBaseTest.createCache(0); - assertNotNull(cache1); - final cgCache cache2 = cgBaseTest.createCache(1); + final cgCache cache1 = new cgCache(); + cache1.setGeocode("Cache 1"); + final cgCache cache2 = new cgCache(); + cache2.setGeocode("Cache 2"); assertNotNull(cache2); try { diff --git a/tests/src/cgeo/geocaching/cgeoApplicationTest.java b/tests/src/cgeo/geocaching/cgeoApplicationTest.java index 4f952fd..4a1fcb0 100644 --- a/tests/src/cgeo/geocaching/cgeoApplicationTest.java +++ b/tests/src/cgeo/geocaching/cgeoApplicationTest.java @@ -2,6 +2,7 @@ package cgeo.geocaching; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.gc.GCBase; +import cgeo.geocaching.connector.gc.GCParser; import cgeo.geocaching.connector.gc.Login; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy; @@ -16,6 +17,7 @@ import cgeo.geocaching.test.mock.GC2JVEH; import cgeo.geocaching.test.mock.MockedCache; import cgeo.geocaching.utils.CancellableHandler; import cgeo.geocaching.utils.Log; +import cgeo.test.Compare; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -44,7 +46,6 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { // init environment createApplication(); - cgBase.initialize(getApplication()); } /** @@ -64,7 +65,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static void testSearchTrackableNotExisting() { - cgTrackable tb = cgBase.searchTrackable("123456", null, null); + cgTrackable tb = GCParser.searchTrackable("123456", null, null); assertNotNull(tb); } @@ -73,7 +74,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static void testSearchTrackable() { - cgTrackable tb = cgBase.searchTrackable("TB2J1VZ", null, null); + cgTrackable tb = GCParser.searchTrackable("TB2J1VZ", null, null); // fix data assertEquals("aefffb86-099f-444f-b132-605436163aa8", tb.getGuid()); assertEquals("TB2J1VZ", tb.getGeocode()); @@ -100,7 +101,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static cgCache testSearchByGeocode(final String geocode) { - final SearchResult search = cgBase.searchByGeocode(geocode, null, 0, true, null); + final SearchResult search = cgCache.searchByGeocode(geocode, null, 0, true, null); assertNotNull(search); if (Settings.isPremiumMember() || search.getError() == null) { assertEquals(1, search.getGeocodes().size()); @@ -116,7 +117,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static void testSearchByGeocodeNotExisting() { - final SearchResult search = cgBase.searchByGeocode("GC123456", null, 0, true, null); + final SearchResult search = cgCache.searchByGeocode("GC123456", null, 0, true, null); assertNotNull(search); assertEquals(StatusCode.UNPUBLISHED_CACHE, search.getError()); } @@ -135,7 +136,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { deleteCacheFromDBAndLogout(cache.getGeocode()); - SearchResult search = cgBase.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); + SearchResult search = cgCache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); assertNotNull(search); assertEquals(1, search.getGeocodes().size()); assertTrue(search.getGeocodes().contains(cache.getGeocode())); @@ -148,7 +149,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { deleteCacheFromDBAndLogout(cache.getGeocode()); - search = cgBase.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); + search = cgCache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); assertNotNull(search); assertEquals(0, search.getGeocodes().size()); @@ -174,7 +175,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { deleteCacheFromDBAndLogout(cache.getGeocode()); - SearchResult search = cgBase.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); + SearchResult search = cgCache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null); assertNotNull(search); assertEquals(0, search.getGeocodes().size()); @@ -191,7 +192,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static void testSearchByCoords() { - final SearchResult search = cgBase.searchByCoords(null, new Geopoint("N 52° 24.972 E 009° 35.647"), CacheType.MYSTERY, false); + final SearchResult search = GCParser.searchByCoords(null, new Geopoint("N 52° 24.972 E 009° 35.647"), CacheType.MYSTERY, false); assertNotNull(search); assertTrue(18 <= search.getGeocodes().size()); assertTrue(search.getGeocodes().contains("GC1RMM2")); @@ -202,7 +203,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static void testSearchByOwner() { - final SearchResult search = cgBase.searchByOwner(null, "blafoo", CacheType.MYSTERY, false); + final SearchResult search = GCParser.searchByOwner(null, "blafoo", CacheType.MYSTERY, false); assertNotNull(search); assertEquals(3, search.getGeocodes().size()); assertTrue(search.getGeocodes().contains("GC36RT6")); @@ -213,7 +214,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static void testSearchByUsername() { - final SearchResult search = cgBase.searchByUsername(null, "blafoo", CacheType.WEBCAM, false); + final SearchResult search = GCParser.searchByUsername(null, "blafoo", CacheType.WEBCAM, false); assertNotNull(search); assertEquals(3, search.getTotal()); assertTrue(search.getGeocodes().contains("GCP0A9")); @@ -325,7 +326,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { mockedCache.setMockedDataUser(Settings.getUsername()); cgCache parsedCache = cgeoApplicationTest.testSearchByGeocode(mockedCache.getGeocode()); if (null != parsedCache) { - cgBaseTest.testCompareCaches(mockedCache, parsedCache, true); + Compare.assertCompareCaches(mockedCache, parsedCache, true); } } } diff --git a/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java b/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java index e6a2474..88873a1 100644 --- a/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCBaseTest.java @@ -1,11 +1,11 @@ package cgeo.geocaching.connector.gc; import cgeo.geocaching.SearchResult; -import cgeo.geocaching.cgBaseTest; import cgeo.geocaching.cgCache; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.test.mock.GC2CJPF; import cgeo.geocaching.test.mock.MockedCache; +import cgeo.test.Compare; import java.util.HashSet; import java.util.Set; @@ -37,7 +37,7 @@ public class GCBaseTest extends TestCase { SearchResult result = GCBase.searchByGeocodes(geocodes); cgCache parsedCache = result.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_ONLY); - cgBaseTest.testCompareCaches(mockedCache, parsedCache, false); + Compare.assertCompareCaches(mockedCache, parsedCache, false); } } diff --git a/tests/src/cgeo/geocaching/cgBaseTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java index 1f80ac6..54f69ce 100644 --- a/tests/src/cgeo/geocaching/cgBaseTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java @@ -1,16 +1,18 @@ -package cgeo.geocaching; +package cgeo.geocaching.connector.gc; -import cgeo.geocaching.connector.gc.GCConstants; +import cgeo.geocaching.SearchResult; +import cgeo.geocaching.Settings; +import cgeo.geocaching.cgCache; +import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.enumerations.LoadFlags; -import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; import cgeo.geocaching.test.R; import cgeo.geocaching.test.RegExPerformanceTest; import cgeo.geocaching.test.mock.MockedCache; -import cgeo.geocaching.utils.BaseUtils; import cgeo.geocaching.utils.CancellableHandler; +import cgeo.test.Compare; import org.apache.commons.lang3.StringUtils; @@ -18,72 +20,34 @@ import android.test.suitebuilder.annotation.MediumTest; import java.util.ArrayList; -public class cgBaseTest extends AbstractResourceInstrumentationTestCase { - - public static void testRegEx() { - String page = MockedCache.readCachePage("GC2CJPF"); - assertEquals("blafoo", BaseUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, true, "???")); - assertTrue(page.contains("id=\"ctl00_hlRenew\"") || "Premium Member".equals(BaseUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, "???"))); - int cachesFound = 0; - try { - cachesFound = Integer.parseInt(BaseUtils.getMatch(page, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", "")); - } catch (NumberFormatException e) { - fail(); - } - assertTrue(cachesFound >= 491); - } - - public static void testReplaceWhitespaces() { - assertEquals("foo bar baz ", BaseUtils.replaceWhitespace(" foo\n\tbar \r baz ")); - } - - public static void testElevation() { - assertEquals(125.663703918457, (new Geopoint(48.0, 2.0)).getElevation(), 0.1); +public class GCParserTest extends AbstractResourceInstrumentationTestCase { + public void testUnpublishedCache() { + final String page = getFileContent(R.raw.cache_unpublished); + SearchResult result = GCParser.parseCacheFromText(page, null); + assertNotNull(result); + assertTrue(result.isEmpty()); + assertEquals(StatusCode.UNPUBLISHED_CACHE, result.getError()); } - public static void testCompareCaches(ICache expected, cgCache actual, boolean all) { - assertEquals(expected.getGeocode(), actual.getGeocode()); - assertTrue(expected.getType() == actual.getType()); - assertEquals(expected.getOwner(), actual.getOwner()); - assertEquals(expected.getDifficulty(), actual.getDifficulty()); - assertEquals(expected.getTerrain(), actual.getTerrain()); - assertEquals(expected.isDisabled(), actual.isDisabled()); - assertEquals(expected.isArchived(), actual.isArchived()); - assertEquals(expected.getSize(), actual.getSize()); - assertEquals(expected.getName(), actual.getName()); - assertEquals(expected.getGuid(), actual.getGuid()); - assertTrue(expected.getFavoritePoints() <= actual.getFavoritePoints()); - assertEquals(expected.getHiddenDate().toString(), actual.getHiddenDate().toString()); - assertEquals(expected.isPremiumMembersOnly(), actual.isPremiumMembersOnly()); - - if (all) { - assertEquals(expected.getCoords(), actual.getCoords()); - assertTrue(actual.isReliableLatLon()); - assertEquals(expected.isOwn(), actual.isOwn()); - assertEquals(expected.getOwnerReal(), actual.getOwnerReal()); - assertEquals(expected.getHint(), actual.getHint()); - assertTrue(actual.getDescription().startsWith(expected.getDescription())); - assertEquals(expected.getShortDescription(), actual.getShortDescription()); - assertEquals(expected.getCacheId(), actual.getCacheId()); - assertEquals(expected.getLocation(), actual.getLocation()); - assertEquals(expected.getPersonalNote(), actual.getPersonalNote()); - assertEquals(expected.isFound(), actual.isFound()); - assertEquals(expected.isFavorite(), actual.isFavorite()); - assertEquals(expected.isWatchlist(), actual.isWatchlist()); + private static cgCache createCache(int index) { + final MockedCache mockedCache = RegExPerformanceTest.MOCKED_CACHES[index]; + // to get the same results we have to use the date format used when the mocked data was created + String oldCustomDate = Settings.getGcCustomDate(); - for (String attribute : expected.getAttributes()) { - assertTrue(actual.getAttributes().contains(attribute)); - } - for (LogType logType : expected.getLogCounts().keySet()) { - assertTrue(actual.getLogCounts().get(logType) >= expected.getLogCounts().get(logType)); - } + SearchResult searchResult; + try { + Settings.setGcCustomDate(MockedCache.getDateFormat()); + searchResult = GCParser.parseCacheFromText(mockedCache.getData(), null); + } finally { + Settings.setGcCustomDate(oldCustomDate); + } - // the inventory can differ to often, therefore we don't compare them + assertNotNull(searchResult); + assertEquals(1, searchResult.getCount()); - int actualSpoilersSize = null != actual.getSpoilers() ? actual.getSpoilers().size() : 0; - int expectedSpoilersSize = null != expected.getSpoilers() ? expected.getSpoilers().size() : 0; - assertEquals(expectedSpoilersSize, actualSpoilersSize); - } + final cgCache cache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); + assertNotNull(cache); + return cache; } /** @@ -97,10 +61,10 @@ public class cgBaseTest extends AbstractResourceInstrumentationTestCase { for (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 = cgBase.parseCacheFromText(mockedCache.getData(), null); + SearchResult searchResult = GCParser.parseCacheFromText(mockedCache.getData(), null); cgCache parsedCache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); assertTrue(StringUtils.isNotBlank(mockedCache.getMockedDataUser())); - cgBaseTest.testCompareCaches(mockedCache, parsedCache, true); + Compare.assertCompareCaches(mockedCache, parsedCache, true); } } finally { Settings.setGcCustomDate(gcCustomDate); @@ -108,7 +72,7 @@ public class cgBaseTest extends AbstractResourceInstrumentationTestCase { } public static void testWaypointsFromNote() { - final cgCache cache = cgBaseTest.createCache(0); + final cgCache cache = createCache(0); final Geopoint[] empty = new Geopoint[] {}; final Geopoint[] one = new Geopoint[] { new Geopoint("N51 21.523", "E7 2.680") }; @@ -154,32 +118,4 @@ public class cgBaseTest extends AbstractResourceInstrumentationTestCase { } } - public static cgCache createCache(int index) { - final MockedCache mockedCache = RegExPerformanceTest.MOCKED_CACHES[index]; - // to get the same results we have to use the date format used when the mocked data was created - String oldCustomDate = Settings.getGcCustomDate(); - - SearchResult searchResult; - try { - Settings.setGcCustomDate(MockedCache.getDateFormat()); - searchResult = cgBase.parseCacheFromText(mockedCache.getData(), null); - } finally { - Settings.setGcCustomDate(oldCustomDate); - } - - assertNotNull(searchResult); - assertEquals(1, searchResult.getCount()); - - final cgCache cache = searchResult.getFirstCacheFromResult(LoadFlags.LOAD_CACHE_OR_DB); - assertNotNull(cache); - return cache; - } - - public void testUnpublishedCache() { - final String page = getFileContent(R.raw.cache_unpublished); - SearchResult result = cgBase.parseCacheFromText(page, null); - assertNotNull(result); - assertTrue(result.isEmpty()); - assertEquals(StatusCode.UNPUBLISHED_CACHE, result.getError()); - } -}
\ No newline at end of file +} diff --git a/tests/src/cgeo/geocaching/filter/AbstractFilterTestCase.java b/tests/src/cgeo/geocaching/filter/AbstractFilterTestCase.java index d2aad26..f16d326 100644 --- a/tests/src/cgeo/geocaching/filter/AbstractFilterTestCase.java +++ b/tests/src/cgeo/geocaching/filter/AbstractFilterTestCase.java @@ -1,6 +1,5 @@ package cgeo.geocaching.filter; -import cgeo.geocaching.cgBase; import cgeo.geocaching.cgeoapplication; import android.test.ApplicationTestCase; @@ -17,6 +16,5 @@ public abstract class AbstractFilterTestCase extends ApplicationTestCase<cgeoapp // init environment createApplication(); - cgBase.initialize(getApplication()); } } diff --git a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java b/tests/src/cgeo/geocaching/geopoint/GeopointTest.java index 8bb0956..7990489 100644 --- a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java +++ b/tests/src/cgeo/geocaching/geopoint/GeopointTest.java @@ -246,4 +246,8 @@ public class GeopointTest extends AndroidTestCase { Assert.assertEquals(lonSecFrac, dms.lonSecFrac); } + public static void testElevation() { + assertEquals(125.663703918457, (new Geopoint(48.0, 2.0)).getElevation(), 0.1); + } + } diff --git a/tests/src/cgeo/geocaching/utils/BaseUtilsTest.java b/tests/src/cgeo/geocaching/utils/BaseUtilsTest.java new file mode 100644 index 0000000..e174d1f --- /dev/null +++ b/tests/src/cgeo/geocaching/utils/BaseUtilsTest.java @@ -0,0 +1,26 @@ +package cgeo.geocaching.utils; + +import cgeo.geocaching.connector.gc.GCConstants; +import cgeo.geocaching.test.mock.MockedCache; + +import android.test.AndroidTestCase; + +public class BaseUtilsTest extends AndroidTestCase { + public static void testRegEx() { + String page = MockedCache.readCachePage("GC2CJPF"); + assertEquals("blafoo", BaseUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, true, "???")); + assertTrue(page.contains("id=\"ctl00_hlRenew\"") || "Premium Member".equals(BaseUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, "???"))); + int cachesFound = 0; + try { + cachesFound = Integer.parseInt(BaseUtils.getMatch(page, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", "")); + } catch (NumberFormatException e) { + fail(); + } + assertTrue(cachesFound >= 491); + } + + public static void testReplaceWhitespaces() { + assertEquals("foo bar baz ", BaseUtils.replaceWhitespace(" foo\n\tbar \r baz ")); + } + +} diff --git a/tests/src/cgeo/test/Compare.java b/tests/src/cgeo/test/Compare.java new file mode 100644 index 0000000..432f4e4 --- /dev/null +++ b/tests/src/cgeo/test/Compare.java @@ -0,0 +1,57 @@ +package cgeo.test; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; + +import cgeo.geocaching.ICache; +import cgeo.geocaching.cgCache; +import cgeo.geocaching.enumerations.LogType; + +public abstract class Compare { + + public static void assertCompareCaches(ICache expected, cgCache actual, boolean all) { + assertEquals(expected.getGeocode(), actual.getGeocode()); + assertTrue(expected.getType() == actual.getType()); + assertEquals(expected.getOwner(), actual.getOwner()); + assertEquals(expected.getDifficulty(), actual.getDifficulty()); + assertEquals(expected.getTerrain(), actual.getTerrain()); + assertEquals(expected.isDisabled(), actual.isDisabled()); + assertEquals(expected.isArchived(), actual.isArchived()); + assertEquals(expected.getSize(), actual.getSize()); + assertEquals(expected.getName(), actual.getName()); + assertEquals(expected.getGuid(), actual.getGuid()); + assertTrue(expected.getFavoritePoints() <= actual.getFavoritePoints()); + assertEquals(expected.getHiddenDate().toString(), actual.getHiddenDate().toString()); + assertEquals(expected.isPremiumMembersOnly(), actual.isPremiumMembersOnly()); + + if (all) { + assertEquals(expected.getCoords(), actual.getCoords()); + assertTrue(actual.isReliableLatLon()); + assertEquals(expected.isOwn(), actual.isOwn()); + assertEquals(expected.getOwnerReal(), actual.getOwnerReal()); + assertEquals(expected.getHint(), actual.getHint()); + assertTrue(actual.getDescription().startsWith(expected.getDescription())); + assertEquals(expected.getShortDescription(), actual.getShortDescription()); + assertEquals(expected.getCacheId(), actual.getCacheId()); + assertEquals(expected.getLocation(), actual.getLocation()); + assertEquals(expected.getPersonalNote(), actual.getPersonalNote()); + assertEquals(expected.isFound(), actual.isFound()); + assertEquals(expected.isFavorite(), actual.isFavorite()); + assertEquals(expected.isWatchlist(), actual.isWatchlist()); + + for (String attribute : expected.getAttributes()) { + assertTrue(actual.getAttributes().contains(attribute)); + } + for (LogType logType : expected.getLogCounts().keySet()) { + assertTrue(actual.getLogCounts().get(logType) >= expected.getLogCounts().get(logType)); + } + + // the inventory can differ to often, therefore we don't compare them + + int actualSpoilersSize = null != actual.getSpoilers() ? actual.getSpoilers().size() : 0; + int expectedSpoilersSize = null != expected.getSpoilers() ? expected.getSpoilers().size() : 0; + assertEquals(expectedSpoilersSize, actualSpoilersSize); + } + } + +} |
