aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/cgeo/geocaching/ParserTest.java13
-rw-r--r--tests/src/cgeo/geocaching/TrackablesTest.java12
-rw-r--r--tests/src/cgeo/geocaching/connector/ConnectorFactoryTest.java31
-rw-r--r--tests/src/cgeo/geocaching/connector/opencaching/OkapiClientTest.java17
-rw-r--r--tests/src/cgeo/geocaching/enumerations/CacheSizeTest.java11
-rw-r--r--tests/src/cgeo/geocaching/enumerations/CacheTypeTest.java13
-rw-r--r--tests/src/cgeo/geocaching/enumerations/LogTypeTrackableTest.java11
-rw-r--r--tests/src/cgeo/geocaching/enumerations/WaypointTypeTest.java11
-rw-r--r--tests/src/cgeo/geocaching/files/GPXImporterTest.java22
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java9
-rw-r--r--tests/src/cgeo/geocaching/files/LocParserTest.java9
-rw-r--r--tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java38
-rw-r--r--tests/src/cgeo/geocaching/test/mock/GC2JVEH.java17
13 files changed, 153 insertions, 61 deletions
diff --git a/tests/src/cgeo/geocaching/ParserTest.java b/tests/src/cgeo/geocaching/ParserTest.java
index ca4a171..18a11df 100644
--- a/tests/src/cgeo/geocaching/ParserTest.java
+++ b/tests/src/cgeo/geocaching/ParserTest.java
@@ -1,18 +1,9 @@
package cgeo.geocaching;
+import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
-import android.test.InstrumentationTestCase;
-
-import java.io.InputStream;
-import java.util.Scanner;
-
-public class ParserTest extends InstrumentationTestCase {
-
- private String getFileContent(int resourceId) {
- InputStream ins = getInstrumentation().getContext().getResources().openRawResource(resourceId);
- return new Scanner(ins).useDelimiter("\\A").next();
- }
+public class ParserTest extends AbstractResourceInstrumentationTestCase {
public void testOwnerDecoding() {
cgCacheWrap caches = cgBase.parseCacheFromText(getFileContent(R.raw.gc1zxez), 0, null);
diff --git a/tests/src/cgeo/geocaching/TrackablesTest.java b/tests/src/cgeo/geocaching/TrackablesTest.java
index da4afa3..f66d33c 100644
--- a/tests/src/cgeo/geocaching/TrackablesTest.java
+++ b/tests/src/cgeo/geocaching/TrackablesTest.java
@@ -1,15 +1,12 @@
package cgeo.geocaching;
+import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
import cgeo.geocaching.utils.BaseUtils;
-import android.test.InstrumentationTestCase;
-
-import java.io.InputStream;
import java.util.List;
-import java.util.Scanner;
-public class TrackablesTest extends InstrumentationTestCase {
+public class TrackablesTest extends AbstractResourceInstrumentationTestCase {
public void testLogPageWithTrackables() {
List<cgTrackableLog> tbLogs = cgBase.parseTrackableLog(getFileContent(R.raw.log_with_2tb));
@@ -52,11 +49,6 @@ public class TrackablesTest extends InstrumentationTestCase {
assertNull(trackable.getOrigin());
}
- private String getFileContent(int resourceId) {
- InputStream ins = getInstrumentation().getContext().getResources().openRawResource(resourceId);
- return new Scanner(ins).useDelimiter("\\A").next();
- }
-
private cgTrackable getTB2R124() {
return cgBase.parseTrackable(BaseUtils.replaceWhitespace(getFileContent(R.raw.trackable_tb2r124)), null);
}
diff --git a/tests/src/cgeo/geocaching/connector/ConnectorFactoryTest.java b/tests/src/cgeo/geocaching/connector/ConnectorFactoryTest.java
new file mode 100644
index 0000000..043a6b1
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/ConnectorFactoryTest.java
@@ -0,0 +1,31 @@
+package cgeo.geocaching.connector;
+
+import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
+import cgeo.geocaching.test.mock.GC1ZXX2;
+
+public class ConnectorFactoryTest extends AbstractResourceInstrumentationTestCase {
+
+ public void testGetConnectors() {
+ IConnector[] connectors = ConnectorFactory.getConnectors();
+ assertNotNull(connectors);
+ assertTrue(connectors.length > 0); // unknown connector must exist
+ }
+
+ public void testCanHandle() {
+ assertFalse(ConnectorFactory.canHandle(""));
+ assertTrue(ConnectorFactory.canHandle("GC12345"));
+ assertTrue(ConnectorFactory.canHandle("some string")); // using unknown connector
+ assertFalse(ConnectorFactory.canHandle("[/start with special char"));
+ }
+
+ public void testGetConnectorCgCache() {
+ assertEquals(GCConnector.getInstance(), ConnectorFactory.getConnector(new GC1ZXX2()));
+ }
+
+ public void testGetConnectorString() {
+ IConnector connector = ConnectorFactory.getConnector("GC12345");
+ assertNotNull(connector);
+ assertEquals(GCConnector.getInstance().getName(), connector.getName());
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/connector/opencaching/OkapiClientTest.java b/tests/src/cgeo/geocaching/connector/opencaching/OkapiClientTest.java
new file mode 100644
index 0000000..ea9dcae
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/opencaching/OkapiClientTest.java
@@ -0,0 +1,17 @@
+package cgeo.geocaching.connector.opencaching;
+
+import cgeo.geocaching.cgCache;
+
+import android.test.AndroidTestCase;
+
+public class OkapiClientTest extends AndroidTestCase {
+
+ public void testGetOCCache() {
+ String geoCode = "OU0331";
+ cgCache cache = OkapiClient.getCache(geoCode);
+ assertNotNull(cache);
+ assertEquals(geoCode, cache.getGeocode());
+ assertEquals("Oshkosh Municipal Tank", cache.getName());
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/enumerations/CacheSizeTest.java b/tests/src/cgeo/geocaching/enumerations/CacheSizeTest.java
new file mode 100644
index 0000000..8617629
--- /dev/null
+++ b/tests/src/cgeo/geocaching/enumerations/CacheSizeTest.java
@@ -0,0 +1,11 @@
+package cgeo.geocaching.enumerations;
+
+import android.test.AndroidTestCase;
+
+public class CacheSizeTest extends AndroidTestCase {
+ public void testOrder() {
+ assertTrue(CacheSize.MICRO.comparable < CacheSize.SMALL.comparable);
+ assertTrue(CacheSize.SMALL.comparable < CacheSize.REGULAR.comparable);
+ assertTrue(CacheSize.REGULAR.comparable < CacheSize.LARGE.comparable);
+ }
+}
diff --git a/tests/src/cgeo/geocaching/enumerations/CacheTypeTest.java b/tests/src/cgeo/geocaching/enumerations/CacheTypeTest.java
new file mode 100644
index 0000000..52c8fe1
--- /dev/null
+++ b/tests/src/cgeo/geocaching/enumerations/CacheTypeTest.java
@@ -0,0 +1,13 @@
+package cgeo.geocaching.enumerations;
+
+import android.test.AndroidTestCase;
+
+public class CacheTypeTest extends AndroidTestCase {
+
+ public void testGetById() {
+ assertEquals(CacheType.UNKNOWN, CacheType.getById(""));
+ assertEquals(CacheType.UNKNOWN, CacheType.getById(null));
+ assertEquals(CacheType.UNKNOWN, CacheType.getById("random garbage"));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/enumerations/LogTypeTrackableTest.java b/tests/src/cgeo/geocaching/enumerations/LogTypeTrackableTest.java
new file mode 100644
index 0000000..7f26db6
--- /dev/null
+++ b/tests/src/cgeo/geocaching/enumerations/LogTypeTrackableTest.java
@@ -0,0 +1,11 @@
+package cgeo.geocaching.enumerations;
+
+import android.test.AndroidTestCase;
+
+public class LogTypeTrackableTest extends AndroidTestCase {
+
+ public void testFindById() {
+ assertEquals(LogTypeTrackable.DO_NOTHING, LogTypeTrackable.findById(12345));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/enumerations/WaypointTypeTest.java b/tests/src/cgeo/geocaching/enumerations/WaypointTypeTest.java
new file mode 100644
index 0000000..0363205
--- /dev/null
+++ b/tests/src/cgeo/geocaching/enumerations/WaypointTypeTest.java
@@ -0,0 +1,11 @@
+package cgeo.geocaching.enumerations;
+
+import android.test.AndroidTestCase;
+
+public class WaypointTypeTest extends AndroidTestCase {
+
+ public void testFindById() {
+ assertEquals(WaypointType.WAYPOINT, WaypointType.findById("random garbage"));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/files/GPXImporterTest.java b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
index 182e5e9..d23521b 100644
--- a/tests/src/cgeo/geocaching/files/GPXImporterTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
@@ -3,21 +3,19 @@ package cgeo.geocaching.files;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgSearch;
import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
import cgeo.geocaching.utils.CancellableHandler;
import android.os.Message;
-import android.test.InstrumentationTestCase;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-public class GPXImporterTest extends InstrumentationTestCase {
+public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
private TestHandler importStepHandler = new TestHandler();
private TestHandler progressHandler = new TestHandler();
private int listId;
@@ -132,22 +130,6 @@ public class GPXImporterTest extends InstrumentationTestCase {
assertEquals(GPXImporter.IMPORT_STEP_CANCELED, importStepHandler.messages.get(1).what);
}
- private void copyResourceToFile(int resourceId, File file) throws IOException {
- final InputStream is = getInstrumentation().getContext().getResources().openRawResource(resourceId);
- final FileOutputStream os = new FileOutputStream(file);
-
- try {
- byte[] buffer = new byte[4096];
- int byteCount;
- while ((byteCount = is.read(buffer)) >= 0) {
- os.write(buffer, 0, byteCount);
- }
- } finally {
- os.close();
- is.close();
- }
- }
-
static class TestHandler extends CancellableHandler {
private final List<Message> messages = new ArrayList<Message>();
private long lastMessage = System.currentTimeMillis();
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index 6f585b3..11d0161 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -8,11 +8,9 @@ import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.GeopointFormatter;
+import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
-import android.content.res.Resources;
-import android.test.InstrumentationTestCase;
-
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
@@ -21,7 +19,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-public class GPXParserTest extends InstrumentationTestCase {
+public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
private static final SimpleDateFormat LOG_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // 2010-04-20T07:00:00Z
public void testGPXVersion100() throws Exception {
@@ -186,8 +184,7 @@ public class GPXParserTest extends InstrumentationTestCase {
private List<cgCache> readVersionedGPX(final GPXParser parser, int... resourceIds) throws IOException, ParserException {
Collection<cgCache> caches = null;
for (int resourceId : resourceIds) {
- final Resources res = getInstrumentation().getContext().getResources();
- final InputStream instream = res.openRawResource(resourceId);
+ final InputStream instream = getResourceStream(resourceId);
try {
caches = parser.parse(instream, null);
assertNotNull(caches);
diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java
index 31e8e13..8facfe4 100644
--- a/tests/src/cgeo/geocaching/files/LocParserTest.java
+++ b/tests/src/cgeo/geocaching/files/LocParserTest.java
@@ -3,23 +3,20 @@ package cgeo.geocaching.files;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
-import android.content.res.Resources;
-import android.test.InstrumentationTestCase;
-
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-public class LocParserTest extends InstrumentationTestCase {
+public class LocParserTest extends AbstractResourceInstrumentationTestCase {
private List<cgCache> readLoc(int resourceId) throws IOException, ParserException {
LocParser parser = new LocParser(1);
Collection<cgCache> caches = null;
- final Resources res = getInstrumentation().getContext().getResources();
- final InputStream instream = res.openRawResource(resourceId);
+ final InputStream instream = getResourceStream(resourceId);
try {
caches = parser.parse(instream, null);
assertNotNull(caches);
diff --git a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
new file mode 100644
index 0000000..906b414
--- /dev/null
+++ b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
@@ -0,0 +1,38 @@
+package cgeo.geocaching.test;
+
+import android.content.res.Resources;
+import android.test.InstrumentationTestCase;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Scanner;
+
+public abstract class AbstractResourceInstrumentationTestCase extends InstrumentationTestCase {
+ protected InputStream getResourceStream(int resourceId) {
+ final Resources res = getInstrumentation().getContext().getResources();
+ return res.openRawResource(resourceId);
+ }
+
+ protected String getFileContent(int resourceId) {
+ InputStream ins = getInstrumentation().getContext().getResources().openRawResource(resourceId);
+ return new Scanner(ins).useDelimiter("\\A").next();
+ }
+
+ protected void copyResourceToFile(int resourceId, File file) throws IOException {
+ final InputStream is = getResourceStream(resourceId);
+ final FileOutputStream os = new FileOutputStream(file);
+
+ try {
+ byte[] buffer = new byte[4096];
+ int byteCount;
+ while ((byteCount = is.read(buffer)) >= 0) {
+ os.write(buffer, 0, byteCount);
+ }
+ } finally {
+ os.close();
+ is.close();
+ }
+ }
+}
diff --git a/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java b/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java
index 1c7ac5b..5ff95b3 100644
--- a/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java
+++ b/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java
@@ -97,7 +97,7 @@ public class GC2JVEH extends MockedCache {
@Override
public List<String> getAttributes() {
- String[] attributes = new String[] {
+ final String[] attributes = new String[] {
"winter_yes",
"flashlight_yes",
"stealth_yes",
@@ -111,7 +111,7 @@ public class GC2JVEH extends MockedCache {
@Override
public Map<Integer, Integer> getLogCounts() {
- Map<Integer, Integer> logCounts = new HashMap<Integer, Integer>();
+ final Map<Integer, Integer> logCounts = new HashMap<Integer, Integer>();
logCounts.put(cgBase.LOG_FOUND_IT, 59);
logCounts.put(cgBase.LOG_NOTE, 7);
logCounts.put(cgBase.LOG_TEMP_DISABLE_LISTING, 1);
@@ -122,7 +122,7 @@ public class GC2JVEH extends MockedCache {
@Override
public Integer getFavoritePoints() {
- return new Integer(21);
+ return 21;
}
@Override
@@ -132,17 +132,18 @@ public class GC2JVEH extends MockedCache {
@Override
public List<cgTrackable> getInventory() {
- ArrayList<cgTrackable> inventory = new ArrayList<cgTrackable>();
+ final ArrayList<cgTrackable> inventory = new ArrayList<cgTrackable>();
inventory.add(new cgTrackable());
return inventory;
}
@Override
public List<cgImage> getSpoilers() {
- ArrayList<cgImage> spoilers = new ArrayList<cgImage>();
- spoilers.add(new cgImage());
- spoilers.add(new cgImage());
- spoilers.add(new cgImage());
+ final ArrayList<cgImage> spoilers = new ArrayList<cgImage>();
+ final cgImage mockedImage = new cgImage(null, null, null);
+ spoilers.add(mockedImage);
+ spoilers.add(mockedImage);
+ spoilers.add(mockedImage);
return spoilers;
}
}