aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/cgeo/geocaching/CgeoApplicationTest.java10
-rw-r--r--tests/src/cgeo/geocaching/DataStoreTest.java4
-rw-r--r--tests/src/cgeo/geocaching/DestinationTest.java2
-rw-r--r--tests/src/cgeo/geocaching/GeocacheTest.java4
-rw-r--r--tests/src/cgeo/geocaching/SettingsTest.java4
-rw-r--r--tests/src/cgeo/geocaching/StaticMapsProviderTest.java2
-rw-r--r--tests/src/cgeo/geocaching/WaypointTest.java2
-rw-r--r--tests/src/cgeo/geocaching/activity/AbstractEspressoTest.java30
-rw-r--r--tests/src/cgeo/geocaching/activity/logtrackable/AbstractLogTrackableActivityTest.java31
-rw-r--r--tests/src/cgeo/geocaching/activity/logtrackable/LogTrackableActivityTest.java26
-rw-r--r--tests/src/cgeo/geocaching/activity/waypoint/AbstractAddWaypointActivityTest.java12
-rw-r--r--tests/src/cgeo/geocaching/activity/waypoint/AbstractEditWaypointActivityTest.java28
-rw-r--r--tests/src/cgeo/geocaching/activity/waypoint/AbstractWaypointActivityTest.java52
-rw-r--r--tests/src/cgeo/geocaching/activity/waypoint/AddWaypointActivityTest.java62
-rw-r--r--tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMultiTest.java34
-rw-r--r--tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMysteryTest.java32
-rw-r--r--tests/src/cgeo/geocaching/activity/waypoint/EditWaypointActivityTest.java29
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java4
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java4
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCParserTest.java2
-rw-r--r--tests/src/cgeo/geocaching/export/ExportTest.java2
-rw-r--r--tests/src/cgeo/geocaching/export/GpxSerializerTest.java2
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java41
-rw-r--r--tests/src/cgeo/geocaching/files/LocParserTest.java2
-rw-r--r--tests/src/cgeo/geocaching/gcvote/GCVoteTest.java47
-rw-r--r--tests/src/cgeo/geocaching/location/DistanceParserTest.java (renamed from tests/src/cgeo/geocaching/geopoint/DistanceParserTest.java)4
-rw-r--r--tests/src/cgeo/geocaching/location/GeoPointFormatterTest.java (renamed from tests/src/cgeo/geocaching/geopoint/GeoPointFormatterTest.java)4
-rw-r--r--tests/src/cgeo/geocaching/location/GeoPointParserTest.java (renamed from tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java)4
-rw-r--r--tests/src/cgeo/geocaching/location/GeopointTest.java (renamed from tests/src/cgeo/geocaching/geopoint/GeopointTest.java)4
-rw-r--r--tests/src/cgeo/geocaching/location/UnitsTest.java (renamed from tests/src/cgeo/geocaching/geopoint/UnitsTest.java)9
-rw-r--r--tests/src/cgeo/geocaching/location/ViewportTest.java (renamed from tests/src/cgeo/geocaching/geopoint/ViewportTest.java)4
-rw-r--r--tests/src/cgeo/geocaching/sensors/SensorsTest.java3
-rw-r--r--tests/src/cgeo/geocaching/settings/TestSettings.java2
-rw-r--r--tests/src/cgeo/geocaching/sorting/DistanceComparatorTest.java2
-rw-r--r--tests/src/cgeo/geocaching/speech/TextFactoryTest.java4
-rw-r--r--tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java4
-rw-r--r--tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java2
-rw-r--r--tests/src/cgeo/geocaching/test/mock/GC2CJPF.java4
-rw-r--r--tests/src/cgeo/geocaching/test/mock/GC2JVEH.java2
-rw-r--r--tests/src/cgeo/geocaching/test/mock/GC3XX5J.java2
-rw-r--r--tests/src/cgeo/geocaching/test/mock/MockedCache.java2
-rw-r--r--tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java5
-rw-r--r--tests/src/cgeo/geocaching/utils/TextUtilsTest.java7
-rw-r--r--tests/src/cgeo/junit/CgeoTestRunner.java120
44 files changed, 604 insertions, 52 deletions
diff --git a/tests/src/cgeo/geocaching/CgeoApplicationTest.java b/tests/src/cgeo/geocaching/CgeoApplicationTest.java
index de3f4ba..2b04a48 100644
--- a/tests/src/cgeo/geocaching/CgeoApplicationTest.java
+++ b/tests/src/cgeo/geocaching/CgeoApplicationTest.java
@@ -13,10 +13,10 @@ import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.enumerations.StatusCode;
-import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.list.StoredList;
import cgeo.geocaching.loaders.RecaptchaReceiver;
+import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.location.Viewport;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.TestSettings;
import cgeo.geocaching.test.RegExPerformanceTest;
@@ -165,7 +165,7 @@ public class CgeoApplicationTest extends CGeoTestCase {
deleteCacheFromDBAndLogout(cache.getGeocode());
- SearchResult search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null);
+ SearchResult search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST.id, true, null);
assertThat(search).isNotNull();
assertThat(search.getGeocodes()).hasSize(1);
assertThat(search.getGeocodes().contains(cache.getGeocode())).isTrue();
@@ -180,7 +180,7 @@ public class CgeoApplicationTest extends CGeoTestCase {
deleteCacheFromDBAndLogout(cache.getGeocode());
- search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null);
+ search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST.id, true, null);
assertThat(search).isNotNull();
assertThat(search.getGeocodes()).isEmpty();
}
@@ -201,7 +201,7 @@ public class CgeoApplicationTest extends CGeoTestCase {
deleteCacheFromDBAndLogout(cache.getGeocode());
- final SearchResult search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST_ID, true, null);
+ final SearchResult search = Geocache.searchByGeocode(cache.getGeocode(), null, StoredList.TEMPORARY_LIST.id, true, null);
assertThat(search).isNotNull();
assertThat(search.getGeocodes()).isEmpty();
}
diff --git a/tests/src/cgeo/geocaching/DataStoreTest.java b/tests/src/cgeo/geocaching/DataStoreTest.java
index 3579cc5..03713ac 100644
--- a/tests/src/cgeo/geocaching/DataStoreTest.java
+++ b/tests/src/cgeo/geocaching/DataStoreTest.java
@@ -8,9 +8,9 @@ import cgeo.geocaching.connector.gc.Tile;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
-import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.list.StoredList;
+import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.location.Viewport;
import org.apache.commons.lang3.StringUtils;
diff --git a/tests/src/cgeo/geocaching/DestinationTest.java b/tests/src/cgeo/geocaching/DestinationTest.java
index 00249c4..9883a32 100644
--- a/tests/src/cgeo/geocaching/DestinationTest.java
+++ b/tests/src/cgeo/geocaching/DestinationTest.java
@@ -2,7 +2,7 @@ package cgeo.geocaching;
import static org.assertj.core.api.Assertions.assertThat;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import android.test.AndroidTestCase;
diff --git a/tests/src/cgeo/geocaching/GeocacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java
index b3ec6be..954b492 100644
--- a/tests/src/cgeo/geocaching/GeocacheTest.java
+++ b/tests/src/cgeo/geocaching/GeocacheTest.java
@@ -5,8 +5,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import cgeo.CGeoTestCase;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LogType;
-import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.list.StoredList;
+import cgeo.geocaching.location.Geopoint;
import org.apache.commons.lang3.StringUtils;
@@ -86,7 +86,7 @@ public class GeocacheTest extends CGeoTestCase {
assertThat(waypoint.getCoords()).isEqualTo(new Geopoint("N51 13.888 E007 03.444"));
// assertThat(waypoint.getNote()).isEqualTo("Test");
assertThat(waypoint.getName()).isEqualTo(CgeoApplication.getInstance().getString(R.string.cache_personal_note) + " 1");
- cache.store(StoredList.TEMPORARY_LIST_ID, null);
+ cache.store(StoredList.TEMPORARY_LIST.id, null);
}
removeCacheCompletely(geocode);
} finally {
diff --git a/tests/src/cgeo/geocaching/SettingsTest.java b/tests/src/cgeo/geocaching/SettingsTest.java
index 21e0557..c210ab7 100644
--- a/tests/src/cgeo/geocaching/SettingsTest.java
+++ b/tests/src/cgeo/geocaching/SettingsTest.java
@@ -20,10 +20,8 @@ public class SettingsTest extends ActivityInstrumentationTestCase2<MainActivity>
* this should work fine without an exception (once there was an exception because of the empty map file string)
*/
public static void testSettingsException() {
- final String mapFile = Settings.getMapFile();
// We just want to ensure that it does not throw any exception but we do not know anything about the result
- MapsforgeMapProvider.isValidMapFile(mapFile);
- assertThat(true).isTrue();
+ MapsforgeMapProvider.isValidMapFile(Settings.getMapFile());
}
public static void testSettings() {
diff --git a/tests/src/cgeo/geocaching/StaticMapsProviderTest.java b/tests/src/cgeo/geocaching/StaticMapsProviderTest.java
index 42ad2c5..b107912 100644
--- a/tests/src/cgeo/geocaching/StaticMapsProviderTest.java
+++ b/tests/src/cgeo/geocaching/StaticMapsProviderTest.java
@@ -4,7 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.files.LocalStorage;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.TestSettings;
import cgeo.geocaching.utils.RxUtils;
diff --git a/tests/src/cgeo/geocaching/WaypointTest.java b/tests/src/cgeo/geocaching/WaypointTest.java
index a3dabbf..9e14146 100644
--- a/tests/src/cgeo/geocaching/WaypointTest.java
+++ b/tests/src/cgeo/geocaching/WaypointTest.java
@@ -3,7 +3,7 @@ package cgeo.geocaching;
import static org.assertj.core.api.Assertions.assertThat;
import cgeo.geocaching.enumerations.WaypointType;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import android.test.AndroidTestCase;
diff --git a/tests/src/cgeo/geocaching/activity/AbstractEspressoTest.java b/tests/src/cgeo/geocaching/activity/AbstractEspressoTest.java
new file mode 100644
index 0000000..0647ec8
--- /dev/null
+++ b/tests/src/cgeo/geocaching/activity/AbstractEspressoTest.java
@@ -0,0 +1,30 @@
+package cgeo.geocaching.activity;
+
+import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;
+import static com.google.android.apps.common.testing.ui.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
+import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
+import static org.hamcrest.Matchers.hasToString;
+import static org.hamcrest.Matchers.startsWith;
+
+import android.app.Activity;
+import android.test.ActivityInstrumentationTestCase2;
+
+public abstract class AbstractEspressoTest<T extends Activity> extends ActivityInstrumentationTestCase2<T> {
+
+ public AbstractEspressoTest(Class<T> activityClass) {
+ super(activityClass);
+ }
+
+ protected final void clickActionBarItem(int labelResourceId) {
+ onData(hasToString(startsWith(getString(labelResourceId)))).perform(click());
+ }
+
+ protected final void openActionBar() {
+ openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
+ }
+
+ protected final String getString(int resId) {
+ return getActivity().getString(resId);
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/activity/logtrackable/AbstractLogTrackableActivityTest.java b/tests/src/cgeo/geocaching/activity/logtrackable/AbstractLogTrackableActivityTest.java
new file mode 100644
index 0000000..d93f1ad
--- /dev/null
+++ b/tests/src/cgeo/geocaching/activity/logtrackable/AbstractLogTrackableActivityTest.java
@@ -0,0 +1,31 @@
+package cgeo.geocaching.activity.logtrackable;
+
+import cgeo.geocaching.DataStore;
+import cgeo.geocaching.LogTrackableActivity;
+import cgeo.geocaching.Trackable;
+import cgeo.geocaching.activity.AbstractEspressoTest;
+
+public abstract class AbstractLogTrackableActivityTest extends AbstractEspressoTest<LogTrackableActivity> {
+
+ private static Trackable trackable;
+
+ public AbstractLogTrackableActivityTest() {
+ super(LogTrackableActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ createTrackable();
+ setActivityIntent(LogTrackableActivity.getIntent(getInstrumentation().getContext(), trackable));
+ getActivity();
+ }
+
+ protected static void createTrackable() {
+ trackable = new Trackable();
+ trackable.setName("Test trackable");
+ trackable.setGeocode("TB4D09K");
+ DataStore.saveTrackable(trackable);
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/activity/logtrackable/LogTrackableActivityTest.java b/tests/src/cgeo/geocaching/activity/logtrackable/LogTrackableActivityTest.java
new file mode 100644
index 0000000..cb2a209
--- /dev/null
+++ b/tests/src/cgeo/geocaching/activity/logtrackable/LogTrackableActivityTest.java
@@ -0,0 +1,26 @@
+package cgeo.geocaching.activity.logtrackable;
+
+import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
+import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.doesNotExist;
+import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
+
+import cgeo.geocaching.R;
+
+public class LogTrackableActivityTest extends AbstractLogTrackableActivityTest {
+
+ public void testInsertNameExists() throws Exception {
+ openActionBar();
+ clickActionBarItem(R.string.log_add);
+
+ onView(withText(getString(R.string.init_signature_template_name))).check(matches(isDisplayed()));
+ }
+
+ public void testInsertNumberNotExists() throws Exception {
+ openActionBar();
+ clickActionBarItem(R.string.log_add);
+
+ onView(withText(getString(R.string.init_signature_template_number))).check(doesNotExist());
+ }
+}
diff --git a/tests/src/cgeo/geocaching/activity/waypoint/AbstractAddWaypointActivityTest.java b/tests/src/cgeo/geocaching/activity/waypoint/AbstractAddWaypointActivityTest.java
new file mode 100644
index 0000000..7be6150
--- /dev/null
+++ b/tests/src/cgeo/geocaching/activity/waypoint/AbstractAddWaypointActivityTest.java
@@ -0,0 +1,12 @@
+package cgeo.geocaching.activity.waypoint;
+
+import cgeo.geocaching.EditWaypointActivity_;
+
+public abstract class AbstractAddWaypointActivityTest extends AbstractWaypointActivityTest {
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ setActivityIntent(new EditWaypointActivity_.IntentBuilder_(getInstrumentation().getContext()).geocode(getCache().getGeocode()).get());
+ getActivity();
+ }
+}
diff --git a/tests/src/cgeo/geocaching/activity/waypoint/AbstractEditWaypointActivityTest.java b/tests/src/cgeo/geocaching/activity/waypoint/AbstractEditWaypointActivityTest.java
new file mode 100644
index 0000000..bf8224a
--- /dev/null
+++ b/tests/src/cgeo/geocaching/activity/waypoint/AbstractEditWaypointActivityTest.java
@@ -0,0 +1,28 @@
+package cgeo.geocaching.activity.waypoint;
+
+import cgeo.geocaching.EditWaypointActivity_;
+import cgeo.geocaching.Waypoint;
+import cgeo.geocaching.enumerations.WaypointType;
+
+public abstract class AbstractEditWaypointActivityTest extends AbstractWaypointActivityTest {
+ private Waypoint waypoint;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ createWaypoint();
+ getCache().addOrChangeWaypoint(waypoint, true);
+ final int waypointId = getCache().getWaypoints().get(0).getId();
+ setActivityIntent(new EditWaypointActivity_.IntentBuilder_(getInstrumentation().getContext()).geocode(getCache().getGeocode()).waypointId(waypointId).get());
+ getActivity();
+ }
+
+ private void createWaypoint() {
+ waypoint = new Waypoint("Test waypoint", WaypointType.PUZZLE, true);
+ waypoint.setNote("Test note");
+ }
+
+ protected final Waypoint getWaypoint() {
+ return waypoint;
+ }
+}
diff --git a/tests/src/cgeo/geocaching/activity/waypoint/AbstractWaypointActivityTest.java b/tests/src/cgeo/geocaching/activity/waypoint/AbstractWaypointActivityTest.java
new file mode 100644
index 0000000..36c4302
--- /dev/null
+++ b/tests/src/cgeo/geocaching/activity/waypoint/AbstractWaypointActivityTest.java
@@ -0,0 +1,52 @@
+package cgeo.geocaching.activity.waypoint;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.DataStore;
+import cgeo.geocaching.EditWaypointActivity_;
+import cgeo.geocaching.Geocache;
+import cgeo.geocaching.activity.AbstractEspressoTest;
+import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.enumerations.LoadFlags;
+import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
+
+import java.util.Collections;
+
+public abstract class AbstractWaypointActivityTest extends AbstractEspressoTest<EditWaypointActivity_> {
+
+ private Geocache cache;
+
+ public AbstractWaypointActivityTest() {
+ super(EditWaypointActivity_.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ cache = createTestCache();
+ DataStore.saveCache(cache, Collections.singleton(SaveFlag.CACHE));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ removeTestCache();
+ super.tearDown();
+ }
+
+ protected final Geocache getCache() {
+ return cache;
+ }
+
+ private void removeTestCache() {
+ DataStore.removeCache(cache.getGeocode(), LoadFlags.REMOVE_ALL);
+ assertThat(DataStore.loadCache(cache.getGeocode(), LoadFlags.LOAD_CACHE_OR_DB)).isNull();
+ }
+
+ @SuppressWarnings("static-method")
+ protected Geocache createTestCache() {
+ Geocache testCache = new Geocache();
+ testCache.setGeocode("TEST");
+ testCache.setType(CacheType.TRADITIONAL);
+ return testCache;
+ }
+}
diff --git a/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointActivityTest.java b/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointActivityTest.java
new file mode 100644
index 0000000..853054a
--- /dev/null
+++ b/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointActivityTest.java
@@ -0,0 +1,62 @@
+package cgeo.geocaching.activity.waypoint;
+
+import cgeo.geocaching.R;
+import cgeo.geocaching.enumerations.WaypointType;
+
+import com.google.android.apps.common.testing.ui.espresso.action.ViewActions;
+
+import static com.google.android.apps.common.testing.ui.espresso.Espresso.onData;
+import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
+
+import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
+
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isClickable;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isNotChecked;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withChild;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
+
+import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
+
+import static org.hamcrest.Matchers.hasToString;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
+
+public class AddWaypointActivityTest extends AbstractAddWaypointActivityTest {
+
+ public static void testAddWayPointHasTypeSelection() {
+ onView(withId(R.id.type)).check(matches(isDisplayed()));
+ }
+
+ public static void testDefaultWaypointTypeForTraditional() {
+ onView(withId(R.id.type)).check(matches(withChild(withText(WaypointType.WAYPOINT.getL10n()))));
+ onView(withId(R.id.name)).check(matches(withText(WaypointType.WAYPOINT.getL10n() + " 1")));
+ }
+
+ public static void testFieldsAreEmpty() {
+ onView(withId(R.id.note)).check(matches(withText("")));
+ onView(withId(R.id.bearing)).check(matches(withText("")));
+ onView(withId(R.id.distance)).check(matches(withText("")));
+ }
+
+ public static void testNewWaypointNotVisited() {
+ onView(withId(R.id.wpt_visited_checkbox)).check(matches(isNotChecked()));
+ }
+
+ public static void testSwitchingWaypointTypeChangesWaypointName() {
+ WaypointType waypointType = WaypointType.FINAL;
+
+ // verify we don't have a final type yet
+ onView(withId(R.id.name)).check(matches(not(withText(waypointType.getL10n()))));
+
+ // open type selector
+ onView(withId(R.id.type)).perform(ViewActions.click());
+
+ // select final type
+ onData(hasToString(startsWith(waypointType.getL10n()))).inAdapterView(isClickable()).perform(click());
+
+ // verify changed name
+ onView(withId(R.id.name)).check(matches(withText(waypointType.getL10n())));
+ }
+}
diff --git a/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMultiTest.java b/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMultiTest.java
new file mode 100644
index 0000000..c66c8de
--- /dev/null
+++ b/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMultiTest.java
@@ -0,0 +1,34 @@
+package cgeo.geocaching.activity.waypoint;
+
+import cgeo.geocaching.Geocache;
+import cgeo.geocaching.R;
+import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.enumerations.WaypointType;
+
+import com.google.android.apps.common.testing.ui.espresso.ViewInteraction;
+
+import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
+
+import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
+
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withChild;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
+
+public class AddWaypointMultiTest extends AbstractAddWaypointActivityTest {
+
+ @Override
+ protected Geocache createTestCache() {
+ final Geocache cache = super.createTestCache();
+ cache.setType(CacheType.MULTI);
+ return cache;
+ }
+
+ public static void testMysteryDefaultWaypointFinal() {
+ final ViewInteraction waypointTypeSelector = onView(withId(R.id.type));
+ waypointTypeSelector.check(matches(isDisplayed()));
+ waypointTypeSelector.check(matches(withChild(withText(WaypointType.STAGE.getL10n()))));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMysteryTest.java b/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMysteryTest.java
new file mode 100644
index 0000000..810aa25
--- /dev/null
+++ b/tests/src/cgeo/geocaching/activity/waypoint/AddWaypointMysteryTest.java
@@ -0,0 +1,32 @@
+package cgeo.geocaching.activity.waypoint;
+
+import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
+import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withChild;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
+
+import cgeo.geocaching.Geocache;
+import cgeo.geocaching.R;
+import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.enumerations.WaypointType;
+
+import com.google.android.apps.common.testing.ui.espresso.ViewInteraction;
+
+public class AddWaypointMysteryTest extends AbstractAddWaypointActivityTest {
+
+ @Override
+ protected Geocache createTestCache() {
+ final Geocache cache = super.createTestCache();
+ cache.setType(CacheType.MYSTERY);
+ return cache;
+ }
+
+ public static void testMysteryDefaultWaypointFinal() {
+ final ViewInteraction waypointTypeSelector = onView(withId(R.id.type));
+ waypointTypeSelector.check(matches(isDisplayed()));
+ waypointTypeSelector.check(matches(withChild(withText(WaypointType.FINAL.getL10n()))));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/activity/waypoint/EditWaypointActivityTest.java b/tests/src/cgeo/geocaching/activity/waypoint/EditWaypointActivityTest.java
new file mode 100644
index 0000000..d419555
--- /dev/null
+++ b/tests/src/cgeo/geocaching/activity/waypoint/EditWaypointActivityTest.java
@@ -0,0 +1,29 @@
+package cgeo.geocaching.activity.waypoint;
+
+import cgeo.geocaching.R;
+
+import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
+
+import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
+
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withChild;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
+import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class EditWaypointActivityTest extends AbstractEditWaypointActivityTest {
+
+ public void testFieldsAreNotEmpty() {
+ String name = getWaypoint().getName();
+ assertThat(name).isNotEmpty();
+ onView(withId(R.id.name)).check(matches(withText(name)));
+
+ final String note = getWaypoint().getNote();
+ assertThat(note).isNotEmpty();
+ onView(withId(R.id.note)).check(matches(withText(note)));
+
+ onView(withId(R.id.type)).check(matches(withChild(withText(getWaypoint().getWaypointType().getL10n()))));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java b/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java
index 63924ab..f7dbe72 100644
--- a/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/AutoZoomTest.java
@@ -2,8 +2,8 @@ package cgeo.geocaching.connector.gc;
import static org.assertj.core.api.Assertions.assertThat;
-import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.Viewport;
+import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.location.Viewport;
import java.util.Set;
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
index 811c0e4..24f65fd 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCConnectorTest.java
@@ -6,8 +6,8 @@ import cgeo.geocaching.SearchResult;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.trackable.TravelBugConnector;
import cgeo.geocaching.enumerations.CacheType;
-import cgeo.geocaching.geopoint.Geopoint;
-import cgeo.geocaching.geopoint.Viewport;
+import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.location.Viewport;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.TestSettings;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
index be96cf3..bfd5cb1 100644
--- a/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
+++ b/tests/src/cgeo/geocaching/connector/gc/GCParserTest.java
@@ -11,7 +11,7 @@ import cgeo.geocaching.Waypoint;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.enumerations.WaypointType;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
diff --git a/tests/src/cgeo/geocaching/export/ExportTest.java b/tests/src/cgeo/geocaching/export/ExportTest.java
index 848a1f7..7dc4ed9 100644
--- a/tests/src/cgeo/geocaching/export/ExportTest.java
+++ b/tests/src/cgeo/geocaching/export/ExportTest.java
@@ -8,7 +8,7 @@ import cgeo.geocaching.Geocache;
import cgeo.geocaching.LogEntry;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LogType;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.utils.FileUtils;
import java.io.File;
diff --git a/tests/src/cgeo/geocaching/export/GpxSerializerTest.java b/tests/src/cgeo/geocaching/export/GpxSerializerTest.java
index 809c121..c43ad38 100644
--- a/tests/src/cgeo/geocaching/export/GpxSerializerTest.java
+++ b/tests/src/cgeo/geocaching/export/GpxSerializerTest.java
@@ -67,7 +67,7 @@ public class GpxSerializerTest extends AbstractResourceInstrumentationTestCase {
assertThat(gpxFirst.length() > 0).isTrue();
- final GPX10Parser parser = new GPX10Parser(StoredList.TEMPORARY_LIST_ID);
+ final GPX10Parser parser = new GPX10Parser(StoredList.TEMPORARY_LIST.id);
final InputStream stream = new ByteArrayInputStream(gpxFirst.getBytes(CharEncoding.UTF_8));
Collection<Geocache> caches = parser.parse(stream, null);
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index 6171bab..4bbfbff 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -11,7 +11,7 @@ import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LoadFlags.LoadFlag;
import cgeo.geocaching.enumerations.WaypointType;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
import cgeo.geocaching.utils.SynchronizedDateFormat;
@@ -375,14 +375,41 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
public void testGPXMysteryType() throws IOException, ParserException {
final List<Geocache> caches = readGPX10(R.raw.tc2012);
- Geocache mystery = null;
- for (Geocache geocache : caches) {
- if (geocache.getName().equals("U017")) {
- mystery = geocache;
- }
- }
+ Geocache mystery = getCache(caches, "U017");
assertThat(mystery).isNotNull();
assert (mystery != null);
assertThat(mystery.getType()).isEqualTo(CacheType.MYSTERY);
}
+
+ private static Geocache getCache(final List<Geocache> caches, String geocode) {
+ for (Geocache geocache : caches) {
+ if (geocache.getName().equals(geocode)) {
+ return geocache;
+ }
+ }
+ return null;
+ }
+
+ public void testLabCaches() throws IOException, ParserException {
+ final List<Geocache> caches = readGPX10(R.raw.giga_lab_caches);
+ assertThat(caches).hasSize(10);
+ Geocache lab = getCache(caches, "01_Munich Olympic Walk Of Stars_Updated-Project MUNICH2014 - Mia san Giga! Olympiapark");
+ assertThat(lab).isNotNull();
+
+ // parse labs as virtual for the time being
+ assertThat(lab.getType()).isEqualTo(CacheType.VIRTUAL);
+
+ // no difficulty and terrain rating
+ assertThat(lab.getTerrain()).isEqualTo(0);
+ assertThat(lab.getDifficulty()).isEqualTo(0);
+
+ // geocodes are just big hashes
+ assertThat(lab.getGeocode()).isEqualTo("01_Munich Olympic Walk Of Stars_Updated-Project MUNICH2014 - Mia san Giga! Olympiapark".toUpperCase(Locale.US));
+
+ // other normal cache properties
+ assertThat(lab.getName()).isEqualTo("01_Munich Olympic Walk Of Stars_Updated-Project MUNICH2014 - Mia san Giga! Olympiapark");
+ assertThat(lab.getShortDescription()).isEqualTo("01_Munich Olympic Walk Of Stars_Updated (Giga! Olympia Park)-Project MUNICH2014 - Mia san Giga! Olympiapark");
+ assertThat(lab.getDescription()).startsWith("DEU:");
+ }
+
}
diff --git a/tests/src/cgeo/geocaching/files/LocParserTest.java b/tests/src/cgeo/geocaching/files/LocParserTest.java
index d87b593..7d5ccee 100644
--- a/tests/src/cgeo/geocaching/files/LocParserTest.java
+++ b/tests/src/cgeo/geocaching/files/LocParserTest.java
@@ -5,7 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
diff --git a/tests/src/cgeo/geocaching/gcvote/GCVoteTest.java b/tests/src/cgeo/geocaching/gcvote/GCVoteTest.java
new file mode 100644
index 0000000..c1b5e75
--- /dev/null
+++ b/tests/src/cgeo/geocaching/gcvote/GCVoteTest.java
@@ -0,0 +1,47 @@
+package cgeo.geocaching.gcvote;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
+import cgeo.geocaching.test.R;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+public class GCVoteTest extends AbstractResourceInstrumentationTestCase {
+
+ private InputStream responseStream;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ responseStream = new ByteArrayInputStream(getFileContent(R.raw.gcvote).getBytes());
+ responseStream.mark(getFileContent(R.raw.gcvote).getBytes().length + 1);
+ }
+
+ private InputStream responseStream() {
+ try {
+ responseStream.reset();
+ } catch (final IOException ignored) {
+ // Cannot happen
+ }
+ return responseStream;
+ }
+
+ public void testGetRatingsByGeocode() {
+ final Map<String, GCVoteRating> ratings = GCVote.getRatingsFromXMLResponse(responseStream(), false);
+ assertThat(ratings).hasSize(10);
+ assertThat(ratings).containsKey("GCKF13");
+ assertThat(ratings.get("GC1WEVZ")).isEqualToComparingFieldByField(new GCVoteRating(3.75f, 2, 0));
+ }
+
+ public void testGetRatingsByGuid() {
+ final Map<String, GCVoteRating> ratings = GCVote.getRatingsFromXMLResponse(responseStream(), true);
+ assertThat(ratings).hasSize(10);
+ assertThat(ratings).containsKey("a02894bb-4a08-4c09-a73c-25939894ba15");
+ assertThat(ratings.get("5520c33b-3941-45ca-9056-ea655dbaadf7")).isEqualToComparingFieldByField(new GCVoteRating(3.75f, 2, 0));
+ }
+
+}
diff --git a/tests/src/cgeo/geocaching/geopoint/DistanceParserTest.java b/tests/src/cgeo/geocaching/location/DistanceParserTest.java
index 621d268..4d9e5a5 100644
--- a/tests/src/cgeo/geocaching/geopoint/DistanceParserTest.java
+++ b/tests/src/cgeo/geocaching/location/DistanceParserTest.java
@@ -1,4 +1,6 @@
-package cgeo.geocaching.geopoint;
+package cgeo.geocaching.location;
+
+import cgeo.geocaching.location.DistanceParser;
import android.test.AndroidTestCase;
diff --git a/tests/src/cgeo/geocaching/geopoint/GeoPointFormatterTest.java b/tests/src/cgeo/geocaching/location/GeoPointFormatterTest.java
index 2816664..9ae54fa 100644
--- a/tests/src/cgeo/geocaching/geopoint/GeoPointFormatterTest.java
+++ b/tests/src/cgeo/geocaching/location/GeoPointFormatterTest.java
@@ -1,7 +1,9 @@
-package cgeo.geocaching.geopoint;
+package cgeo.geocaching.location;
import static org.assertj.core.api.Assertions.assertThat;
+import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.location.GeopointFormatter;
import cgeo.geocaching.utils.Formatter;
import android.test.AndroidTestCase;
diff --git a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java b/tests/src/cgeo/geocaching/location/GeoPointParserTest.java
index f8a3bb2..e9e002d 100644
--- a/tests/src/cgeo/geocaching/geopoint/GeoPointParserTest.java
+++ b/tests/src/cgeo/geocaching/location/GeoPointParserTest.java
@@ -1,7 +1,9 @@
-package cgeo.geocaching.geopoint;
+package cgeo.geocaching.location;
import static org.assertj.core.api.Assertions.assertThat;
+import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.location.GeopointParser;
import cgeo.geocaching.utils.Formatter;
import android.test.AndroidTestCase;
diff --git a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java b/tests/src/cgeo/geocaching/location/GeopointTest.java
index 5db877a..6f5dd78 100644
--- a/tests/src/cgeo/geocaching/geopoint/GeopointTest.java
+++ b/tests/src/cgeo/geocaching/location/GeopointTest.java
@@ -1,8 +1,10 @@
-package cgeo.geocaching.geopoint;
+package cgeo.geocaching.location;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.offset;
+import cgeo.geocaching.location.Geopoint;
+
import android.os.Build;
import android.os.Bundle;
import android.test.AndroidTestCase;
diff --git a/tests/src/cgeo/geocaching/geopoint/UnitsTest.java b/tests/src/cgeo/geocaching/location/UnitsTest.java
index f208984..f03f6f0 100644
--- a/tests/src/cgeo/geocaching/geopoint/UnitsTest.java
+++ b/tests/src/cgeo/geocaching/location/UnitsTest.java
@@ -1,8 +1,9 @@
-package cgeo.geocaching.geopoint;
+package cgeo.geocaching.location;
import static org.assertj.core.api.Assertions.assertThat;
import cgeo.CGeoTestCase;
+import cgeo.geocaching.location.Units;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.TestSettings;
@@ -14,7 +15,7 @@ public class UnitsTest extends CGeoTestCase {
final String actual = Units.getDistanceFromKilometers(distance);
if (!StringUtils.equals(expected, actual.replace(',', '.'))) { // make 1.2 the same as 1,2
fail("getHumanDistance(" + distance +
- ") [metric: " + (!Settings.isUseImperialUnits() ? "yes" : "no") +
+ ") [metric: " + (!Settings.useImperialUnits() ? "yes" : "no") +
"] fails to match " + expected + ": " + actual);
}
}
@@ -23,7 +24,7 @@ public class UnitsTest extends CGeoTestCase {
@SuppressWarnings("static-method")
public void testDistance() {
assertThat(Units.getDistanceFromKilometers(null)).isEqualTo("?");
- final boolean savedImperial = Settings.isUseImperialUnits();
+ final boolean savedImperial = Settings.useImperialUnits();
try {
TestSettings.setUseImperialUnits(false);
assertDistance("123 km", 122.782f);
@@ -46,7 +47,7 @@ public class UnitsTest extends CGeoTestCase {
@SuppressWarnings("static-method")
public void testSpeed() {
assertThat(Units.getDistanceFromKilometers(null)).isEqualTo("?");
- final boolean savedImperial = Settings.isUseImperialUnits();
+ final boolean savedImperial = Settings.useImperialUnits();
try {
TestSettings.setUseImperialUnits(false);
assertSpeed("123 km/h", 122.782f);
diff --git a/tests/src/cgeo/geocaching/geopoint/ViewportTest.java b/tests/src/cgeo/geocaching/location/ViewportTest.java
index ace0356..be15458 100644
--- a/tests/src/cgeo/geocaching/geopoint/ViewportTest.java
+++ b/tests/src/cgeo/geocaching/location/ViewportTest.java
@@ -1,8 +1,10 @@
-package cgeo.geocaching.geopoint;
+package cgeo.geocaching.location;
import static org.assertj.core.api.Assertions.assertThat;
import cgeo.geocaching.ICoordinates;
+import cgeo.geocaching.location.Geopoint;
+import cgeo.geocaching.location.Viewport;
import org.eclipse.jdt.annotation.NonNull;
diff --git a/tests/src/cgeo/geocaching/sensors/SensorsTest.java b/tests/src/cgeo/geocaching/sensors/SensorsTest.java
index c4f70aa..b54cd13 100644
--- a/tests/src/cgeo/geocaching/sensors/SensorsTest.java
+++ b/tests/src/cgeo/geocaching/sensors/SensorsTest.java
@@ -3,6 +3,7 @@ package cgeo.geocaching.sensors;
import static org.assertj.core.api.Assertions.assertThat;
import cgeo.geocaching.MainActivity;
+import cgeo.geocaching.utils.AngleUtils;
import android.test.ActivityInstrumentationTestCase2;
@@ -18,7 +19,7 @@ public class SensorsTest extends ActivityInstrumentationTestCase2<MainActivity>
}
public static void testGetDirectionNow() {
- final float angle = DirectionProvider.getDirectionNow(1.0f);
+ final float angle = AngleUtils.getDirectionNow(1.0f);
assertThat(angle == 1.0f || angle == 91.0f || angle == 181.0f || angle == 271.0f).isTrue();
}
diff --git a/tests/src/cgeo/geocaching/settings/TestSettings.java b/tests/src/cgeo/geocaching/settings/TestSettings.java
index 279f658..b82c120 100644
--- a/tests/src/cgeo/geocaching/settings/TestSettings.java
+++ b/tests/src/cgeo/geocaching/settings/TestSettings.java
@@ -37,7 +37,7 @@ public final class TestSettings extends Settings {
}
public static void setUseImperialUnits(final boolean imperial) {
- putBoolean(R.string.pref_units, imperial);
+ putBoolean(R.string.pref_units_imperial, imperial);
}
public static void setCacheTwitterMessage(final String template) {
diff --git a/tests/src/cgeo/geocaching/sorting/DistanceComparatorTest.java b/tests/src/cgeo/geocaching/sorting/DistanceComparatorTest.java
index 0cfee49..51e7dae 100644
--- a/tests/src/cgeo/geocaching/sorting/DistanceComparatorTest.java
+++ b/tests/src/cgeo/geocaching/sorting/DistanceComparatorTest.java
@@ -1,7 +1,7 @@
package cgeo.geocaching.sorting;
import cgeo.geocaching.Geocache;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import android.test.AndroidTestCase;
diff --git a/tests/src/cgeo/geocaching/speech/TextFactoryTest.java b/tests/src/cgeo/geocaching/speech/TextFactoryTest.java
index c53aec9..c01fbd0 100644
--- a/tests/src/cgeo/geocaching/speech/TextFactoryTest.java
+++ b/tests/src/cgeo/geocaching/speech/TextFactoryTest.java
@@ -3,7 +3,7 @@ package cgeo.geocaching.speech;
import static org.assertj.core.api.Assertions.assertThat;
import cgeo.geocaching.CgeoApplication;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.TestSettings;
@@ -35,7 +35,7 @@ public class TextFactoryTest extends AndroidTestCase {
final Configuration config = resources.getConfiguration();
defaultLocale1 = config.locale;
defaultLocale2 = Locale.getDefault();
- defaultMetric = !Settings.isUseImperialUnits();
+ defaultMetric = !Settings.useImperialUnits();
}
@Override
diff --git a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
index eaac181..2a22895 100644
--- a/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
+++ b/tests/src/cgeo/geocaching/test/AbstractResourceInstrumentationTestCase.java
@@ -75,7 +75,7 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument
protected void setUp() throws Exception {
super.setUp();
temporaryListId = DataStore.createList("Temporary unit testing");
- assertThat(temporaryListId != StoredList.TEMPORARY_LIST_ID).isTrue();
+ assertThat(temporaryListId != StoredList.TEMPORARY_LIST.id).isTrue();
assertThat(temporaryListId != StoredList.STANDARD_LIST_ID).isTrue();
}
@@ -95,7 +95,7 @@ public abstract class AbstractResourceInstrumentationTestCase extends Instrument
final protected Geocache loadCacheFromResource(int resourceId) throws IOException, ParserException {
final InputStream instream = getResourceStream(resourceId);
try {
- GPX10Parser parser = new GPX10Parser(StoredList.TEMPORARY_LIST_ID);
+ GPX10Parser parser = new GPX10Parser(StoredList.TEMPORARY_LIST.id);
Collection<Geocache> caches = parser.parse(instream, null);
assertThat(caches).isNotNull();
assertThat(caches.isEmpty()).isFalse();
diff --git a/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java b/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java
index ddd2310..34422ff 100644
--- a/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java
+++ b/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java
@@ -4,7 +4,7 @@ import cgeo.geocaching.connector.gc.GCLogin;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LogType;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import java.text.ParseException;
import java.util.Date;
diff --git a/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java b/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java
index 817f285..bf01f61 100644
--- a/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java
+++ b/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java
@@ -4,7 +4,7 @@ import cgeo.geocaching.connector.gc.GCLogin;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LogType;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.settings.Settings;
import java.text.ParseException;
@@ -66,7 +66,7 @@ public class GC2CJPF extends MockedCache {
@Override
public String getDescription() {
- return "<a href=\"http://www.kinderwald.de/\"><b>http://www.kinderwald.de/</b></a><br/><br/>Kleiner Multi über 7 Stationen";
+ return "Kleiner Multi über 7 Stationen";
}
@Override
diff --git a/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java b/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java
index be27a2e..cfccc3a 100644
--- a/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java
+++ b/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java
@@ -6,7 +6,7 @@ import cgeo.geocaching.connector.gc.GCLogin;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LogType;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import java.text.ParseException;
import java.util.ArrayList;
diff --git a/tests/src/cgeo/geocaching/test/mock/GC3XX5J.java b/tests/src/cgeo/geocaching/test/mock/GC3XX5J.java
index 65de80c..9f69e8e 100644
--- a/tests/src/cgeo/geocaching/test/mock/GC3XX5J.java
+++ b/tests/src/cgeo/geocaching/test/mock/GC3XX5J.java
@@ -4,7 +4,7 @@ import cgeo.geocaching.connector.gc.GCLogin;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LogType;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import java.text.ParseException;
import java.util.Date;
diff --git a/tests/src/cgeo/geocaching/test/mock/MockedCache.java b/tests/src/cgeo/geocaching/test/mock/MockedCache.java
index 0ef6488..6fb249d 100644
--- a/tests/src/cgeo/geocaching/test/mock/MockedCache.java
+++ b/tests/src/cgeo/geocaching/test/mock/MockedCache.java
@@ -6,7 +6,7 @@ import cgeo.geocaching.ICache;
import cgeo.geocaching.Image;
import cgeo.geocaching.Trackable;
import cgeo.geocaching.connector.gc.GCConstants;
-import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.location.Geopoint;
import cgeo.geocaching.utils.TextUtils;
import org.apache.commons.lang3.StringUtils;
diff --git a/tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java b/tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java
index 65e86b8..e75c2e6 100644
--- a/tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/HtmlUtilsTest.java
@@ -15,4 +15,9 @@ public class HtmlUtilsTest extends TestCase {
assertThat(HtmlUtils.extractText("<b>bold</b>")).isEqualTo("bold");
}
+ public static void testRemoveExtraParagraph() {
+ assertThat(HtmlUtils.removeExtraParagraph("<p></p>")).isEqualTo("");
+ assertThat(HtmlUtils.removeExtraParagraph("<p>Test</p>")).isEqualTo("Test");
+ assertThat(HtmlUtils.removeExtraParagraph("<p>1</p><p>2</p>")).isEqualTo("<p>1</p><p>2</p>");
+ }
}
diff --git a/tests/src/cgeo/geocaching/utils/TextUtilsTest.java b/tests/src/cgeo/geocaching/utils/TextUtilsTest.java
index e04025e..bc49c30 100644
--- a/tests/src/cgeo/geocaching/utils/TextUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/TextUtilsTest.java
@@ -26,4 +26,11 @@ public class TextUtilsTest extends AndroidTestCase {
assertThat(TextUtils.getMatch("some" + "\u001C" + "control" + (char) 0x1D + "characters removed", patternAll, "")).isEqualTo("some control characters removed");
assertThat(TextUtils.getMatch("newline\nalso\nremoved", patternAll, "")).isEqualTo("newline also removed");
}
+
+ public static void testGetMatch() {
+ final Pattern patternAll = Pattern.compile("foo(...)");
+ final String text = "abc-foobar-def-fooxyz-ghi-foobaz-jkl";
+ assertThat(TextUtils.getMatch(text, patternAll, false, 1, null, false)).isEqualTo("bar");
+ assertThat(TextUtils.getMatch(text, patternAll, false, 1, null, true)).isEqualTo("baz");
+ }
}
diff --git a/tests/src/cgeo/junit/CgeoTestRunner.java b/tests/src/cgeo/junit/CgeoTestRunner.java
new file mode 100644
index 0000000..7a6f15e
--- /dev/null
+++ b/tests/src/cgeo/junit/CgeoTestRunner.java
@@ -0,0 +1,120 @@
+package cgeo.junit;
+
+import com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner;
+import com.zutubi.android.junitreport.JUnitReportListener;
+import com.zutubi.android.junitreport.JUnitReportTestRunner;
+
+import android.os.Bundle;
+import android.test.AndroidTestRunner;
+import android.util.Log;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Test runner which derives from the newer Google instrumentation test runner used by the Espresso test framework. It
+ * adds junit report functionality by cloning the behaviour of the {@link JUnitReportTestRunner}.
+ *
+ */
+public class CgeoTestRunner extends GoogleInstrumentationTestRunner {
+
+ /**
+ * Name of the report file(s) to write, may contain __suite__ in multiFile mode.
+ */
+ private static final String ARG_REPORT_FILE = "reportFile";
+ /**
+ * If specified, path of the directory to write report files to. May start with __external__.
+ * If not set files are written to the internal storage directory of the app under test.
+ */
+ private static final String ARG_REPORT_DIR = "reportDir";
+ /**
+ * If true, stack traces in the report will be filtered to remove common noise (e.g. framework
+ * methods).
+ */
+ private static final String ARG_FILTER_TRACES = "filterTraces";
+ /**
+ * If true, produce a separate file for each test suite. By default a single report is created
+ * for all suites.
+ */
+ private static final String ARG_MULTI_FILE = "multiFile";
+ /**
+ * Default name of the single report file.
+ */
+ private static final String DEFAULT_SINGLE_REPORT_FILE = "junit-report.xml";
+ /**
+ * Default name pattern for multiple report files.
+ */
+ private static final String DEFAULT_MULTI_REPORT_FILE = "junit-report-" + JUnitReportListener.TOKEN_SUITE + ".xml";
+
+ private static final String LOG_TAG = CgeoTestRunner.class.getSimpleName();
+
+ private JUnitReportListener mListener;
+ private String mReportFile;
+ private String mReportDir;
+ private boolean mFilterTraces = true;
+ private boolean mMultiFile = false;
+
+ @Override
+ public void onCreate(Bundle arguments) {
+ if (arguments != null) {
+ Log.i(LOG_TAG, "Created with arguments: " + arguments.keySet());
+ mReportFile = arguments.getString(ARG_REPORT_FILE);
+ mReportDir = arguments.getString(ARG_REPORT_DIR);
+ mFilterTraces = getBooleanArgument(arguments, ARG_FILTER_TRACES, true);
+ mMultiFile = getBooleanArgument(arguments, ARG_MULTI_FILE, false);
+ } else {
+ Log.i(LOG_TAG, "No arguments provided");
+ }
+
+ if (mReportFile == null) {
+ mReportFile = mMultiFile ? DEFAULT_MULTI_REPORT_FILE : DEFAULT_SINGLE_REPORT_FILE;
+ }
+ Log.i(LOG_TAG, "report directory '" + mReportDir + "'");
+ Log.i(LOG_TAG, "report file '" + mReportFile + "'");
+
+ super.onCreate(arguments);
+ }
+
+ private static boolean getBooleanArgument(Bundle arguments, String name, boolean defaultValue) {
+ String value = arguments.getString(name);
+ if (value == null) {
+ return defaultValue;
+ }
+ return Boolean.parseBoolean(value);
+ }
+
+ @Override
+ public void start() {
+ mListener = new JUnitReportListener(getContext(), getTargetContext(), mReportFile, mReportDir, mFilterTraces, mMultiFile);
+ try {
+ Class<?> c = getClass();
+ Field bridgeTestRunner = c.getSuperclass().getDeclaredField("bridgeTestRunner");
+ bridgeTestRunner.setAccessible(true);
+ Object obj = bridgeTestRunner.get(this);
+ Method m = obj.getClass().getDeclaredMethod("getAndroidTestRunner", (Class[]) null);
+ AndroidTestRunner androidTestRunner = (AndroidTestRunner) m.invoke(obj);
+ androidTestRunner.addTestListener(mListener);
+ } catch (NoSuchFieldException x) {
+ Log.e(LOG_TAG, x.toString());
+ } catch (SecurityException e) {
+ Log.e(LOG_TAG, e.toString());
+ } catch (NoSuchMethodException e) {
+ Log.e(LOG_TAG, e.toString());
+ } catch (IllegalAccessException x) {
+ Log.e(LOG_TAG, x.toString());
+ } catch (InvocationTargetException e) {
+ Log.e(LOG_TAG, e.toString());
+ }
+ super.start();
+ }
+
+ @Override
+ public void finish(int resultCode, Bundle results) {
+ if (mListener != null) {
+ mListener.close();
+ }
+
+ super.finish(resultCode, results);
+ }
+}