From 827ea017fea5ec91ffe0042ae1d323b61a8af18b Mon Sep 17 00:00:00 2001 From: dilpreet96 Date: Tue, 27 Jun 2017 00:52:00 +0530 Subject: [PATCH] feat: AccountsPresenter Test --- app/build.gradle | 16 +- .../FakeJsonName.java | 16 + .../FakeRemoteDataSource.java | 34 ++ .../TestDataFactory.java | 71 +++ .../selfserviceapp/AccountsPresenterTest.java | 145 +++++ .../mifos/selfserviceapp/ExampleUnitTest.java | 16 - .../util/RxSchedulersOverrideRule.java | 71 +++ app/src/test/resources/clientAccounts.json | 553 ++++++++++++++++++ .../test/resources/clientLoanAccounts.json | 201 +++++++ .../test/resources/clientSavingsAccounts.json | 243 ++++++++ .../test/resources/clientShareAccounts.json | 111 ++++ build.gradle | 3 + .../findbugs/android-exclude-filter.xml | 11 + 13 files changed, 1474 insertions(+), 17 deletions(-) create mode 100644 app/src/commonTest/java/org.mifos.selfserviceapp/FakeJsonName.java create mode 100644 app/src/commonTest/java/org.mifos.selfserviceapp/FakeRemoteDataSource.java create mode 100644 app/src/commonTest/java/org.mifos.selfserviceapp/TestDataFactory.java create mode 100644 app/src/test/java/org/mifos/selfserviceapp/AccountsPresenterTest.java delete mode 100644 app/src/test/java/org/mifos/selfserviceapp/ExampleUnitTest.java create mode 100644 app/src/test/java/org/mifos/selfserviceapp/util/RxSchedulersOverrideRule.java create mode 100644 app/src/test/resources/clientAccounts.json create mode 100644 app/src/test/resources/clientLoanAccounts.json create mode 100644 app/src/test/resources/clientSavingsAccounts.json create mode 100644 app/src/test/resources/clientShareAccounts.json diff --git a/app/build.gradle b/app/build.gradle index 345420beb..d33ccadce 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,6 +37,17 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + + sourceSets { + def commonTestDir = 'src/commonTest/java' + androidTest { + java.srcDir commonTestDir + } + test { + java.srcDir commonTestDir + } + } + compileOptions.incremental = false lintOptions { @@ -48,7 +59,6 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - testCompile 'junit:junit:4.12' apt "com.github.Raizlabs.DBFlow:dbflow-processor:$rootProject.dbflowVersion" compile "com.github.Raizlabs.DBFlow:dbflow-core:$rootProject.dbflowVersion" @@ -87,4 +97,8 @@ dependencies { } //Charts compile 'com.github.PhilJay:MPAndroidChart:v3.0.2' + + // Unit tests dependencies + testCompile "junit:junit:$rootProject.jUnitVersion" + testCompile "org.mockito:mockito-core:$rootProject.mockitoVersion" } diff --git a/app/src/commonTest/java/org.mifos.selfserviceapp/FakeJsonName.java b/app/src/commonTest/java/org.mifos.selfserviceapp/FakeJsonName.java new file mode 100644 index 000000000..c0a9abf1e --- /dev/null +++ b/app/src/commonTest/java/org.mifos.selfserviceapp/FakeJsonName.java @@ -0,0 +1,16 @@ +package org.mifos.selfserviceapp; + +/** + * Created by dilpreet on 26/6/17. + */ + +public class FakeJsonName { + + public static final String CLIENT_ACCOUNTS_JSON = "clientAccounts.json"; + + public static final String CLIENT_SAVINGS_ACCOUNT_JSON = "clientSavingsAccounts.json"; + + public static final String CLIENT_LOAN_ACCOUNT_JSON = "clientLoanAccounts.json"; + + public static final String CLIENT_SHARE_ACCOUNT_JSON = "clientShareAccounts.json"; +} diff --git a/app/src/commonTest/java/org.mifos.selfserviceapp/FakeRemoteDataSource.java b/app/src/commonTest/java/org.mifos.selfserviceapp/FakeRemoteDataSource.java new file mode 100644 index 000000000..f705594e0 --- /dev/null +++ b/app/src/commonTest/java/org.mifos.selfserviceapp/FakeRemoteDataSource.java @@ -0,0 +1,34 @@ +package org.mifos.selfserviceapp; + +import com.google.gson.reflect.TypeToken; + +import org.mifos.selfserviceapp.models.client.ClientAccounts; + +/** + * Created by dilpreet on 26/6/17. + */ + +public class FakeRemoteDataSource { + + private static TestDataFactory mTestDataFactory = new TestDataFactory(); + + public static ClientAccounts getClientAccounts() { + return mTestDataFactory.getListTypePojo(new TypeToken() { + }, FakeJsonName.CLIENT_ACCOUNTS_JSON); + } + + public static ClientAccounts getClientSavingsAccount() { + return mTestDataFactory.getObjectTypePojo(ClientAccounts.class, + FakeJsonName.CLIENT_SAVINGS_ACCOUNT_JSON); + } + + public static ClientAccounts getClientLoanAccount() { + return mTestDataFactory.getObjectTypePojo(ClientAccounts.class, + FakeJsonName.CLIENT_LOAN_ACCOUNT_JSON); + } + + public static ClientAccounts getClientShareAccount() { + return mTestDataFactory.getObjectTypePojo(ClientAccounts.class, + FakeJsonName.CLIENT_SHARE_ACCOUNT_JSON); + } +} diff --git a/app/src/commonTest/java/org.mifos.selfserviceapp/TestDataFactory.java b/app/src/commonTest/java/org.mifos.selfserviceapp/TestDataFactory.java new file mode 100644 index 000000000..5384f83f2 --- /dev/null +++ b/app/src/commonTest/java/org.mifos.selfserviceapp/TestDataFactory.java @@ -0,0 +1,71 @@ +package org.mifos.selfserviceapp; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; + +import java.io.InputStream; +import java.io.InputStreamReader; + +/** + * Created by dilpreet on 26/6/17. + */ + +public class TestDataFactory { + + + /** + * Note : This Generic Method DeSerialize Only Json Object in POJO + *

+ * Note : Do Not use Array [] in POJO classes for of any element initialization, + * Use Instead ArrayList. + * + * @param model Class of the Model of the Pojo + * @param jsonName Name of Json file in test/resource + * @param Return type + * @return Return the Object Type model by Deserializing the Json of resources + * @Example Of Deserializing Object Type Json + *

+ * Object object = mTestDataFactory.getListTypePojo( + * new TypeToken(){}, "Object.json") + */ + public T getObjectTypePojo(Class model, String jsonName) { + + InputStream in = getClass().getClassLoader().getResourceAsStream(jsonName); + JsonReader reader = new JsonReader(new InputStreamReader(in)); + T jsonModel = new Gson().fromJson(reader, model); + return jsonModel; + + } + + + /** + * Note : This Generic Method DeSerialize Both Object and List Type Json in POJO + *

+ * Note : Do Not use Array [] in POJO classes for of any element initialization, + * Use Instead ArrayList. + * + * @param listModel Class of the List Model + * @param jsonName Name of the Json in resources + * @param return type + * @return Return the List of the listModel by Deserializing the Json of resources + * @Example of Deserializing List Type Json + *

+ * TestDataFactory mTestDataFactory = new TestDataFactory(); + *

+ * List listObject = mTestDataFactory.getListTypePojo( + * new TypeToken>(){}, "ListObject.json") + * @Example Of Deserializing Object Type Json + *

+ * Object object = mTestDataFactory.getListTypePojo( + * new TypeToken(){}, "Object.json") + */ + public T getListTypePojo(TypeToken listModel, String jsonName) { + + InputStream in = getClass().getClassLoader().getResourceAsStream(jsonName); + JsonReader reader = new JsonReader(new InputStreamReader(in)); + T listJsonModel = new Gson().fromJson(reader, listModel.getType()); + return listJsonModel; + + } +} diff --git a/app/src/test/java/org/mifos/selfserviceapp/AccountsPresenterTest.java b/app/src/test/java/org/mifos/selfserviceapp/AccountsPresenterTest.java new file mode 100644 index 000000000..34a988bef --- /dev/null +++ b/app/src/test/java/org/mifos/selfserviceapp/AccountsPresenterTest.java @@ -0,0 +1,145 @@ +package org.mifos.selfserviceapp; + +import android.content.Context; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mifos.selfserviceapp.api.DataManager; +import org.mifos.selfserviceapp.models.client.ClientAccounts; +import org.mifos.selfserviceapp.presenters.AccountsPresenter; +import org.mifos.selfserviceapp.ui.views.AccountsView; +import org.mifos.selfserviceapp.util.RxSchedulersOverrideRule; +import org.mifos.selfserviceapp.utils.Constants; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import rx.Observable; + +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * Created by dilpreet on 26/6/17. + */ +@RunWith(MockitoJUnitRunner.class) +public class AccountsPresenterTest { + + @Rule + public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule(); + + @Mock + Context context; + + @Mock + DataManager dataManager; + + @Mock + AccountsView accountsView; + + private AccountsPresenter presenter; + private ClientAccounts accounts, savingsAccount, loanAccounts, shareAccounts; + + @Before + public void setUp() throws Exception { + presenter = new AccountsPresenter(context, dataManager); + presenter.attachView(accountsView); + + accounts = FakeRemoteDataSource.getClientAccounts(); + savingsAccount = FakeRemoteDataSource.getClientSavingsAccount(); + loanAccounts = FakeRemoteDataSource.getClientLoanAccount(); + shareAccounts = FakeRemoteDataSource.getClientShareAccount(); + + when(context.getString(R.string.error_fetching_accounts)). + thenReturn("Failed to fetch Accounts"); + } + + @After + public void tearDown() throws Exception { + presenter.detachView(); + } + + @Test + public void testLoadClientAccounts() { + when(dataManager.getClientAccounts()).thenReturn(Observable.just(accounts)); + + presenter.loadClientAccounts(); + + verify(accountsView).showProgress(); + verify(accountsView).hideProgress(); + verify(accountsView).showSavingsAccounts(accounts.getSavingsAccounts()); + verify(accountsView).showLoanAccounts(accounts.getLoanAccounts()); + verify(accountsView).showShareAccounts(accounts.getShareAccounts()); + verify(accountsView, never()).showError(context.getString(R.string. + error_fetching_accounts)); + + } + + @Test + public void testLoadClientAccountsFail() { + when(dataManager.getClientAccounts()).thenReturn(Observable.error(new + RuntimeException())); + presenter.loadClientAccounts(); + + verify(accountsView).showProgress(); + verify(accountsView).hideProgress(); + verify(accountsView).showError(context.getString(R.string. + error_fetching_accounts)); + + } + + @Test + public void testLoadClientSavingsAccount() { + when(dataManager.getAccounts(Constants.SAVINGS_ACCOUNTS)). + thenReturn(Observable.just(savingsAccount)); + + presenter.loadAccounts(Constants.SAVINGS_ACCOUNTS); + + verify(accountsView).showProgress(); + verify(accountsView).hideProgress(); + verify(accountsView).showSavingsAccounts(savingsAccount.getSavingsAccounts()); + verify(accountsView, never()).showLoanAccounts(null); + verify(accountsView, never()).showShareAccounts(null); + verify(accountsView, never()).showError(context.getString(R.string. + error_fetching_accounts)); + + } + + @Test + public void testLoadClientLoanAccount() { + when(dataManager.getAccounts(Constants.LOAN_ACCOUNTS)). + thenReturn(Observable.just(loanAccounts)); + + presenter.loadAccounts(Constants.LOAN_ACCOUNTS); + + verify(accountsView).showProgress(); + verify(accountsView).hideProgress(); + verify(accountsView).showLoanAccounts(loanAccounts.getLoanAccounts()); + verify(accountsView, never()).showSavingsAccounts(null); + verify(accountsView, never()).showShareAccounts(null); + verify(accountsView, never()).showError(context.getString(R.string. + error_fetching_accounts)); + + } + + @Test + public void testLoadClientShareAccount() { + when(dataManager.getAccounts(Constants.SHARE_ACCOUNTS)). + thenReturn(Observable.just(shareAccounts)); + + presenter.loadAccounts(Constants.SHARE_ACCOUNTS); + + verify(accountsView).showProgress(); + verify(accountsView).hideProgress(); + verify(accountsView).showShareAccounts(shareAccounts.getShareAccounts()); + verify(accountsView, never()).showLoanAccounts(null); + verify(accountsView, never()).showSavingsAccounts(null); + verify(accountsView, never()).showError(context.getString(R.string. + error_fetching_accounts)); + + } + +} diff --git a/app/src/test/java/org/mifos/selfserviceapp/ExampleUnitTest.java b/app/src/test/java/org/mifos/selfserviceapp/ExampleUnitTest.java deleted file mode 100644 index 7adce9e4e..000000000 --- a/app/src/test/java/org/mifos/selfserviceapp/ExampleUnitTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.mifos.selfserviceapp; - -import static junit.framework.Assert.assertEquals; - -import org.junit.Test; - - -/** - * To work on unit tests, switch the Test Artifact in the Build Variants view. - */ -public class ExampleUnitTest { - @Test - public void additionIsCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/app/src/test/java/org/mifos/selfserviceapp/util/RxSchedulersOverrideRule.java b/app/src/test/java/org/mifos/selfserviceapp/util/RxSchedulersOverrideRule.java new file mode 100644 index 000000000..145719016 --- /dev/null +++ b/app/src/test/java/org/mifos/selfserviceapp/util/RxSchedulersOverrideRule.java @@ -0,0 +1,71 @@ +package org.mifos.selfserviceapp.util; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import rx.Scheduler; +import rx.android.plugins.RxAndroidPlugins; +import rx.android.plugins.RxAndroidSchedulersHook; +import rx.plugins.RxJavaPlugins; +import rx.plugins.RxJavaSchedulersHook; +import rx.schedulers.Schedulers; + +/** + * This rule registers SchedulerHooks for RxJava and RxAndroid to ensure that subscriptions + * always subscribeOn and observeOn Schedulers.immediate(). + * Warning, this rule will reset RxAndroidPlugins and RxJavaPlugins before and after each test so + * if the application code uses RxJava plugins this may affect the behaviour of the testing method. + */ +public class RxSchedulersOverrideRule implements TestRule { + + private final RxJavaSchedulersHook mRxJavaSchedulersHook = new RxJavaSchedulersHook() { + @Override + public Scheduler getIOScheduler() { + return Schedulers.immediate(); + } + + @Override + public Scheduler getNewThreadScheduler() { + return Schedulers.immediate(); + } + }; + + private final RxAndroidSchedulersHook mRxAndroidSchedulersHook = new RxAndroidSchedulersHook() { + @Override + public Scheduler getMainThreadScheduler() { + return Schedulers.immediate(); + } + }; + + // Hack to get around RxJavaPlugins.reset() not being public + // See https://github.com/ReactiveX/RxJava/issues/2297 + // Hopefully the method will be public in new releases of RxAndroid and we can remove the hack. + private void callResetViaReflectionIn(RxJavaPlugins rxJavaPlugins) + throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { + Method method = rxJavaPlugins.getClass().getDeclaredMethod("reset"); + method.setAccessible(true); + method.invoke(rxJavaPlugins); + } + + @Override + public Statement apply(final Statement base, Description description) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + RxAndroidPlugins.getInstance().reset(); + RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook); + callResetViaReflectionIn(RxJavaPlugins.getInstance()); + RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook); + + base.evaluate(); + + RxAndroidPlugins.getInstance().reset(); + callResetViaReflectionIn(RxJavaPlugins.getInstance()); + } + }; + } +} diff --git a/app/src/test/resources/clientAccounts.json b/app/src/test/resources/clientAccounts.json new file mode 100644 index 000000000..5b7c74b4d --- /dev/null +++ b/app/src/test/resources/clientAccounts.json @@ -0,0 +1,553 @@ +{ + "savingsAccounts": [ + { + "id": 21, + "accountNo": "000000021", + "externalId": "63723612", + "productId": 1, + "productName": "Voluntary savings", + "shortProductName": "VS", + "status": { + "id": 300, + "code": "savingsAccountStatusType.active", + "value": "Active", + "submittedAndPendingApproval": false, + "approved": false, + "rejected": false, + "withdrawnByApplicant": false, + "active": true, + "closed": false, + "prematureClosed": false, + "transferInProgress": false, + "transferOnHold": false, + "matured": false + }, + "currency": { + "code": "USD", + "name": "US Dollar", + "decimalPlaces": 2, + "inMultiplesOf": 0, + "displaySymbol": "$", + "nameCode": "currency.USD", + "displayLabel": "US Dollar ($)" + }, + "accountBalance": 118393.150000, + "accountType": { + "id": 1, + "code": "accountType.individual", + "value": "Individual" + }, + "timeline": { + "submittedOnDate": [ + 2016, + 10, + 3 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedOnDate": [ + 2016, + 10, + 3 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "activatedOnDate": [ + 2016, + 10, + 3 + ] + }, + "subStatus": { + "id": 0, + "code": "SavingsAccountSubStatusEnum.none", + "value": "None", + "none": true, + "inactive": false, + "dormant": false, + "escheat": false + }, + "lastActiveTransactionDate": [ + 2017, + 6, + 25 + ], + "depositType": { + "id": 100, + "code": "depositAccountType.savingsDeposit", + "value": "Savings" + } + }, + { + "id": 22, + "accountNo": "000000022", + "externalId": "8291847", + "productId": 1, + "productName": "Voluntary savings", + "shortProductName": "VS", + "status": { + "id": 300, + "code": "savingsAccountStatusType.active", + "value": "Active", + "submittedAndPendingApproval": false, + "approved": false, + "rejected": false, + "withdrawnByApplicant": false, + "active": true, + "closed": false, + "prematureClosed": false, + "transferInProgress": false, + "transferOnHold": false, + "matured": false + }, + "currency": { + "code": "USD", + "name": "US Dollar", + "decimalPlaces": 2, + "inMultiplesOf": 0, + "displaySymbol": "$", + "nameCode": "currency.USD", + "displayLabel": "US Dollar ($)" + }, + "accountBalance": 19930.520000, + "accountType": { + "id": 1, + "code": "accountType.individual", + "value": "Individual" + }, + "timeline": { + "submittedOnDate": [ + 2016, + 10, + 3 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedOnDate": [ + 2016, + 10, + 3 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "activatedOnDate": [ + 2016, + 10, + 3 + ] + }, + "subStatus": { + "id": 0, + "code": "SavingsAccountSubStatusEnum.none", + "value": "None", + "none": true, + "inactive": false, + "dormant": false, + "escheat": false + }, + "lastActiveTransactionDate": [ + 2017, + 6, + 25 + ], + "depositType": { + "id": 100, + "code": "depositAccountType.savingsDeposit", + "value": "Savings" + } + }, + { + "id": 23, + "accountNo": "000000023", + "externalId": "42414", + "productId": 1, + "productName": "Voluntary savings", + "shortProductName": "VS", + "status": { + "id": 300, + "code": "savingsAccountStatusType.active", + "value": "Active", + "submittedAndPendingApproval": false, + "approved": false, + "rejected": false, + "withdrawnByApplicant": false, + "active": true, + "closed": false, + "prematureClosed": false, + "transferInProgress": false, + "transferOnHold": false, + "matured": false + }, + "currency": { + "code": "USD", + "name": "US Dollar", + "decimalPlaces": 2, + "inMultiplesOf": 0, + "displaySymbol": "$", + "nameCode": "currency.USD", + "displayLabel": "US Dollar ($)" + }, + "accountBalance": 3117780552329.610000, + "accountType": { + "id": 1, + "code": "accountType.individual", + "value": "Individual" + }, + "timeline": { + "submittedOnDate": [ + 2016, + 10, + 3 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedOnDate": [ + 2016, + 10, + 3 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "activatedOnDate": [ + 2016, + 10, + 3 + ] + }, + "subStatus": { + "id": 0, + "code": "SavingsAccountSubStatusEnum.none", + "value": "None", + "none": true, + "inactive": false, + "dormant": false, + "escheat": false + }, + "lastActiveTransactionDate": [ + 2017, + 4, + 7 + ], + "depositType": { + "id": 100, + "code": "depositAccountType.savingsDeposit", + "value": "Savings" + } + } + ], + "loanAccounts": [{ + "id": 27, + "accountNo": "000000027", + "externalId": "34478914", + "productId": 2, + "productName": "For Prepay - Calculate till preclosure date", + "shortProductName": "CTPC", + "status": { + "id": 700, + "code": "loanStatusType.overpaid", + "value": "Overpaid", + "pendingApproval": false, + "waitingForDisbursal": false, + "active": false, + "closedObligationsMet": false, + "closedWrittenOff": false, + "closedRescheduled": false, + "closed": false, + "overpaid": true + }, + "loanType": { + "id": 1, + "code": "accountType.individual", + "value": "Individual" + }, + "loanCycle": 1, + "timeline": { + "submittedOnDate": [ + 2016, + 10, + 3 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedOnDate": [ + 2016, + 11, + 6 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "expectedDisbursementDate": [ + 2017, + 9, + 7 + ], + "actualDisbursementDate": [ + 2016, + 11, + 23 + ], + "disbursedByUsername": "mifos", + "disbursedByFirstname": "App", + "disbursedByLastname": "Administrator", + "expectedMaturityDate": [ + 2017, + 1, + 9 + ] + }, + "inArrears": false, + "originalLoan": 10000.000000, + "amountPaid": 10125.810000 + }, + { + "id": 28, + "accountNo": "000000028", + "productId": 4, + "productName": "BGS Prepay Loan", + "shortProductName": "BPL", + "status": { + "id": 700, + "code": "loanStatusType.overpaid", + "value": "Overpaid", + "pendingApproval": false, + "waitingForDisbursal": false, + "active": false, + "closedObligationsMet": false, + "closedWrittenOff": false, + "closedRescheduled": false, + "closed": false, + "overpaid": true + }, + "loanType": { + "id": 1, + "code": "accountType.individual", + "value": "Individual" + }, + "loanCycle": 1, + "timeline": { + "submittedOnDate": [ + 2016, + 10, + 3 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedOnDate": [ + 2016, + 10, + 3 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "expectedDisbursementDate": [ + 2017, + 11, + 3 + ], + "actualDisbursementDate": [ + 2016, + 10, + 3 + ], + "disbursedByUsername": "mifos", + "disbursedByFirstname": "App", + "disbursedByLastname": "Administrator", + "expectedMaturityDate": [ + 2016, + 11, + 3 + ] + }, + "inArrears": false, + "originalLoan": 2000.000000, + "amountPaid": 3180.000000 + }, + { + "id": 29, + "accountNo": "000000029", + "externalId": "342342", + "productId": 3, + "productName": "For Preclose- Calculate till rest frequency date", + "shortProductName": "CTRF", + "status": { + "id": 300, + "code": "loanStatusType.active", + "value": "Active", + "pendingApproval": false, + "waitingForDisbursal": false, + "active": true, + "closedObligationsMet": false, + "closedWrittenOff": false, + "closedRescheduled": false, + "closed": false, + "overpaid": false + }, + "loanType": { + "id": 1, + "code": "accountType.individual", + "value": "Individual" + }, + "loanCycle": 1, + "timeline": { + "submittedOnDate": [ + 2016, + 10, + 3 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedOnDate": [ + 2016, + 10, + 3 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "expectedDisbursementDate": [ + 2016, + 10, + 3 + ], + "actualDisbursementDate": [ + 2016, + 10, + 3 + ], + "disbursedByUsername": "mifos", + "disbursedByFirstname": "App", + "disbursedByLastname": "Administrator", + "expectedMaturityDate": [ + 2017, + 10, + 3 + ] + }, + "inArrears": false, + "originalLoan": 10000.000000, + "loanBalance": 6331.460000, + "amountPaid": 4478.450000 + } + ], + "shareAccounts": [ + { + "id": 14, + "accountNo": "000000014", + "totalApprovedShares": 10, + "totalPendingForApprovalShares": 0, + "productId": 2, + "productName": "SPTest", + "shortProductName": "SPT", + "status": { + "id": 300, + "code": "shareAccountStatusType.active", + "value": "Active", + "submittedAndPendingApproval": false, + "approved": false, + "rejected": false, + "active": true, + "closed": false + }, + "currency": { + "code": "USD", + "name": "US Dollar", + "decimalPlaces": 2, + "inMultiplesOf": 1, + "displaySymbol": "$", + "nameCode": "currency.USD", + "displayLabel": "US Dollar ($)" + }, + "timeline": { + "submittedOnDate": [ + 2016, + 11, + 4 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedDate": [ + 2016, + 11, + 4 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "activatedDate": [ + 2016, + 11, + 4 + ], + "activatedByUsername": "mifos", + "activatedByFirstname": "App", + "activatedByLastname": "Administrator" + } + }, + { + "id": 15, + "accountNo": "000000015", + "totalApprovedShares": 10, + "totalPendingForApprovalShares": 0, + "productId": 2, + "productName": "SPTest", + "shortProductName": "SPT", + "status": { + "id": 300, + "code": "shareAccountStatusType.active", + "value": "Active", + "submittedAndPendingApproval": false, + "approved": false, + "rejected": false, + "active": true, + "closed": false + }, + "currency": { + "code": "USD", + "name": "US Dollar", + "decimalPlaces": 2, + "inMultiplesOf": 1, + "displaySymbol": "$", + "nameCode": "currency.USD", + "displayLabel": "US Dollar ($)" + }, + "timeline": { + "submittedOnDate": [ + 2016, + 11, + 4 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedDate": [ + 2016, + 11, + 4 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "activatedDate": [ + 2016, + 11, + 4 + ], + "activatedByUsername": "mifos", + "activatedByFirstname": "App", + "activatedByLastname": "Administrator" + } + } + ] +} diff --git a/app/src/test/resources/clientLoanAccounts.json b/app/src/test/resources/clientLoanAccounts.json new file mode 100644 index 000000000..2969962ea --- /dev/null +++ b/app/src/test/resources/clientLoanAccounts.json @@ -0,0 +1,201 @@ +{ + "loanAccounts": [ + { + "id": 27, + "accountNo": "000000027", + "externalId": "34478914", + "productId": 2, + "productName": "For Prepay - Calculate till preclosure date", + "shortProductName": "CTPC", + "status": { + "id": 700, + "code": "loanStatusType.overpaid", + "value": "Overpaid", + "pendingApproval": false, + "waitingForDisbursal": false, + "active": false, + "closedObligationsMet": false, + "closedWrittenOff": false, + "closedRescheduled": false, + "closed": false, + "overpaid": true + }, + "loanType": { + "id": 1, + "code": "accountType.individual", + "value": "Individual" + }, + "loanCycle": 1, + "timeline": { + "submittedOnDate": [ + 2016, + 10, + 3 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedOnDate": [ + 2016, + 11, + 6 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "expectedDisbursementDate": [ + 2017, + 9, + 7 + ], + "actualDisbursementDate": [ + 2016, + 11, + 23 + ], + "disbursedByUsername": "mifos", + "disbursedByFirstname": "App", + "disbursedByLastname": "Administrator", + "expectedMaturityDate": [ + 2017, + 1, + 9 + ] + }, + "inArrears": false, + "originalLoan": 10000.000000, + "amountPaid": 10125.810000 + }, + { + "id": 28, + "accountNo": "000000028", + "productId": 4, + "productName": "BGS Prepay Loan", + "shortProductName": "BPL", + "status": { + "id": 700, + "code": "loanStatusType.overpaid", + "value": "Overpaid", + "pendingApproval": false, + "waitingForDisbursal": false, + "active": false, + "closedObligationsMet": false, + "closedWrittenOff": false, + "closedRescheduled": false, + "closed": false, + "overpaid": true + }, + "loanType": { + "id": 1, + "code": "accountType.individual", + "value": "Individual" + }, + "loanCycle": 1, + "timeline": { + "submittedOnDate": [ + 2016, + 10, + 3 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedOnDate": [ + 2016, + 10, + 3 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "expectedDisbursementDate": [ + 2017, + 11, + 3 + ], + "actualDisbursementDate": [ + 2016, + 10, + 3 + ], + "disbursedByUsername": "mifos", + "disbursedByFirstname": "App", + "disbursedByLastname": "Administrator", + "expectedMaturityDate": [ + 2016, + 11, + 3 + ] + }, + "inArrears": false, + "originalLoan": 2000.000000, + "amountPaid": 3180.000000 + }, + { + "id": 29, + "accountNo": "000000029", + "externalId": "342342", + "productId": 3, + "productName": "For Preclose- Calculate till rest frequency date", + "shortProductName": "CTRF", + "status": { + "id": 300, + "code": "loanStatusType.active", + "value": "Active", + "pendingApproval": false, + "waitingForDisbursal": false, + "active": true, + "closedObligationsMet": false, + "closedWrittenOff": false, + "closedRescheduled": false, + "closed": false, + "overpaid": false + }, + "loanType": { + "id": 1, + "code": "accountType.individual", + "value": "Individual" + }, + "loanCycle": 1, + "timeline": { + "submittedOnDate": [ + 2016, + 10, + 3 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedOnDate": [ + 2016, + 10, + 3 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "expectedDisbursementDate": [ + 2016, + 10, + 3 + ], + "actualDisbursementDate": [ + 2016, + 10, + 3 + ], + "disbursedByUsername": "mifos", + "disbursedByFirstname": "App", + "disbursedByLastname": "Administrator", + "expectedMaturityDate": [ + 2017, + 10, + 3 + ] + }, + "inArrears": false, + "originalLoan": 10000.000000, + "loanBalance": 6331.460000, + "amountPaid": 4478.450000 + } +]} \ No newline at end of file diff --git a/app/src/test/resources/clientSavingsAccounts.json b/app/src/test/resources/clientSavingsAccounts.json new file mode 100644 index 000000000..392dc2262 --- /dev/null +++ b/app/src/test/resources/clientSavingsAccounts.json @@ -0,0 +1,243 @@ +{ + "savingsAccounts": [{ + "id": 21, + "accountNo": "000000021", + "externalId": "63723612", + "productId": 1, + "productName": "Voluntary savings", + "shortProductName": "VS", + "status": { + "id": 300, + "code": "savingsAccountStatusType.active", + "value": "Active", + "submittedAndPendingApproval": false, + "approved": false, + "rejected": false, + "withdrawnByApplicant": false, + "active": true, + "closed": false, + "prematureClosed": false, + "transferInProgress": false, + "transferOnHold": false, + "matured": false + }, + "currency": { + "code": "USD", + "name": "US Dollar", + "decimalPlaces": 2, + "inMultiplesOf": 0, + "displaySymbol": "$", + "nameCode": "currency.USD", + "displayLabel": "US Dollar ($)" + }, + "accountBalance": 118393.150000, + "accountType": { + "id": 1, + "code": "accountType.individual", + "value": "Individual" + }, + "timeline": { + "submittedOnDate": [ + 2016, + 10, + 3 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedOnDate": [ + 2016, + 10, + 3 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "activatedOnDate": [ + 2016, + 10, + 3 + ] + }, + "subStatus": { + "id": 0, + "code": "SavingsAccountSubStatusEnum.none", + "value": "None", + "none": true, + "inactive": false, + "dormant": false, + "escheat": false + }, + "lastActiveTransactionDate": [ + 2017, + 6, + 25 + ], + "depositType": { + "id": 100, + "code": "depositAccountType.savingsDeposit", + "value": "Savings" + } + }, + { + "id": 22, + "accountNo": "000000022", + "externalId": "8291847", + "productId": 1, + "productName": "Voluntary savings", + "shortProductName": "VS", + "status": { + "id": 300, + "code": "savingsAccountStatusType.active", + "value": "Active", + "submittedAndPendingApproval": false, + "approved": false, + "rejected": false, + "withdrawnByApplicant": false, + "active": true, + "closed": false, + "prematureClosed": false, + "transferInProgress": false, + "transferOnHold": false, + "matured": false + }, + "currency": { + "code": "USD", + "name": "US Dollar", + "decimalPlaces": 2, + "inMultiplesOf": 0, + "displaySymbol": "$", + "nameCode": "currency.USD", + "displayLabel": "US Dollar ($)" + }, + "accountBalance": 19930.520000, + "accountType": { + "id": 1, + "code": "accountType.individual", + "value": "Individual" + }, + "timeline": { + "submittedOnDate": [ + 2016, + 10, + 3 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedOnDate": [ + 2016, + 10, + 3 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "activatedOnDate": [ + 2016, + 10, + 3 + ] + }, + "subStatus": { + "id": 0, + "code": "SavingsAccountSubStatusEnum.none", + "value": "None", + "none": true, + "inactive": false, + "dormant": false, + "escheat": false + }, + "lastActiveTransactionDate": [ + 2017, + 6, + 25 + ], + "depositType": { + "id": 100, + "code": "depositAccountType.savingsDeposit", + "value": "Savings" + } + }, + { + "id": 23, + "accountNo": "000000023", + "externalId": "42414", + "productId": 1, + "productName": "Voluntary savings", + "shortProductName": "VS", + "status": { + "id": 300, + "code": "savingsAccountStatusType.active", + "value": "Active", + "submittedAndPendingApproval": false, + "approved": false, + "rejected": false, + "withdrawnByApplicant": false, + "active": true, + "closed": false, + "prematureClosed": false, + "transferInProgress": false, + "transferOnHold": false, + "matured": false + }, + "currency": { + "code": "USD", + "name": "US Dollar", + "decimalPlaces": 2, + "inMultiplesOf": 0, + "displaySymbol": "$", + "nameCode": "currency.USD", + "displayLabel": "US Dollar ($)" + }, + "accountBalance": 3117780552329.610000, + "accountType": { + "id": 1, + "code": "accountType.individual", + "value": "Individual" + }, + "timeline": { + "submittedOnDate": [ + 2016, + 10, + 3 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedOnDate": [ + 2016, + 10, + 3 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "activatedOnDate": [ + 2016, + 10, + 3 + ] + }, + "subStatus": { + "id": 0, + "code": "SavingsAccountSubStatusEnum.none", + "value": "None", + "none": true, + "inactive": false, + "dormant": false, + "escheat": false + }, + "lastActiveTransactionDate": [ + 2017, + 4, + 7 + ], + "depositType": { + "id": 100, + "code": "depositAccountType.savingsDeposit", + "value": "Savings" + } + } + ] +} diff --git a/app/src/test/resources/clientShareAccounts.json b/app/src/test/resources/clientShareAccounts.json new file mode 100644 index 000000000..1dc425c4e --- /dev/null +++ b/app/src/test/resources/clientShareAccounts.json @@ -0,0 +1,111 @@ +{ + "shareAccounts": [ + { + "id": 14, + "accountNo": "000000014", + "totalApprovedShares": 10, + "totalPendingForApprovalShares": 0, + "productId": 2, + "productName": "SPTest", + "shortProductName": "SPT", + "status": { + "id": 300, + "code": "shareAccountStatusType.active", + "value": "Active", + "submittedAndPendingApproval": false, + "approved": false, + "rejected": false, + "active": true, + "closed": false + }, + "currency": { + "code": "USD", + "name": "US Dollar", + "decimalPlaces": 2, + "inMultiplesOf": 1, + "displaySymbol": "$", + "nameCode": "currency.USD", + "displayLabel": "US Dollar ($)" + }, + "timeline": { + "submittedOnDate": [ + 2016, + 11, + 4 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedDate": [ + 2016, + 11, + 4 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "activatedDate": [ + 2016, + 11, + 4 + ], + "activatedByUsername": "mifos", + "activatedByFirstname": "App", + "activatedByLastname": "Administrator" + } + }, + { + "id": 15, + "accountNo": "000000015", + "totalApprovedShares": 10, + "totalPendingForApprovalShares": 0, + "productId": 2, + "productName": "SPTest", + "shortProductName": "SPT", + "status": { + "id": 300, + "code": "shareAccountStatusType.active", + "value": "Active", + "submittedAndPendingApproval": false, + "approved": false, + "rejected": false, + "active": true, + "closed": false + }, + "currency": { + "code": "USD", + "name": "US Dollar", + "decimalPlaces": 2, + "inMultiplesOf": 1, + "displaySymbol": "$", + "nameCode": "currency.USD", + "displayLabel": "US Dollar ($)" + }, + "timeline": { + "submittedOnDate": [ + 2016, + 11, + 4 + ], + "submittedByUsername": "mifos", + "submittedByFirstname": "App", + "submittedByLastname": "Administrator", + "approvedDate": [ + 2016, + 11, + 4 + ], + "approvedByUsername": "mifos", + "approvedByFirstname": "App", + "approvedByLastname": "Administrator", + "activatedDate": [ + 2016, + 11, + 4 + ], + "activatedByUsername": "mifos", + "activatedByFirstname": "App", + "activatedByLastname": "Administrator" + } + } +]} \ No newline at end of file diff --git a/build.gradle b/build.gradle index f0f8f0a99..aa425b8ae 100644 --- a/build.gradle +++ b/build.gradle @@ -39,4 +39,7 @@ ext { butterKnifeVersion = '8.0.1' dbflowVersion = '3.1.1'; playServicesVersion = '10.0.1' + + jUnitVersion = '4.12' + mockitoVersion = '2.6.2' } diff --git a/config/quality/findbugs/android-exclude-filter.xml b/config/quality/findbugs/android-exclude-filter.xml index 7a799f5eb..41075a1d3 100755 --- a/config/quality/findbugs/android-exclude-filter.xml +++ b/config/quality/findbugs/android-exclude-filter.xml @@ -27,5 +27,16 @@ + + + + + + + + + + + \ No newline at end of file