diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/presenter/HomeNotificationHandler.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/presenter/HomeNotificationHandler.java index 96decabd..eb0f4f4d 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/presenter/HomeNotificationHandler.java +++ b/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) diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/presenter/HomeV2Presenter.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/presenter/HomeV2Presenter.java index fa25555d..47903fd4 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/presenter/HomeV2Presenter.java +++ b/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 { @@ -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"); diff --git a/app/src/test/java/com/gmeremit/online/gmeremittance_native/HomeNotificationHandlerTest.java b/app/src/test/java/com/gmeremit/online/gmeremittance_native/HomeNotificationHandlerTest.java index ddb28dba..32f7e903 100644 --- a/app/src/test/java/com/gmeremit/online/gmeremittance_native/HomeNotificationHandlerTest.java +++ b/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,46 +17,50 @@ 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 - * + *

* 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 - * - * + * 1) Redirect Notification + * 2) Registration Notification + * Precedence Order + * Redirect Notification (AUTO_DEBIT_REDIRECT) > Registration Notification (KYC_SUBMIT, KYC_VERIFIED, PENNY_TEST_STATUS) */ @RunWith(JUnitParamsRunner.class) public class HomeNotificationHandlerTest { - private static final String AUTO_DEBIT_ROUTE_STRING="autoDebit"; - private static final String AUTO_DEBIT_EMPTY_ROUTE_STRING =""; - private static final String AUTO_DEBIT__NULL_ROUTE_STRING=null; + private static final String AUTO_DEBIT_ROUTE_STRING = "autoDebit"; + private static final String AUTO_DEBIT_EMPTY_ROUTE_STRING = ""; + private static final String AUTO_DEBIT__NULL_ROUTE_STRING = null; - private static final String PENNY_TEST_NOT_STARTED="0"; - private static final String PENNY_TEST_ONLY_REQUESTED="1"; - private static final String PENNY_TEST_COMPLETED="2"; - private static final String PENNY_TEST_STATUS_UNDEFINED=null; + private static final String PENNY_TEST_NOT_STARTED = "0"; + private static final String PENNY_TEST_ONLY_REQUESTED = "1"; + private static final String PENNY_TEST_COMPLETED = "2"; + private static final String PENNY_TEST_STATUS_UNDEFINED = null; - private static final boolean KYC_NOT_VERIFIED_FLAG=false; - private static final boolean KYC_VERIFIED_FLAG=true; + private static final boolean KYC_NOT_VERIFIED_FLAG = false; + private static final boolean KYC_VERIFIED_FLAG = true; - private static final boolean KYC_NOT_SUBMITTED_FLAG=false; - private static final boolean KYC_SUBMITTED_FLAG=true; + 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")); } - private static GmeApplication.StringExtractor dummyStringExtractor=Mockito.mock(GmeApplication.StringExtractor.class); + 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); // @@ -71,111 +77,104 @@ public class HomeNotificationHandlerTest { // // } - @Test - public void shouldShowAutoDebitRedirectPopup() - { - HomeNotificationHandler notificationHandler=new HomeNotificationHandler(dummyStringExtractor,KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_NOT_STARTED,AUTO_DEBIT_ROUTE_STRING); +// @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); +// } - assertEquals("Should have shown auto debit route popup",AUTO_DEBIT_FILLUP_REQUIRED,notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType()); + @Test + 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() - { - HomeNotificationHandler notificationHandler=new HomeNotificationHandler(dummyStringExtractor,KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_NOT_STARTED,AUTO_DEBIT_EMPTY_ROUTE_STRING); + 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()); + assertNotEquals("Should not have shown auto debit route popup", AUTO_DEBIT_FILLUP_REQUIRED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType()); } @Test - public void shouldNotShowAutoDebitRedirectPopupForNullRoute() - { - HomeNotificationHandler notificationHandler=new HomeNotificationHandler(dummyStringExtractor,KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_NOT_STARTED,AUTO_DEBIT__NULL_ROUTE_STRING); + 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()); + assertNotEquals("Should not have shown auto debit route popup", AUTO_DEBIT_FILLUP_REQUIRED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType()); } @Test - public void shouldShowKYCNotSubmittedPopUpForNotSubmittedStatus() - { - HomeNotificationHandler notificationHandler=new HomeNotificationHandler(dummyStringExtractor,KYC_NOT_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_COMPLETED,AUTO_DEBIT__NULL_ROUTE_STRING); + 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()); + assertEquals("Should have shown kyc not submitted popup", KYC_NOT_SUBMITTED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType()); } @Test - 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()); + 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() - { - HomeNotificationHandler notificationHandler=new HomeNotificationHandler(dummyStringExtractor,KYC_SUBMITTED_FLAG,KYC_NOT_VERIFIED_FLAG,PENNY_TEST_COMPLETED,AUTO_DEBIT__NULL_ROUTE_STRING); + 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()); + assertEquals("Should have shown kyc not verified popup", KYC_NOT_VERIFIED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType()); } @Test - 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()); + 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()); } @Test - public void shouldShowPennyTestNotCompletedPopupForNotStartedStatus() - { - HomeNotificationHandler notificationHandler=new HomeNotificationHandler(dummyStringExtractor,KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_NOT_STARTED,AUTO_DEBIT_EMPTY_ROUTE_STRING); + 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()); + assertEquals("Should have shown penny test popup", PENNY_TEST_REQUIRED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType()); } @Test - public void shouldShowPennyTestNotCompletedPopupForUndefinedStatus() - { - HomeNotificationHandler notificationHandler=new HomeNotificationHandler(dummyStringExtractor,KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_STATUS_UNDEFINED,AUTO_DEBIT_EMPTY_ROUTE_STRING); + 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()); + assertEquals("Should have shown penny test popup", PENNY_TEST_REQUIRED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType()); } @Test - public void shouldShowPennyTestNotCompletedPopupForOnlyRequestedStatus() - { - HomeNotificationHandler notificationHandler=new HomeNotificationHandler(dummyStringExtractor,KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_ONLY_REQUESTED,AUTO_DEBIT_EMPTY_ROUTE_STRING); + 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()); + assertEquals("Should have shown penny test popup", PENNY_TEST_REQUIRED, notificationHandler.generateAppropriateHomeNotificationViewDTO().getNoticeViewType()); } @Test - public void shouldNotShowPennyTestPopupForCompletedStatus() - { - HomeNotificationHandler notificationHandler=new HomeNotificationHandler(dummyStringExtractor,KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_COMPLETED,AUTO_DEBIT_EMPTY_ROUTE_STRING); + 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()); + assertNull("Should have return null for penny test completed status", notificationHandler.generateAppropriateHomeNotificationViewDTO()); } - private void stubStringExtractor() - { - Mockito.when(dummyStringExtractor.getStringFromStringId(Mockito.any())).thenReturn("Dummy localized string"); + private void stubStringExtractor() { + Mockito.when(dummyStringExtractor.getStringFromStringId(Mockito.any())).thenReturn("Dummy localized string"); } }