-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[f] 442 - As devices' user, I want to receive the push message and di…
…splay to screen
- Loading branch information
Showing
22 changed files
with
710 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"project_info": { | ||
"project_id": "watd-gcm", | ||
"project_number": "120607825117", | ||
"name": "WaTD-GCm" | ||
}, | ||
"client": [ | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:120607825117:android:6359edd5290a5eb2", | ||
"client_id": "android:com.eahackathon.watd.whosatthedoor", | ||
"client_type": 1, | ||
"android_client_info": { | ||
"package_name": "com.eahackathon.watd.whosatthedoor" | ||
} | ||
}, | ||
"oauth_client": [], | ||
"api_key": [], | ||
"services": { | ||
"analytics_service": { | ||
"status": 1 | ||
}, | ||
"cloud_messaging_service": { | ||
"status": 2, | ||
"apns_config": [] | ||
}, | ||
"appinvite_service": { | ||
"status": 1, | ||
"other_platform_oauth_client": [] | ||
}, | ||
"google_signin_service": { | ||
"status": 1 | ||
}, | ||
"ads_service": { | ||
"status": 1 | ||
} | ||
} | ||
} | ||
], | ||
"client_info": [], | ||
"ARTIFACT_VERSION": "1" | ||
} |
48 changes: 48 additions & 0 deletions
48
app/src/androidTest/java/com/eahackathon/watd/whosatthedoor/MainActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.eahackathon.watd.whosatthedoor; | ||
|
||
import android.content.Intent; | ||
import android.support.test.rule.ActivityTestRule; | ||
|
||
import com.eahackathon.watd.whosatthedoor.helpers.GcmRegistrationHelper; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.action.ViewActions.click; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
/** | ||
* Created by Hoang Phan on 1/9/2016. | ||
*/ | ||
public class MainActivityTest { | ||
private MainActivity mActivity; | ||
|
||
@Rule | ||
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class); | ||
|
||
@Before | ||
public void setUp() { | ||
mActivity = mActivityTestRule.getActivity(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
GcmRegistrationHelper.setInstance(null); | ||
} | ||
|
||
@Test | ||
public void testMain_click_on_start_service() throws Exception { | ||
GcmRegistrationHelper mockHelper = mock(GcmRegistrationHelper.class); | ||
GcmRegistrationHelper.setInstance(mockHelper); | ||
|
||
onView(withId(R.id.btn_start)).perform(click()); | ||
Thread.sleep(1000); | ||
|
||
verify(mockHelper).register(); | ||
} | ||
} |
141 changes: 141 additions & 0 deletions
141
app/src/androidTest/java/com/eahackathon/watd/whosatthedoor/NotificationActivityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package com.eahackathon.watd.whosatthedoor; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.res.AssetManager; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.rule.ActivityTestRule; | ||
|
||
import com.eahackathon.watd.whosatthedoor.models.ResponseModel; | ||
import com.eahackathon.watd.whosatthedoor.models.UpdatePersonNameRequest; | ||
import com.eahackathon.watd.whosatthedoor.network.APIService; | ||
import com.eahackathon.watd.whosatthedoor.network.WaTDAPI; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import retrofit.Call; | ||
import retrofit.Callback; | ||
import retrofit.Response; | ||
|
||
import static android.support.test.espresso.Espresso.onView; | ||
import static android.support.test.espresso.action.ViewActions.click; | ||
import static android.support.test.espresso.assertion.ViewAssertions.matches; | ||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withId; | ||
import static android.support.test.espresso.matcher.ViewMatchers.withText; | ||
import static junit.framework.Assert.assertFalse; | ||
import static junit.framework.Assert.assertTrue; | ||
import static org.hamcrest.core.IsNot.not; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Created by Hoang Phan on 1/9/2016. | ||
*/ | ||
public class NotificationActivityTest { | ||
|
||
private NotificationActivity mActivity; | ||
private WaTDAPI mMockWaTDAPI; | ||
private ArgumentCaptor<Callback> mCallCaptor; | ||
private Call<ResponseModel> mMockCall; | ||
|
||
@Rule | ||
public ActivityTestRule<NotificationActivity> mActivityTestRule = new ActivityTestRule<NotificationActivity>(NotificationActivity.class) { | ||
@Override | ||
protected Intent getActivityIntent() { | ||
Context targetContext = InstrumentationRegistry.getInstrumentation() | ||
.getTargetContext(); | ||
Intent result = new Intent(targetContext, NotificationActivity.class); | ||
result.putExtra(Constants.PERSON_NAME, "My name"); | ||
result.putExtra(Constants.PERSON_ID, "1"); | ||
AssetManager manager = targetContext.getAssets(); | ||
try { | ||
InputStream is = manager.open("test.jpg"); | ||
int size = is.available(); | ||
byte[] buffer = new byte[size]; | ||
is.read(buffer); | ||
is.close(); | ||
result.putExtra(Constants.PERSON_DATA, buffer); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return result; | ||
} | ||
}; | ||
|
||
@Before | ||
public void setUp() { | ||
mActivity = mActivityTestRule.getActivity(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
APIService.setInstance(null); | ||
} | ||
|
||
@Test | ||
public void testNotification_show_name_and_image() throws InterruptedException { | ||
onView(withId(R.id.et_person)).check(matches(withText("My name"))); | ||
onView(withId(R.id.tv_person)).check(matches(withText("My name"))); | ||
onView(withId(R.id.et_person)).check(matches(not(isDisplayed()))); | ||
onView(withId(R.id.tv_person)).check(matches(isDisplayed())); | ||
onView(withId(R.id.iv_person)).check(matches(isDisplayed())); | ||
onView(withId(R.id.btn_ok)).check(matches(isDisplayed())); | ||
onView(withId(R.id.btn_another)).check(matches(isDisplayed())); | ||
} | ||
|
||
@Test | ||
public void testNotification_click_another_btn() throws InterruptedException { | ||
onView(withId(R.id.btn_another)).perform(click()); | ||
|
||
onView(withId(R.id.et_person)).check(matches(isDisplayed())); | ||
onView(withId(R.id.tv_person)).check(matches(not(isDisplayed()))); | ||
onView(withId(R.id.btn_another)).check(matches(not(isDisplayed()))); | ||
} | ||
|
||
@Test | ||
public void testNotification_click_ok_success() throws InterruptedException { | ||
Response<ResponseModel> fakeSuccessResponse = Response.success(new ResponseModel()); | ||
setUpMockCall(); | ||
|
||
onView(withId(R.id.btn_ok)).perform(click()); | ||
Thread.sleep(1000); | ||
|
||
verify(mMockCall).enqueue(mCallCaptor.capture()); | ||
mCallCaptor.getValue().onResponse(fakeSuccessResponse, null); | ||
|
||
assertTrue(mActivity.isFinishing()); | ||
} | ||
|
||
@Test | ||
public void testNotification_click_ok_failure() throws InterruptedException { | ||
setUpMockCall(); | ||
|
||
onView(withId(R.id.btn_ok)).perform(click()); | ||
Thread.sleep(1000); | ||
|
||
verify(mMockCall).enqueue(mCallCaptor.capture()); | ||
mCallCaptor.getValue().onFailure(null); | ||
|
||
assertFalse(mActivity.isFinishing()); | ||
} | ||
|
||
private void setUpMockCall() { | ||
mMockWaTDAPI = Mockito.mock(WaTDAPI.class); | ||
mCallCaptor = ArgumentCaptor.forClass(Callback.class); | ||
mMockCall = Mockito.mock(Call.class); | ||
|
||
when(mMockWaTDAPI.updatePersonName(any(String.class), any(UpdatePersonNameRequest.class))).thenReturn(mMockCall); | ||
APIService.setInstance(mMockWaTDAPI); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/eahackathon/watd/whosatthedoor/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.eahackathon.watd.whosatthedoor; | ||
|
||
/** | ||
* Created by KienDu on 1/9/2016. | ||
*/ | ||
public interface Constants { | ||
String API_ENDPOINT = "http://dcb86d07.ngrok.io"; | ||
|
||
String PERSON_NAME = "name"; | ||
String PERSON_ID = "id"; | ||
String PERSON_DATA = "data"; | ||
} |
Oops, something went wrong.