diff options
8 files changed, 232 insertions, 10 deletions
diff --git a/main/src/cgeo/geocaching/EditWaypointActivity.java b/main/src/cgeo/geocaching/EditWaypointActivity.java index 7193b27..7b444fb 100644 --- a/main/src/cgeo/geocaching/EditWaypointActivity.java +++ b/main/src/cgeo/geocaching/EditWaypointActivity.java @@ -66,7 +66,7 @@ public class EditWaypointActivity extends AbstractActionBarActivity implements C @ViewById(R.id.modify_cache_coordinates_local) protected RadioButton modifyLocal; @Extra(Intents.EXTRA_GEOCODE) protected String geocode = null; - @Extra(Intents.EXTRA_WAYPOINT_ID) protected int id = -1; + @Extra(Intents.EXTRA_WAYPOINT_ID) protected int waypointId = -1; /** * number of waypoints that the corresponding cache has until now */ @@ -95,8 +95,8 @@ public class EditWaypointActivity extends AbstractActionBarActivity implements C public void handleMessage(final Message msg) { try { if (waypoint == null) { - Log.d("No waypoint loaded to edit. id= " + id); - id = -1; + Log.d("No waypoint loaded to edit. id= " + waypointId); + waypointId = -1; } else { geocode = waypoint.getGeocode(); prefix = waypoint.getPrefix(); @@ -141,14 +141,14 @@ public class EditWaypointActivity extends AbstractActionBarActivity implements C public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState, R.layout.editwaypoint_activity); - if (StringUtils.isBlank(geocode) && id <= 0) { + if (StringUtils.isBlank(geocode) && waypointId <= 0) { showToast(res.getString(R.string.err_waypoint_cache_unknown)); finish(); return; } - if (id <= 0) { + if (waypointId <= 0) { setTitle(res.getString(R.string.waypoint_add_title)); } else { setTitle(res.getString(R.string.waypoint_edit_title)); @@ -174,7 +174,7 @@ public class EditWaypointActivity extends AbstractActionBarActivity implements C cache = DataStore.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); setCoordsModificationVisibility(ConnectorFactory.getConnector(geocode), cache); } - if (id > 0) { // existing waypoint + if (waypointId > 0) { // existing waypoint waitDialog = ProgressDialog.show(this, null, res.getString(R.string.waypoint_loading), true); waitDialog.setCancelable(true); @@ -279,7 +279,7 @@ public class EditWaypointActivity extends AbstractActionBarActivity implements C @Override public void run() { try { - waypoint = DataStore.loadWaypoint(id); + waypoint = DataStore.loadWaypoint(waypointId); loadWaypointHandler.sendMessage(Message.obtain()); } catch (final Exception e) { @@ -465,14 +465,14 @@ public class EditWaypointActivity extends AbstractActionBarActivity implements C waypoint.setCoords(coordsToSave); waypoint.setNote(noteText); waypoint.setVisited(visited); - waypoint.setId(id); + waypoint.setId(waypointId); final Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS); if (cache == null) { finishHandler.sendEmptyMessage(SAVE_ERROR); return null; } - final Waypoint oldWaypoint = cache.getWaypointById(id); + final Waypoint oldWaypoint = cache.getWaypointById(waypointId); if (cache.addOrChangeWaypoint(waypoint, true)) { DataStore.saveCache(cache, EnumSet.of(SaveFlag.DB)); if (!StaticMapsProvider.hasAllStaticMapsForWaypoint(geocode, waypoint)) { @@ -520,7 +520,7 @@ public class EditWaypointActivity extends AbstractActionBarActivity implements C } public static void startActivityEditWaypoint(final Context context, final Geocache cache, final int waypointId) { - EditWaypointActivity_.intent(context).geocode(cache.getGeocode()).id(waypointId).start(); + EditWaypointActivity_.intent(context).geocode(cache.getGeocode()).waypointId(waypointId).start(); } public static void startActivityAddWaypoint(final Context context, final Geocache cache) { diff --git a/tests/src/cgeo/geocaching/waypointactivity/AbstractAddWaypointActivityTest.java b/tests/src/cgeo/geocaching/waypointactivity/AbstractAddWaypointActivityTest.java new file mode 100644 index 0000000..34968a3 --- /dev/null +++ b/tests/src/cgeo/geocaching/waypointactivity/AbstractAddWaypointActivityTest.java @@ -0,0 +1,12 @@ +package cgeo.geocaching.waypointactivity; + +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()).wpCount(1).get()); + getActivity(); + } +} diff --git a/tests/src/cgeo/geocaching/waypointactivity/AbstractEditWaypointActivityTest.java b/tests/src/cgeo/geocaching/waypointactivity/AbstractEditWaypointActivityTest.java new file mode 100644 index 0000000..e5cdf69 --- /dev/null +++ b/tests/src/cgeo/geocaching/waypointactivity/AbstractEditWaypointActivityTest.java @@ -0,0 +1,28 @@ +package cgeo.geocaching.waypointactivity; + +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/waypointactivity/AbstractWaypointActivityTest.java b/tests/src/cgeo/geocaching/waypointactivity/AbstractWaypointActivityTest.java new file mode 100644 index 0000000..1a5783c --- /dev/null +++ b/tests/src/cgeo/geocaching/waypointactivity/AbstractWaypointActivityTest.java @@ -0,0 +1,53 @@ +package cgeo.geocaching.waypointactivity; + +import cgeo.geocaching.DataStore; +import cgeo.geocaching.EditWaypointActivity_; +import cgeo.geocaching.Geocache; +import cgeo.geocaching.enumerations.CacheType; +import cgeo.geocaching.enumerations.LoadFlags; +import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; + +import android.test.ActivityInstrumentationTestCase2; + +import java.util.Collections; + +import static org.assertj.core.api.Assertions.assertThat; + +public abstract class AbstractWaypointActivityTest extends ActivityInstrumentationTestCase2<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/waypointactivity/AddWaypointActivityTest.java b/tests/src/cgeo/geocaching/waypointactivity/AddWaypointActivityTest.java new file mode 100644 index 0000000..86a7684 --- /dev/null +++ b/tests/src/cgeo/geocaching/waypointactivity/AddWaypointActivityTest.java @@ -0,0 +1,34 @@ +package cgeo.geocaching.waypointactivity; + +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.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 cgeo.geocaching.R; +import cgeo.geocaching.enumerations.WaypointType; + +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())); + } +} diff --git a/tests/src/cgeo/geocaching/waypointactivity/AddWaypointMultiTest.java b/tests/src/cgeo/geocaching/waypointactivity/AddWaypointMultiTest.java new file mode 100644 index 0000000..3a32570 --- /dev/null +++ b/tests/src/cgeo/geocaching/waypointactivity/AddWaypointMultiTest.java @@ -0,0 +1,34 @@ +package cgeo.geocaching.waypointactivity; + +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/waypointactivity/AddWaypointMysteryTest.java b/tests/src/cgeo/geocaching/waypointactivity/AddWaypointMysteryTest.java new file mode 100644 index 0000000..248f107 --- /dev/null +++ b/tests/src/cgeo/geocaching/waypointactivity/AddWaypointMysteryTest.java @@ -0,0 +1,32 @@ +package cgeo.geocaching.waypointactivity; + +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/waypointactivity/EditWaypointActivityTest.java b/tests/src/cgeo/geocaching/waypointactivity/EditWaypointActivityTest.java new file mode 100644 index 0000000..eda86cc --- /dev/null +++ b/tests/src/cgeo/geocaching/waypointactivity/EditWaypointActivityTest.java @@ -0,0 +1,29 @@ +package cgeo.geocaching.waypointactivity; + +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())))); + } + +} |
