Browse Source

Notification Handler ready to be ported

master
Preyea Regmi 5 years ago
parent
commit
27ecfb36cf
  1. 10
      app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/presenter/HomeNotificationHandler.java
  2. 8
      app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/presenter/HomeV2Presenter.java
  3. 65
      app/src/test/java/com/gmeremit/online/gmeremittance_native/HomeNotificationHandlerTest.java

10
app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/presenter/HomeNotificationHandler.java

@ -19,9 +19,17 @@ public class HomeNotificationHandler {
public HomeNotificationHandler(GmeApplication.StringExtractor stringExtractor, boolean kycSubmit, boolean isVerified, String pennyTestStatus, String redirectTo) {
this.kycSubmit = kycSubmit;
this.isVerified = isVerified;
this.pennyTestStatus = pennyTestStatus;
this.redirectTo = redirectTo;
this.stringExtractor = stringExtractor;
this.pennyTestStatus = pennyTestStatus;
// if("1".equalsIgnoreCase(pennyTestStatus)||"2".equalsIgnoreCase(pennyTestStatus)||"0".equalsIgnoreCase(pennyTestStatus))
// {
// this.pennyTestStatus = pennyTestStatus;
// }
// else
// throw new IllegalArgumentException("Invalid penny test status : "+pennyTestStatus);
}
private HomeNotificationHandler(GmeApplication.StringExtractor stringExtractor)

8
app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/presenter/HomeV2Presenter.java

@ -213,7 +213,10 @@ public class HomeV2Presenter extends BasePresenter implements HomeV2PresenterInt
getRequiredCachedData();
}
/**
* Now home can show different variety on notification and notification type generation is segregated to HomeNotificationHandler class instead of doing it here.
* Consider using UserInfoObserverV2
*/
@Deprecated
public class UserInfoObserver extends UserSessionObserverResponse<UserInfoModelV2> {
@ -262,7 +265,6 @@ public class HomeV2Presenter extends BasePresenter implements HomeV2PresenterInt
boolean shouldShowKJBankNotice = checkIfShouldShowKJNotice();
//TODO Construct HomeNoticeViewDTO from above data using HomeNotificationHandler
if (homeFragmentRelatedSubject != null)
homeFragmentRelatedSubject.onNext(new HomeViewRelatedDTO(shouldShowKYCView, kycMessage, kycTitle,
disableKYCViewClick, fullName, userInfoModelV2.getYearlyLimit(),
@ -310,7 +312,7 @@ public class HomeV2Presenter extends BasePresenter implements HomeV2PresenterInt
//TODO Mocking server response here
userInfoModelV2.setRedirectTo("");
userInfoModelV2.setKyc(true);
userInfoModelV2.setKyc(false);
userInfoModelV2.setVerified(false);
userInfoModelV2.setPennyTestStatus("2");

65
app/src/test/java/com/gmeremit/online/gmeremittance_native/HomeNotificationHandlerTest.java

@ -4,8 +4,10 @@ import com.gmeremit.online.gmeremittance_native.homeV2.presenter.HomeNotificatio
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import static com.gmeremit.online.gmeremittance_native.homeV2.presenter.HomeNotificationHandler.HomeNoticeViewTypeEnum.AUTO_DEBIT_FILLUP_REQUIRED;
import static com.gmeremit.online.gmeremittance_native.homeV2.presenter.HomeNotificationHandler.HomeNoticeViewTypeEnum.KYC_NOT_SUBMITTED;
@ -15,20 +17,17 @@ import static junitparams.JUnitParamsRunner.$;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import org.mockito.*;
/**
* @author Preyea R. Regmi
*
* <p>
* This is unit test for notification generating process
* Currently two set of Notification shown.
* 1) Redirect Notification
* 2) Registration Notification
* Precedence Order
* Redirect Notification > Registration Notification
*
*
* Redirect Notification (AUTO_DEBIT_REDIRECT) > Registration Notification (KYC_SUBMIT, KYC_VERIFIED, PENNY_TEST_STATUS)
*/
@RunWith(JUnitParamsRunner.class)
@ -49,11 +48,18 @@ public class HomeNotificationHandlerTest {
private static final boolean KYC_NOT_SUBMITTED_FLAG = false;
private static final boolean KYC_SUBMITTED_FLAG = true;
public static Object[] getRequiredFlags()
{
return $($(false,false,"0","autodebit"));
public static Object[] getRequiredFlags() {
return $($(false, false, "2", "autodebit"));
}
public static Object[] getInvalidPennyTestContructorParam() {
return $(
$(false, false, "", "autodebit"), $(false, false, null, "autodebit"), $(false, false, "-1", "autodebit"), $(false, false, "3", "autodebit")
);
}
private static GmeApplication.StringExtractor dummyStringExtractor = Mockito.mock(GmeApplication.StringExtractor.class);
@ -69,21 +75,24 @@ public class HomeNotificationHandlerTest {
// assertEquals("Passed pennyTestStatus :"+pennyTestStatus+ " doesn't match with returned value: "+notificationHandler.getPennyTestStatus(),notificationHandler.getPennyTestStatus(),pennyTestStatus);
// assertEquals("Passed redirectTo :"+kycSubmit+ " doesn't match with returned value: "+notificationHandler.getRedirectTo(),notificationHandler.getRedirectTo(),redirectTo);
//
// }
// @Test(expected = IllegalArgumentException.class)
// @Parameters(method = "getRequiredFlags")
// public void throwIAEIFConstructorArgumentValueIsInvalid(boolean kycSubmit, boolean isVerified, String pennyTestSTatus, String redirectTo) {
// new HomeNotificationHandler(dummyStringExtractor, kycSubmit, isVerified, pennyTestSTatus, redirectTo);
// }
@Test
public void shouldShowAutoDebitRedirectPopup()
{
public void shouldShowAutoDebitRedirectPopup() {
HomeNotificationHandler notificationHandler = new HomeNotificationHandler(dummyStringExtractor, KYC_SUBMITTED_FLAG, KYC_VERIFIED_FLAG, PENNY_TEST_NOT_STARTED, AUTO_DEBIT_ROUTE_STRING);
assertEquals("Should have shown auto debit route popup", AUTO_DEBIT_FILLUP_REQUIRED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType());
}
@Test
public void shouldNotShowAutoDebitRedirectPopupForEmptryRoute()
{
public void shouldNotShowAutoDebitRedirectPopupForEmptryRoute() {
HomeNotificationHandler notificationHandler = new HomeNotificationHandler(dummyStringExtractor, KYC_SUBMITTED_FLAG, KYC_VERIFIED_FLAG, PENNY_TEST_NOT_STARTED, AUTO_DEBIT_EMPTY_ROUTE_STRING);
assertNotEquals("Should not have shown auto debit route popup", AUTO_DEBIT_FILLUP_REQUIRED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType());
@ -91,8 +100,7 @@ public class HomeNotificationHandlerTest {
}
@Test
public void shouldNotShowAutoDebitRedirectPopupForNullRoute()
{
public void shouldNotShowAutoDebitRedirectPopupForNullRoute() {
HomeNotificationHandler notificationHandler = new HomeNotificationHandler(dummyStringExtractor, KYC_SUBMITTED_FLAG, KYC_VERIFIED_FLAG, PENNY_TEST_NOT_STARTED, AUTO_DEBIT__NULL_ROUTE_STRING);
assertNotEquals("Should not have shown auto debit route popup", AUTO_DEBIT_FILLUP_REQUIRED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType());
@ -100,8 +108,7 @@ public class HomeNotificationHandlerTest {
}
@Test
public void shouldShowKYCNotSubmittedPopUpForNotSubmittedStatus()
{
public void shouldShowKYCNotSubmittedPopUpForNotSubmittedStatus() {
HomeNotificationHandler notificationHandler = new HomeNotificationHandler(dummyStringExtractor, KYC_NOT_SUBMITTED_FLAG, KYC_VERIFIED_FLAG, PENNY_TEST_COMPLETED, AUTO_DEBIT__NULL_ROUTE_STRING);
assertEquals("Should have shown kyc not submitted popup", KYC_NOT_SUBMITTED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType());
@ -110,16 +117,14 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldNotShowKYCNotSubmittedPopUpForSubmittedStatus()
{
public void shouldNotShowKYCNotSubmittedPopUpForSubmittedStatus() {
HomeNotificationHandler notificationHandler = new HomeNotificationHandler(dummyStringExtractor, KYC_SUBMITTED_FLAG, KYC_NOT_VERIFIED_FLAG, PENNY_TEST_NOT_STARTED, AUTO_DEBIT__NULL_ROUTE_STRING);
assertNotEquals("Should not have shown kyc not submitted popup", KYC_NOT_SUBMITTED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType());
}
@Test
public void shouldShowKYCNotVerifiedPopUpForUnverifiedStatus()
{
public void shouldShowKYCNotVerifiedPopUpForUnverifiedStatus() {
HomeNotificationHandler notificationHandler = new HomeNotificationHandler(dummyStringExtractor, KYC_SUBMITTED_FLAG, KYC_NOT_VERIFIED_FLAG, PENNY_TEST_COMPLETED, AUTO_DEBIT__NULL_ROUTE_STRING);
assertEquals("Should have shown kyc not verified popup", KYC_NOT_VERIFIED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType());
@ -127,8 +132,7 @@ public class HomeNotificationHandlerTest {
}
@Test
public void shouldNotShowKYCNotVerifiedPopUpForVerifiedStatus()
{
public void shouldNotShowKYCNotVerifiedPopUpForVerifiedStatus() {
HomeNotificationHandler notificationHandler = new HomeNotificationHandler(dummyStringExtractor, KYC_SUBMITTED_FLAG, KYC_VERIFIED_FLAG, PENNY_TEST_NOT_STARTED, AUTO_DEBIT__NULL_ROUTE_STRING);
assertNotEquals("Should not have shown kyc not verified popup", KYC_NOT_VERIFIED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType());
@ -136,8 +140,7 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldShowPennyTestNotCompletedPopupForNotStartedStatus()
{
public void shouldShowPennyTestNotCompletedPopupForNotStartedStatus() {
HomeNotificationHandler notificationHandler = new HomeNotificationHandler(dummyStringExtractor, KYC_SUBMITTED_FLAG, KYC_VERIFIED_FLAG, PENNY_TEST_NOT_STARTED, AUTO_DEBIT_EMPTY_ROUTE_STRING);
assertEquals("Should have shown penny test popup", PENNY_TEST_REQUIRED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType());
@ -145,8 +148,7 @@ public class HomeNotificationHandlerTest {
}
@Test
public void shouldShowPennyTestNotCompletedPopupForUndefinedStatus()
{
public void shouldShowPennyTestNotCompletedPopupForUndefinedStatus() {
HomeNotificationHandler notificationHandler = new HomeNotificationHandler(dummyStringExtractor, KYC_SUBMITTED_FLAG, KYC_VERIFIED_FLAG, PENNY_TEST_STATUS_UNDEFINED, AUTO_DEBIT_EMPTY_ROUTE_STRING);
assertEquals("Should have shown penny test popup", PENNY_TEST_REQUIRED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType());
@ -155,8 +157,7 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldShowPennyTestNotCompletedPopupForOnlyRequestedStatus()
{
public void shouldShowPennyTestNotCompletedPopupForOnlyRequestedStatus() {
HomeNotificationHandler notificationHandler = new HomeNotificationHandler(dummyStringExtractor, KYC_SUBMITTED_FLAG, KYC_VERIFIED_FLAG, PENNY_TEST_ONLY_REQUESTED, AUTO_DEBIT_EMPTY_ROUTE_STRING);
assertEquals("Should have shown penny test popup", PENNY_TEST_REQUIRED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType());
@ -165,16 +166,14 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldNotShowPennyTestPopupForCompletedStatus()
{
public void shouldNotShowPennyTestPopupForCompletedStatus() {
HomeNotificationHandler notificationHandler = new HomeNotificationHandler(dummyStringExtractor, KYC_SUBMITTED_FLAG, KYC_VERIFIED_FLAG, PENNY_TEST_COMPLETED, AUTO_DEBIT_EMPTY_ROUTE_STRING);
assertNull("Should have return null for penny test completed status", notificationHandler.generateAppropriateHomeNotificationViewDTO());
}
private void stubStringExtractor()
{
private void stubStringExtractor() {
Mockito.when(dummyStringExtractor.getStringFromStringId(Mockito.any())).thenReturn("Dummy localized string");
}

Loading…
Cancel
Save