aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/cgeo
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/cgeo')
-rw-r--r--tests/src/cgeo/geocaching/cgBaseTest.java9
-rw-r--r--tests/src/cgeo/geocaching/cgeoApplicationTest.java4
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java7
-rw-r--r--tests/src/cgeo/geocaching/files/GPXImporterTest.java2
-rw-r--r--tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java15
-rw-r--r--tests/src/cgeo/geocaching/test/WhitespaceTest.java20
6 files changed, 29 insertions, 28 deletions
diff --git a/tests/src/cgeo/geocaching/cgBaseTest.java b/tests/src/cgeo/geocaching/cgBaseTest.java
index e669535..b6ad561 100644
--- a/tests/src/cgeo/geocaching/cgBaseTest.java
+++ b/tests/src/cgeo/geocaching/cgBaseTest.java
@@ -24,12 +24,17 @@ public class cgBaseTest extends AbstractResourceInstrumentationTestCase {
String page = MockedCache.readCachePage("GC2CJPF");
assertEquals("blafoo", BaseUtils.getMatch(page, GCConstants.PATTERN_LOGIN_NAME, true, "???"));
assertTrue(page.contains("id=\"ctl00_hlRenew\"") || "Premium Member".equals(BaseUtils.getMatch(page, GCConstants.PATTERN_MEMBER_STATUS, true, "???")));
- int cachesFound = Integer.parseInt(BaseUtils.getMatch(page, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", ""));
+ int cachesFound = 0;
+ try {
+ cachesFound = Integer.parseInt(BaseUtils.getMatch(page, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", ""));
+ } catch (NumberFormatException e) {
+ fail();
+ }
assertTrue(cachesFound >= 491);
}
public static void testReplaceWhitespaces() {
- assertEquals("foo bar baz ", BaseUtils.replaceWhitespace(new String(" foo\n\tbar \r baz ")));
+ assertEquals("foo bar baz ", BaseUtils.replaceWhitespace(" foo\n\tbar \r baz "));
}
public static void testElevation() {
diff --git a/tests/src/cgeo/geocaching/cgeoApplicationTest.java b/tests/src/cgeo/geocaching/cgeoApplicationTest.java
index 91d2320..c4ab0e3 100644
--- a/tests/src/cgeo/geocaching/cgeoApplicationTest.java
+++ b/tests/src/cgeo/geocaching/cgeoApplicationTest.java
@@ -231,7 +231,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
GC2CJPF mockedCache = new GC2CJPF();
deleteCacheFromDB(mockedCache.getGeocode());
- final String tokens[] = GCBase.getTokens();
+ final String[] tokens = GCBase.getTokens();
final Viewport viewport = new Viewport(mockedCache.getCoords(), 0.003, 0.003);
// check coords for DETAILED
@@ -275,7 +275,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
try {
- final String tokens[] = null; // without a valid token we are "logged off"
+ final String[] tokens = null; // without a valid token we are "logged off"
// non premium cache
MockedCache cache = new GC2CJPF();
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java
index c930ab5..809318a 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCConstantsTest.java
@@ -1,6 +1,5 @@
package cgeo.geocaching.connector.gc;
-import cgeo.geocaching.connector.gc.GCConstants;
import cgeo.geocaching.test.mock.MockedCache;
import cgeo.geocaching.utils.BaseUtils;
@@ -31,7 +30,11 @@ public class GCConstantsTest extends AndroidTestCase {
}
private static void assertCacheCount(final int count, final String html) {
- assertEquals(count, Integer.parseInt(BaseUtils.getMatch(html, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", "")));
+ try {
+ assertEquals(count, Integer.parseInt(BaseUtils.getMatch(html, GCConstants.PATTERN_CACHES_FOUND, true, "0").replaceAll("[,.]", "")));
+ } catch (NumberFormatException e) {
+ fail();
+ }
}
public static void testConstants() {
diff --git a/tests/src/cgeo/geocaching/files/GPXImporterTest.java b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
index 10d60b3..b8a3354 100644
--- a/tests/src/cgeo/geocaching/files/GPXImporterTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXImporterTest.java
@@ -231,7 +231,7 @@ public class GPXImporterTest extends AbstractResourceInstrumentationTestCase {
@Override
public synchronized void handleRegularMessage(Message msg) {
- final Message msg1 = new Message();
+ final Message msg1 = Message.obtain();
msg1.copyFrom(msg);
messages.add(msg1);
lastMessage = System.currentTimeMillis();
diff --git a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
index 906b414..e07a518 100644
--- a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
+++ b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
@@ -16,16 +16,23 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument
}
protected String getFileContent(int resourceId) {
- InputStream ins = getInstrumentation().getContext().getResources().openRawResource(resourceId);
- return new Scanner(ins).useDelimiter("\\A").next();
+ final InputStream ins = getResourceStream(resourceId);
+ final String result = new Scanner(ins).useDelimiter("\\A").next();
+ try {
+ ins.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return result;
}
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];
+ final byte[] buffer = new byte[4096];
int byteCount;
while ((byteCount = is.read(buffer)) >= 0) {
os.write(buffer, 0, byteCount);
diff --git a/tests/src/cgeo/geocaching/test/WhitespaceTest.java b/tests/src/cgeo/geocaching/test/WhitespaceTest.java
index d2d21dc..59367a5 100644
--- a/tests/src/cgeo/geocaching/test/WhitespaceTest.java
+++ b/tests/src/cgeo/geocaching/test/WhitespaceTest.java
@@ -6,12 +6,8 @@ import cgeo.geocaching.utils.BaseUtils;
import org.apache.commons.lang3.StringUtils;
-import android.test.AndroidTestCase;
import android.util.Log;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -20,25 +16,15 @@ import java.util.regex.Pattern;
* It does not test semantical correctness.
*
*/
-public class WhitespaceTest extends AndroidTestCase {
+public class WhitespaceTest extends AbstractResourceInstrumentationTestCase {
private final static int EXPECTED_SIZE = 122907;
private String data;
@Override
protected void setUp() throws Exception {
- final StringBuilder buffer = new StringBuilder(4096);
- final InputStream is = this.getClass().getResourceAsStream("/cgeo/geocaching/test/mock/GC2CJPF.html");
- final BufferedReader br = new BufferedReader(new InputStreamReader(is), 4096);
-
- String line = null;
-
- while ((line = br.readLine()) != null) {
- buffer.append(line).append('\n');
- }
- data = buffer.toString();
-
- br.close();
+ super.setUp();
+ data = getFileContent(R.raw.gc2cjpf_html);
}
/**