aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2014-11-28 01:54:42 +0100
committerSamuel Tardieu <sam@rfc1149.net>2014-11-28 01:54:42 +0100
commit05e5d126293d682788f720816e5b010b11eaa829 (patch)
tree4050fce30d98cd4563f43ccdf9f6198769f48430
parent7fbeb61433d7297eb05aff9c762b555239f59490 (diff)
downloadcgeo-05e5d126293d682788f720816e5b010b11eaa829.zip
cgeo-05e5d126293d682788f720816e5b010b11eaa829.tar.gz
cgeo-05e5d126293d682788f720816e5b010b11eaa829.tar.bz2
Add GCLogin tests
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCLogin.java9
-rw-r--r--tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java29
2 files changed, 36 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/GCLogin.java b/main/src/cgeo/geocaching/connector/gc/GCLogin.java
index 667866b..faa57d1 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCLogin.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCLogin.java
@@ -267,12 +267,17 @@ public class GCLogin extends AbstractLogin {
return null;
}
+ @Nullable
+ static String retrieveHomeLocation() {
+ final String result = Network.getResponseData(Network.getRequest("https://www.geocaching.com/account/settings/homelocation"));
+ return TextUtils.getMatch(result, GCConstants.PATTERN_HOME_LOCATION, null);
+ }
+
private static void setHomeLocation() {
RxUtils.networkScheduler.createWorker().schedule(new Action0() {
@Override
public void call() {
- final String result = Network.getResponseData(Network.getRequest("https://www.geocaching.com/account/settings/homelocation"));
- final String homeLocationStr = TextUtils.getMatch(result, GCConstants.PATTERN_HOME_LOCATION, null);
+ final String homeLocationStr = retrieveHomeLocation();
if (StringUtils.isNotBlank(homeLocationStr) && !StringUtils.equals(homeLocationStr, Settings.getHomeLocation())) {
Log.i("Setting home location to " + homeLocationStr);
Settings.setHomeLocation(homeLocationStr);
diff --git a/tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java b/tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java
new file mode 100644
index 0000000..b03da4c
--- /dev/null
+++ b/tests/src/cgeo/geocaching/connector/gc/GCLoginTest.java
@@ -0,0 +1,29 @@
+package cgeo.geocaching.connector.gc;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.enumerations.StatusCode;
+
+import org.apache.commons.lang3.StringUtils;
+
+import junit.framework.TestCase;
+
+public class GCLoginTest extends TestCase {
+
+ final GCLogin instance = GCLogin.getInstance();
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ assertThat(instance.login()).isEqualTo(StatusCode.NO_ERROR);
+ }
+
+ public void testHomeLocation() {
+ assertThat(StringUtils.isNotBlank(GCLogin.retrieveHomeLocation())).isTrue();
+ }
+
+ public void testAvatar() {
+ assertThat(instance.downloadAvatarAndGetMemberStatus()).isNotNull();
+ }
+
+}