Browse Source

All Valid unit test passed for getAppropriateHomeNotice method in HomeNotificationHandler

master
Preyea Regmi 5 years ago
parent
commit
9e827ee680
  1. 17
      app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/presenter/HomeNotificationHandler.java
  2. 1
      app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/presenter/HomeV2Presenter.java
  3. 1
      app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/view/HomeFragmentV2.java
  4. 40
      app/src/test/java/com/gmeremit/online/gmeremittance_native/HomeNotificationHandlerTest.java

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

@ -1,36 +1,43 @@
package com.gmeremit.online.gmeremittance_native.homeV2.presenter;
import com.gmeremit.online.gmeremittance_native.GmeApplication;
import com.gmeremit.online.gmeremittance_native.R;
import com.gmeremit.online.gmeremittance_native.homeV2.model.HomeNoticeViewDTO;
/**
* @author Inorder to understand the implementation of this class, consider reading the corresponding Unit Test : HomeNotificationHandlerTest
*/
public class HomeNotificationHandler {
private final GmeApplication.StringExtractor stringExtractor;
private boolean kycSubmit;
private boolean isVerified;
private String pennyTestStatus;
private String redirectTo;
public HomeNotificationHandler(boolean kycSubmit, boolean isVerified, String pennyTestStatus, String redirectTo) {
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;
}
public HomeNoticeViewDTO getAppropriateHomeNotice() {
if ("autoDebit".equalsIgnoreCase(redirectTo))
return new HomeNoticeViewDTO("", "", HomeNoticeViewTypeEnum.AUTO_DEBIT_FILLUP_REQUIRED);
return new HomeNoticeViewDTO(stringExtractor.getStringFromStringId(R.string.text1), stringExtractor.getStringFromStringId(R.string.text1), HomeNoticeViewTypeEnum.AUTO_DEBIT_FILLUP_REQUIRED);
else {
{
if (!kycSubmit)
return new HomeNoticeViewDTO("", "", HomeNoticeViewTypeEnum.KYC_NOT_SUBMITTED);
return new HomeNoticeViewDTO(stringExtractor.getStringFromStringId(R.string.text1), stringExtractor.getStringFromStringId(R.string.text1), HomeNoticeViewTypeEnum.KYC_NOT_SUBMITTED);
else {
if (!isVerified)
return new HomeNoticeViewDTO("", "", HomeNoticeViewTypeEnum.KYC_NOT_VERIFIED);
return new HomeNoticeViewDTO(stringExtractor.getStringFromStringId(R.string.text1), stringExtractor.getStringFromStringId(R.string.text1), HomeNoticeViewTypeEnum.KYC_NOT_VERIFIED);
else {
if (!"2".equalsIgnoreCase(pennyTestStatus))
return new HomeNoticeViewDTO("", "", HomeNoticeViewTypeEnum.PENNY_TEST_REQUIRED);
return new HomeNoticeViewDTO(stringExtractor.getStringFromStringId(R.string.text1), stringExtractor.getStringFromStringId(R.string.text1), HomeNoticeViewTypeEnum.PENNY_TEST_REQUIRED);
else
return null;
}

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

@ -257,6 +257,7 @@ 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(),

1
app/src/main/java/com/gmeremit/online/gmeremittance_native/homeV2/view/HomeFragmentV2.java

@ -491,6 +491,7 @@ public class HomeFragmentV2 extends BaseFragment implements HomeMenuRvAdapterV2.
@Override
protected void onSuccess(HomeViewRelatedDTOV2 homeViewRelatedDTOV2) {
updateInfo(homeViewRelatedDTOV2.getUserName(), homeViewRelatedDTOV2.getYearlyLimit(), homeViewRelatedDTOV2.getRewardPoint());
showNotificationView(HomeNotificiationViewFactory.getNotificationView(homeViewRelatedDTOV2.getHomeNoticeViewDTO(), getActivity()));
}

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

@ -16,6 +16,8 @@ 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
@ -39,6 +41,7 @@ public class HomeNotificationHandlerTest {
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;
@ -51,6 +54,9 @@ public class HomeNotificationHandlerTest {
return $($(false,false,"0","autodebit"));
}
private static GmeApplication.StringExtractor dummyStringExtractor=Mockito.mock(GmeApplication.StringExtractor.class);
//
// @Test
// @Parameters(method="getRequiredFlags")
@ -68,7 +74,7 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldShowAutoDebitRedirectPopup()
{
HomeNotificationHandler notificationHandler=new HomeNotificationHandler(KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_NOT_STARTED,AUTO_DEBIT_ROUTE_STRING);
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.getAppropriateHomeNotice().getNoticeViewType());
@ -78,7 +84,7 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldNotShowAutoDebitRedirectPopupForEmptryRoute()
{
HomeNotificationHandler notificationHandler=new HomeNotificationHandler(KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_NOT_STARTED,AUTO_DEBIT_EMPTY_ROUTE_STRING);
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.getAppropriateHomeNotice().getNoticeViewType());
@ -87,7 +93,7 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldNotShowAutoDebitRedirectPopupForNullRoute()
{
HomeNotificationHandler notificationHandler=new HomeNotificationHandler(KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_NOT_STARTED,AUTO_DEBIT__NULL_ROUTE_STRING);
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.getAppropriateHomeNotice().getNoticeViewType());
@ -96,7 +102,7 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldShowKYCNotSubmittedPopUpForNotSubmittedStatus()
{
HomeNotificationHandler notificationHandler=new HomeNotificationHandler(KYC_NOT_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_COMPLETED,AUTO_DEBIT__NULL_ROUTE_STRING);
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.getAppropriateHomeNotice().getNoticeViewType());
@ -106,7 +112,7 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldNotShowKYCNotSubmittedPopUpForSubmittedStatus()
{
HomeNotificationHandler notificationHandler=new HomeNotificationHandler(KYC_SUBMITTED_FLAG,KYC_NOT_VERIFIED_FLAG,PENNY_TEST_NOT_STARTED,AUTO_DEBIT__NULL_ROUTE_STRING);
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.getAppropriateHomeNotice().getNoticeViewType());
}
@ -114,7 +120,7 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldShowKYCNotVerifiedPopUpForUnverifiedStatus()
{
HomeNotificationHandler notificationHandler=new HomeNotificationHandler(KYC_SUBMITTED_FLAG,KYC_NOT_VERIFIED_FLAG,PENNY_TEST_COMPLETED,AUTO_DEBIT__NULL_ROUTE_STRING);
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.getAppropriateHomeNotice().getNoticeViewType());
@ -123,7 +129,7 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldNotShowKYCNotVerifiedPopUpForVerifiedStatus()
{
HomeNotificationHandler notificationHandler=new HomeNotificationHandler(KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_NOT_STARTED,AUTO_DEBIT__NULL_ROUTE_STRING);
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.getAppropriateHomeNotice().getNoticeViewType());
}
@ -132,7 +138,16 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldShowPennyTestNotCompletedPopupForNotStartedStatus()
{
HomeNotificationHandler notificationHandler=new HomeNotificationHandler(KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_NOT_STARTED,AUTO_DEBIT_EMPTY_ROUTE_STRING);
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.getAppropriateHomeNotice().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);
assertEquals("Should have shown penny test popup",PENNY_TEST_REQUIRED,notificationHandler.getAppropriateHomeNotice().getNoticeViewType());
@ -142,7 +157,7 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldShowPennyTestNotCompletedPopupForOnlyRequestedStatus()
{
HomeNotificationHandler notificationHandler=new HomeNotificationHandler(KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_ONLY_REQUESTED,AUTO_DEBIT_EMPTY_ROUTE_STRING);
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.getAppropriateHomeNotice().getNoticeViewType());
@ -152,10 +167,15 @@ public class HomeNotificationHandlerTest {
@Test
public void shouldNotShowPennyTestPopupForCompletedStatus()
{
HomeNotificationHandler notificationHandler=new HomeNotificationHandler(KYC_SUBMITTED_FLAG,KYC_VERIFIED_FLAG,PENNY_TEST_COMPLETED,AUTO_DEBIT_EMPTY_ROUTE_STRING);
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.getAppropriateHomeNotice());
}
private void stubStringExtractor()
{
Mockito.when(dummyStringExtractor.getStringFromStringId(Mockito.any())).thenReturn("Dummy localized string");
}
}
Loading…
Cancel
Save