diff options
author | blafoo <github@blafoo.de> | 2011-12-18 23:40:58 +0100 |
---|---|---|
committer | blafoo <github@blafoo.de> | 2011-12-18 23:42:27 +0100 |
commit | 3270b85786317f43c2db3719f40f2eb06903e6c5 (patch) | |
tree | 87844988f76d0eba96d38f91ea69447229c0661b /tests | |
parent | fc42b60c464029ccd8a50e40e137014cb44547ba (diff) | |
download | cgeo-3270b85786317f43c2db3719f40f2eb06903e6c5.zip cgeo-3270b85786317f43c2db3719f40f2eb06903e6c5.tar.gz cgeo-3270b85786317f43c2db3719f40f2eb06903e6c5.tar.bz2 |
User independent tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/cgeo/geocaching/cgBaseTest.java | 20 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/cgeoApplicationTest.java | 21 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java | 8 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/test/mock/GC2CJPF.java | 26 | ||||
-rw-r--r-- | tests/src/cgeo/geocaching/test/mock/MockedCache.java | 22 |
5 files changed, 64 insertions, 33 deletions
diff --git a/tests/src/cgeo/geocaching/cgBaseTest.java b/tests/src/cgeo/geocaching/cgBaseTest.java index 94f1a9a..ab88952 100644 --- a/tests/src/cgeo/geocaching/cgBaseTest.java +++ b/tests/src/cgeo/geocaching/cgBaseTest.java @@ -42,8 +42,15 @@ public class cgBaseTest extends AndroidTestCase { Assert.assertEquals(expected.getName(), actual.getName()); Assert.assertEquals(expected.getCacheId(), actual.getCacheId()); Assert.assertEquals(expected.getGuid(), actual.getGuid()); - // Assert.assertEquals(expected.getLocation(), actual.getLocation()); - Assert.assertEquals(expected.getPersonalNote(), actual.getPersonalNote()); + Assert.assertEquals(expected.getLocation(), actual.getLocation()); + // the personal note is different for premium and non-premium user: + // null for non-premium, empty string for premium users. + int actualPersonalNoteLength = null != actual.getPersonalNote() ? actual.getPersonalNote().length() : 0; + int expectedPersonalNoteLength = null != expected.getPersonalNote() ? expected.getPersonalNote().length() : 0; + Assert.assertEquals(expectedPersonalNoteLength, actualPersonalNoteLength); + if (expectedPersonalNoteLength == actualPersonalNoteLength && expectedPersonalNoteLength > 0) { + Assert.assertEquals(expected.getPersonalNote(), actual.getPersonalNote()); + } Assert.assertEquals(expected.isFound(), actual.isFound()); Assert.assertEquals(expected.isFavorite(), actual.isFavorite()); Assert.assertEquals(expected.getFavoritePoints(), actual.getFavoritePoints()); @@ -57,18 +64,17 @@ public class cgBaseTest extends AndroidTestCase { } int actualInventorySize = null != actual.getInventory() ? actual.getInventory().size() : 0; - int expectInventorysize = null != expected.getInventory() ? expected.getInventory().size() : 0; - Assert.assertEquals(expectInventorysize, actualInventorySize); + int expectedInventorySize = null != expected.getInventory() ? expected.getInventory().size() : 0; + Assert.assertEquals(expectedInventorySize, actualInventorySize); int actualSpoilersSize = null != actual.getSpoilers() ? actual.getSpoilers().size() : 0; - int expectSpoilerssize = null != expected.getSpoilers() ? expected.getSpoilers().size() : 0; - Assert.assertEquals(expectSpoilerssize, actualSpoilersSize); + int expectedSpoilersSize = null != expected.getSpoilers() ? expected.getSpoilers().size() : 0; + Assert.assertEquals(expectedSpoilersSize, actualSpoilersSize); } /** * Test {@link cgBase#parseCacheFromText(String, int, CancellableHandler)} with "mocked" data * - * @param base */ @MediumTest public static void testParseCacheFromTextWithMockedData() { diff --git a/tests/src/cgeo/geocaching/cgeoApplicationTest.java b/tests/src/cgeo/geocaching/cgeoApplicationTest.java index a22ce94..f23a6ce 100644 --- a/tests/src/cgeo/geocaching/cgeoApplicationTest.java +++ b/tests/src/cgeo/geocaching/cgeoApplicationTest.java @@ -1,6 +1,7 @@ package cgeo.geocaching; import cgeo.geocaching.enumerations.CacheType; +import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.test.RegExPerformanceTest; import cgeo.geocaching.test.mock.MockedCache; @@ -85,11 +86,15 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ @MediumTest public static cgCache testSearchByGeocode(final String geocode) { - final cgSearch search = cgBase.searchByGeocode(geocode, null, 0, true, null); + final cgSearch search = cgBase.searchByGeocode(geocode, null, 1, true, null); assertNotNull(search); - assertEquals(1, search.getGeocodes().size()); - assertTrue(search.getGeocodes().contains(geocode)); - return cgeoapplication.getInstance().getCacheByGeocode(geocode); + if (Settings.isPremiumMember() || search.error == null) { + assertEquals(1, search.getGeocodes().size()); + assertTrue(search.getGeocodes().contains(geocode)); + return cgeoapplication.getInstance().getCacheByGeocode(geocode); + } + assertEquals(0, search.getGeocodes().size()); + return null; } /** @@ -98,7 +103,8 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { @MediumTest public static void testSearchByGeocodeNotExisting() { final cgSearch search = cgBase.searchByGeocode("GC123456", null, 0, true, null); - assertNull(search); + assertNotNull(search); + assertEquals(search.error, StatusCode.UNPUBLISHED_CACHE); } /** @@ -139,8 +145,11 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { */ public static void testCacheBasics() { for (MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) { + mockedCache.setMockedDataUser(Settings.getUsername()); cgCache parsedCache = cgeoApplicationTest.testSearchByGeocode(mockedCache.getGeocode()); - cgBaseTest.testCompareCaches(mockedCache, parsedCache); + if (null != parsedCache) { + cgBaseTest.testCompareCaches(mockedCache, parsedCache); + } } } diff --git a/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java b/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java index 5ad739d..bfbde87 100644 --- a/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java +++ b/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java @@ -87,10 +87,10 @@ public class GC1ZXX2 extends MockedCache { @Override public boolean isWatchlist() { - if ("blafoo".equals(this.getUserLoggedIn())) { + if ("blafoo".equals(this.getMockedDataUser())) { return true; } - return false; + return super.isWatchlist(); } @Override @@ -140,10 +140,10 @@ public class GC1ZXX2 extends MockedCache { @Override public String getPersonalNote() { - if ("blafoo".equals(this.getUserLoggedIn())) { + if ("blafoo".equals(this.getMockedDataUser())) { return "Test für c:geo"; } - return null; + return super.getPersonalNote(); } } diff --git a/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java b/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java index e23b883..6f04e74 100644 --- a/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java +++ b/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java @@ -1,5 +1,6 @@ package cgeo.geocaching.test.mock; +import cgeo.geocaching.Settings; import cgeo.geocaching.cgBase; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; @@ -95,18 +96,31 @@ public class GC2CJPF extends MockedCache { @Override public boolean isFound() { - if ("blafoo".equals(this.getUserLoggedIn())) { + if ("blafoo".equals(this.getMockedDataUser())) { return true; } - return false; + return super.isFound(); + } + + /* + * (non-Javadoc) + * + * @see cgeo.geocaching.test.mock.MockedCache#isOwn() + */ + @Override + public boolean isOwn() { + if ("Tom03".equals(Settings.getUsername())) { + return true; + } + return super.isOwn(); } @Override public boolean isFavorite() { - if ("blafoo".equals(this.getUserLoggedIn())) { + if ("blafoo".equals(this.getMockedDataUser())) { return true; } - return false; + return super.isFavorite(); } @Override @@ -157,7 +171,7 @@ public class GC2CJPF extends MockedCache { @Override public String getLatitude() { - if ("blafoo".equals(this.getUserLoggedIn())) { + if ("blafoo".equals(this.getMockedDataUser())) { return userCoords.format(GeopointFormatter.Format.LAT_DECMINUTE); } return coords.format(GeopointFormatter.Format.LAT_DECMINUTE); @@ -165,7 +179,7 @@ public class GC2CJPF extends MockedCache { @Override public String getLongitude() { - if ("blafoo".equals(this.getUserLoggedIn())) { + if ("blafoo".equals(this.getMockedDataUser())) { return userCoords.format(GeopointFormatter.Format.LON_DECMINUTE); } return coords.format(GeopointFormatter.Format.LON_DECMINUTE); diff --git a/tests/src/cgeo/geocaching/test/mock/MockedCache.java b/tests/src/cgeo/geocaching/test/mock/MockedCache.java index 62f3369..46d72e2 100644 --- a/tests/src/cgeo/geocaching/test/mock/MockedCache.java +++ b/tests/src/cgeo/geocaching/test/mock/MockedCache.java @@ -8,8 +8,6 @@ import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.GeopointFormatter; import cgeo.geocaching.utils.BaseUtils; -import org.apache.commons.lang3.StringUtils; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -20,14 +18,21 @@ public abstract class MockedCache implements ICache { final protected Geopoint coords; String data; + String mockedDataUser; protected MockedCache(final Geopoint coords) { this.coords = coords; - this.data = getData(); + this.data = MockedCache.readCachePage(getGeocode()); + // for mocked caches the user logged in is the user who saved the html file(s) + this.mockedDataUser = BaseUtils.getMatch(data, GCConstants.PATTERN_USERLOGGEDIN, true, ""); + } + + public String getMockedDataUser() { + return mockedDataUser; } - protected String getUserLoggedIn() { - return BaseUtils.getMatch(data, GCConstants.PATTERN_USERLOGGEDIN, true, ""); + public void setMockedDataUser(String mockedDataUser) { + this.mockedDataUser = mockedDataUser; } /* @@ -36,10 +41,7 @@ public abstract class MockedCache implements ICache { * into a browser and saving the file */ public String getData() { - if (StringUtils.isEmpty(data)) { - data = MockedCache.readCachePage(getGeocode()); - } - return data; + return this.data; } public static String readCachePage(final String geocode) { @@ -104,7 +106,7 @@ public abstract class MockedCache implements ICache { @Override public String getPersonalNote() { - return ""; + return null; } @Override |