diff options
Diffstat (limited to 'tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java')
| -rw-r--r-- | tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java index cd8b5e7..cb8238f 100644 --- a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java +++ b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java @@ -1,8 +1,14 @@ package cgeo.geocaching.test; +import cgeo.geocaching.Geocache; +import cgeo.geocaching.SearchResult; +import cgeo.geocaching.StoredList; import cgeo.geocaching.cgData; +import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; +import cgeo.geocaching.files.GPX10Parser; +import cgeo.geocaching.files.ParserException; import android.content.res.Resources; import android.test.InstrumentationTestCase; @@ -11,10 +17,13 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.Collection; import java.util.EnumSet; import java.util.Scanner; public abstract class AbstractResourceInstrumentationTestCase extends InstrumentationTestCase { + private int temporaryListId; + protected static void removeCacheCompletely(final String geocode) { final EnumSet<RemoveFlag> flags = EnumSet.copyOf(LoadFlags.REMOVE_ALL); flags.add(RemoveFlag.REMOVE_OWN_WAYPOINTS_ONLY_FOR_TESTING); @@ -52,4 +61,38 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument is.close(); } } + + @Override + protected void setUp() throws Exception { + super.setUp(); + temporaryListId = cgData.createList("Temporary unit testing"); + assertTrue(temporaryListId != StoredList.TEMPORARY_LIST_ID); + assertTrue(temporaryListId != StoredList.STANDARD_LIST_ID); + } + + @Override + protected void tearDown() throws Exception { + final SearchResult search = cgData.getBatchOfStoredCaches(null, CacheType.ALL, temporaryListId); + assertNotNull(search); + cgData.removeCaches(search.getGeocodes(), LoadFlags.REMOVE_ALL); + cgData.removeList(temporaryListId); + super.tearDown(); + } + + protected final int getTemporaryListId() { + return temporaryListId; + } + + final protected Geocache loadCacheFromResource(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); + assertNotNull(caches); + assertFalse(caches.isEmpty()); + return caches.iterator().next(); + } finally { + instream.close(); + } + } } |
