From f0652d4b679eb8039e9ea670dda410b2a34989fb Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Mon, 2 Apr 2012 23:05:16 +0200 Subject: refactoring: more static code analysis cleanups --- tests/res/raw/gc2cjpf_html | 2522 ++++++++++++++++++++ tests/src/cgeo/geocaching/cgBaseTest.java | 9 +- tests/src/cgeo/geocaching/cgeoApplicationTest.java | 4 +- .../geocaching/connector/gc/GCConstantsTest.java | 7 +- .../src/cgeo/geocaching/files/GPXImporterTest.java | 2 +- .../AbstractResourceInstrumentationTestCase.java | 15 +- tests/src/cgeo/geocaching/test/WhitespaceTest.java | 20 +- 7 files changed, 2551 insertions(+), 28 deletions(-) create mode 100644 tests/res/raw/gc2cjpf_html (limited to 'tests') diff --git a/tests/res/raw/gc2cjpf_html b/tests/res/raw/gc2cjpf_html new file mode 100644 index 0000000..5fc0e3f --- /dev/null +++ b/tests/res/raw/gc2cjpf_html @@ -0,0 +1,2522 @@ + + + + + + + GC2CJPF Kinderwald KiC (Multi-cache) in Niedersachsen, Germany created by Tom03 + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ +

+ Geocaching.com

+
+ +
+ +
+ + + + +
+
+ + +
+ + + +
+ + + + + +
+ + + Close +
+ + + +
+ +
+

+ Multi-cache +

+ +

+ Kinderwald KiC

+ + A + cache + by Tom03 + Hidden + : + 31/07/2010 + +
+
+ + Difficulty: +
+ Terrain: + +
+ +
+ + 2.5 out of 5 + 2 out of 5 + +
+ +
+ +

+ Size: Size: Small (Small)

+ +
+ +
+ + + + + +
+ +

+ Related Web Page

+ + + + +
+
+
+

+ + N 52° 25.504 E 009° 39.852 + +
+ + UTM: 32U E 545164 N 5808524 +
+
+ Other Conversions + +

+
+
+ In Niedersachsen, Germany
+ E E 4.8 km from your home location +
+
+
+

+ Print: +
+ + + Print  + No Logs + +   + 5 Logs  + 10 Logs ·  + + Driving Directions  + Driving Directions + +

+ +
+
+

+ Download: + + Read about waypoint downloads + +

+ +

+ + | + + | + + | + +

+ +
+
+ +
+ + Please note + +

+ Use of geocaching.com services is subject to the terms and conditions in our disclaimer. +

+
+ + +
+ + Personal Cache Note + + +

+

+
+ +
+ + Von Nachwuchs-Cachern für Nachwuchs-Cacher. + + +
+ +
+
+ + Kleiner Multi über 7 Stationen. Länge ca. 1 km + 1km für den Rückweg. Die ZS befinden sich alle am KLEINEN BACH innerhalb des Kinderwaldes. Die Fragen müssen nicht in der aufgeführten Reihenfolge beantwortet werden, ihr könnt auch mit der letzten Frage anfangen !
+
+Nähere Infos zum Kinderwald gibt es unter www.kinderwald.de
+
+A. Am Start findet ihr einige Tiere. Wieviele blau-gelbe Punkte hat die grüne Eidechse ?
+
+B. Folgt dem Weg in Richtung Norden und biegt hinter der Brücke gleich links ab. Nach ein paar Metern
+könnt ihr auf der rechten Seite mehrere Tipis sehen, an denen ihr aber vorbei geht. Überquert nun nach ein paar Metern links die Brücke und gelangt auf die kleine Insel wo das Wasser gestaut wird.
+Auf der Insel könnt ihr beim großen Zelt einen "Marterpfahl" finden, dort seht ihr eine (lachende) Blume mit roten Blättern. Wieviele Blätter hat die Blume ?
+
+C. Verlasst die Insel. Auf dem Weg zur nächsten Station kommt ihr in der Kurve an einem großen, allein stehenden Baum vorbei. Was für ein Baum ist das (fünf Buchstaben) ? Hier wird der Buchstabenwert (A=1, B=2,...) des Anfangsbuchstaben benötigt. Evtl. könnt ihr noch die Traumfänger erkennen.
+
+D. Folgt dem Weg ein Stück. Ihr kommt nach kurzer Zeit zum Plumpsklo, der ehemaligen Villa Kunterbunt. Netterweise hat jemand meinen Namen am Eingang hingeschrieben.... Wieviele Personen können das Klo gleichzeitig benutzen ?
+
+E. Weiter geht es. Links findet ihr eine weitere (bunte) Brücke. Dort sind wieviele Kindergesichter zu finden ?
+
+F. Nach ca. 200 Metern kommt ihr zur Seilfähre. An der Seilfähre findet ihr die Antwort (GC= ?)
+
+G. Gegenüber der Seilfähre befindet sich ein Schaukasten mit Nisthilfen für Insekten. Wieviele rote, parallel zum Boden verlaufende Dachträger hat das Dach ?
+
+H. Nach weiteren 250 Metern gelangt ihr zur Schafherde. Aus wievielen Mitgliedern besteht die Schafherde ?
+
+Das Final könnt ihr nun unter
+
+N 52° 2A.(D+F)CE / E 009° 3(B+1).(F+1)E(G-1) finden.
+
+Kontrolle: Die Quersumme von ABCDEFGH beträgt 40.
+
+Die, die sich die Seilfähre nicht zutrauen (oder sie gerade nicht da ist), berechnen F. folgendermaßen:
+
+F=H+A-B-C
+
+Über Fotos würde ich mich freuen !
+
+Viel Spaß !
+
+P.S. An warmen Tagen Badesachen und Handtuch mitnehmen.
+ +
+ +

