aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo/geocaching
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-05-24 08:03:38 +0200
committerBananeweizen <bananeweizen@gmx.de>2013-05-24 08:03:38 +0200
commit04f1bf0386776de8ca6e3eb95c2d6bfde5401ed2 (patch)
tree40008e89acd5d2739e9561e228b018b907be1a73 /tests/src/cgeo/geocaching
parentf6ed7c0e2cee57503de2c2582dd29536e6cfdf0a (diff)
downloadcgeo-04f1bf0386776de8ca6e3eb95c2d6bfde5401ed2.zip
cgeo-04f1bf0386776de8ca6e3eb95c2d6bfde5401ed2.tar.gz
cgeo-04f1bf0386776de8ca6e3eb95c2d6bfde5401ed2.tar.bz2
fix #2764: remove temporary caches after test
Diffstat (limited to 'tests/src/cgeo/geocaching')
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java23
-rw-r--r--tests/src/cgeo/geocaching/files/LocParserTest.java2
-rw-r--r--tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java26
3 files changed, 29 insertions, 22 deletions
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index f6c0b99..8fd962e 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -2,8 +2,6 @@ package cgeo.geocaching.files;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.LogEntry;
-import cgeo.geocaching.SearchResult;
-import cgeo.geocaching.StoredList;
import cgeo.geocaching.Waypoint;
import cgeo.geocaching.cgData;
import cgeo.geocaching.enumerations.CacheSize;
@@ -29,7 +27,6 @@ import java.util.Set;
public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
private static final SimpleDateFormat LOG_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); // 2010-04-20T07:00:00Z
- private int listId;
public void testGPXVersion100() throws Exception {
testGPXVersion(R.raw.gc1bkp3_gpx100);
@@ -189,12 +186,12 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
}
private List<Geocache> readGPX10(int... resourceIds) throws IOException, ParserException {
- final GPX10Parser parser = new GPX10Parser(listId);
+ final GPX10Parser parser = new GPX10Parser(getTemporaryListId());
return readVersionedGPX(parser, resourceIds);
}
private List<Geocache> readGPX11(int... resourceIds) throws IOException, ParserException {
- final GPX11Parser parser = new GPX11Parser(listId);
+ final GPX11Parser parser = new GPX11Parser(getTemporaryListId());
return readVersionedGPX(parser, resourceIds);
}
@@ -284,20 +281,4 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
removeCacheCompletely(geocode);
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- listId = cgData.createList("Temporary unit testing");
- assertTrue(listId != StoredList.TEMPORARY_LIST_ID);
- assertTrue(listId != StoredList.STANDARD_LIST_ID);
- }
-
- @Override
- protected void tearDown() throws Exception {
- final SearchResult search = cgData.getBatchOfStoredCaches(null, CacheType.ALL, listId);
- assertNotNull(search);
- cgData.removeCaches(search.getGeocodes(), LoadFlags.REMOVE_ALL);
- cgData.removeList(listId);
- super.tearDown();
- }
}
diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java
index c95d860..bcc8e78 100644
--- a/tests/src/cgeo/geocaching/files/LocParserTest.java
+++ b/tests/src/cgeo/geocaching/files/LocParserTest.java
@@ -14,7 +14,7 @@ import java.util.List;
public class LocParserTest extends AbstractResourceInstrumentationTestCase {
private List<Geocache> readLoc(int resourceId) throws IOException, ParserException {
- final LocParser parser = new LocParser(1);
+ final LocParser parser = new LocParser(getTemporaryListId());
Collection<Geocache> caches = null;
final InputStream instream = getResourceStream(resourceId);
try {
diff --git a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
index cd8b5e7..304f98d 100644
--- a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
+++ b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
@@ -1,6 +1,9 @@
package cgeo.geocaching.test;
+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;
@@ -15,6 +18,8 @@ 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 +57,25 @@ 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;
+ }
}