diff options
Diffstat (limited to 'tests/src')
| -rw-r--r-- | tests/src/cgeo/geocaching/files/GPXParserTest.java | 21 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java | 27 |
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java index 4b4f286..6f8a76d 100644 --- a/tests/src/cgeo/geocaching/files/GPXParserTest.java +++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java @@ -7,6 +7,7 @@ import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; +import cgeo.geocaching.enumerations.LoadFlags.LoadFlag; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase; @@ -18,6 +19,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; +import java.util.EnumSet; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -253,4 +255,23 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase { assertTrue(codes.contains("GC2KN6K")); assertTrue(codes.contains("GC1T3MK")); } + + public void testLazyLogLoading() throws IOException, ParserException { + // this test should be in CacheTest, but it is easier to create here due to the GPX import abilities + final String geocode = "GC31J2H"; + removeCacheCompletely(geocode); + final List<cgCache> caches = readGPX10(R.raw.lazy); + assertEquals(1, caches.size()); + cgeoapplication.getInstance().removeAllFromCache(); + + // load only the minimum cache, it has several members missing + final cgCache minimalCache = cgeoapplication.getInstance().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()); + + removeCacheCompletely(geocode); + } + } diff --git a/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java b/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java new file mode 100644 index 0000000..1d0767e --- /dev/null +++ b/tests/src/cgeo/geocaching/utils/LazyInitializedListTest.java @@ -0,0 +1,27 @@ +package cgeo.geocaching.utils; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +public class LazyInitializedListTest extends TestCase { + public static void testAccess() { + final LazyInitializedList<String> list = new LazyInitializedList<String>() { + @Override + protected List<String> loadFromDatabase() { + return new ArrayList<String>(); + } + }; + assertTrue(list.isEmpty()); + list.add("Test"); + assertFalse(list.isEmpty()); + assertEquals(1, list.size()); + int iterations = 0; + for (String element : list) { + assertEquals("Test", element); + iterations++; + } + assertEquals(1, iterations); + } +} |