+ + +

+

+ + Additional Hints + (Encrypt)

+
+ Das Final ist unter Steinen
+
+ +
+
+
+ +
+ + +
+ + + + + + + +
+ + + +

+ + Found ItYou logged this as Found on 19/08/2010.

+ +
+ +

+ Watching 2 user(s) watching this cache.

+ +
+ + +
+ +

+ +

+
+ +

+ + +
+ +

+ + Info + Attributes

+ + +
+ + +
+ +
+ +

+ +

+

+ Advertising with Us

+ +
+ +
+ + + + +
+
+ + + + +
+ +

+ Inventory + Inventory +

+ + + +
+ + +
+ +

+  Bookmark Lists

+
+ + + + +

+ View all bookmark lists... +

+ +
+ + +
+ + + + +
+ +

+  My Bookmark Lists

+
+ + + + +

+ +

+ +
+ + +
+ + + + +
+ + +
+ +

+ Additional Waypoints  +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +   + +   + + Prefix + + Lookup + + Name + + Coordinate + +   +
+ + + Hide Coordinates + + Final Location + + + FN + + FINAL + + GC2CJPF Final (Final Location) + + ???  + + +   +   + + +
+   + + Note: + + +
+ + + Visible + + Parking Area + + + PK + + PARKNG + + GC2CJPF Parking (Parking Area) + + N 52° 25.384 E 009° 39.023  + + +   +   + + +
+   + + Note: + + Kein "offizieller" Parkplatz, Parken trotzdem möglich. +
+ + + Visible + + Question to Answer + + + ST + + START + + GC2CJPF Start (Question to Answer) + + N 52° 25.504 E 009° 39.852  + + +   +   + + +
+   + + Note: + + +
+ + + Visible + + Reference Point + + + WO + + SCENIC + + Aussichtspunkt (Reference Point) + + N 52° 25.488 E 009° 39.432  + + +   +   + + +
+   + + Note: + + Ehemalige Finallocation wo es gebrannt hat. Gleichzeitig netter Aussichtspunkt. +
+ +

+ + | + Show Hidden Waypoints + Hide Hidden Waypoints +

+ + + +

+ +
+ +
+
+ +
+
+ To print the map in Firefox and Opera, enable background images in the print dialog. + + Close + +
+
+ +
+ +

+ Find... +
+ +

+ +

+ For online maps... +

+ + + + + +

+ +

+ +
+

+ 83 Logged Visits

+ +

Found it 64     Didn't find it 3     Write note 6     Temporarily Disable Listing 2     Enable Listing 2     Publish Listing 1     Needs Maintenance 2     Owner Maintenance 3     

+

+ View Logbook | View the Image Gallery of 14 images +

+

+ **Warning! Spoilers may be included in the descriptions or links. +

+
+ +
+ + + + + + + + +
+ + +
+
+

+ + Current Time:
Last Updated: on 01/29/2012 10:57:05 (UTC-08:00) Pacific Time (US & Canada) (18:57 GMT)
Rendered From:Unknown
Coordinates are in the WGS84 datum +
+

+ + +
+ + + + + + + + + + +
+ + + + +
+ + +
+ + + + + + + + +
+ + + + + + + + + + + + +
+ + + +
+ + + + + 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 { 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 { 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); } /** -- cgit v1.1