From a4552641d35e47d945296d2bcc9f1bad7eaa6177 Mon Sep 17 00:00:00 2001 From: Aditya Gupta Date: Wed, 6 Sep 2023 01:47:43 +0530 Subject: [PATCH] Deleted presenters --- .../mifos/mifosxdroid/base/BasePresenter.kt | 31 -- .../com/mifos/mifosxdroid/base/MvpView.kt | 10 - .../com/mifos/mifosxdroid/base/Presenter.kt | 10 - .../SyncClientPayloadsMvpView.kt | 17 -- .../SyncClientPayloadsPresenter.kt | 116 -------- .../online/centerlist/CenterListMvpView.kt | 19 -- .../online/centerlist/CenterListPresenter.kt | 181 ------------ .../clientcharge/ClientChargeMvpView.kt | 14 - .../clientcharge/ClientChargePresenter.kt | 67 ----- .../online/clientlist/ClientListMvpView.kt | 17 -- .../online/clientlist/ClientListPresenter.kt | 190 ------------- .../documentlist/DocumentListMvpView.kt | 21 -- .../documentlist/DocumentListPresenter.kt | 94 ------- .../online/groupslist/GroupsListMvpView.kt | 17 -- .../online/groupslist/GroupsListPresenter.kt | 158 ----------- .../online/loancharge/LoanChargeMvpView.kt | 12 - .../online/loancharge/LoanChargePresenter.kt | 60 ---- .../online/search/SearchMvpView.kt | 14 - .../online/search/SearchPresenter.kt | 60 ---- .../SyncClientPayloadsPresenterTest.kt | 136 --------- .../online/CenterListPresenterTest.kt | 149 ---------- .../online/ClientChargePresenterTest.kt | 72 ----- .../online/ClientListPresenterTest.kt | 151 ---------- .../online/DocumentListPresenterTest.kt | 88 ------ .../online/GroupsListPresenterTest.kt | 145 ---------- .../online/LoanChargePresenterTest.kt | 73 ----- .../mifosxdroid/online/SearchPresenterTest.kt | 265 ------------------ .../viewmodels/ClientChargeViewModelTest.kt | 3 + .../viewmodels/LoanChargeViewModelTest.kt | 3 + .../mifos/viewmodels/LoginViewModelTest.kt | 3 + .../mifos/viewmodels/SearchViewModelTest.kt | 3 + 31 files changed, 12 insertions(+), 2187 deletions(-) delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/base/BasePresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/base/MvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/base/Presenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncclientpayloads/SyncClientPayloadsMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncclientpayloads/SyncClientPayloadsPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargePresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/documentlist/DocumentListMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/documentlist/DocumentListPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListPresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargeMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargePresenter.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/search/SearchMvpView.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/search/SearchPresenter.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/mifosxdroid/offline/syncclientpayloads/SyncClientPayloadsPresenterTest.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/mifosxdroid/online/CenterListPresenterTest.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/mifosxdroid/online/ClientChargePresenterTest.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/mifosxdroid/online/ClientListPresenterTest.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/mifosxdroid/online/DocumentListPresenterTest.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/mifosxdroid/online/GroupsListPresenterTest.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/mifosxdroid/online/LoanChargePresenterTest.kt delete mode 100644 mifosng-android/src/test/java/com/mifos/mifosxdroid/online/SearchPresenterTest.kt diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/base/BasePresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/base/BasePresenter.kt deleted file mode 100644 index 66f482c2ec4..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/base/BasePresenter.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.mifos.mifosxdroid.base - -/** - * Base class that implements the Presenter interface and provides a base implementation for - * attachView() and detachView(). It also handles keeping a reference to the mvpView that - * can be accessed from the children classes by calling getMvpView(). - */ -open class BasePresenter : Presenter { - var mvpView: T? = null - private set - - override fun attachView(mvpView: T) { - this.mvpView = mvpView - } - - override fun detachView() { - mvpView = null - } - - private val isViewAttached: Boolean - get() = mvpView != null - - fun checkViewAttached() { - if (!isViewAttached) throw MvpViewNotAttachedException() - } - - class MvpViewNotAttachedException : RuntimeException( - "Please call Presenter.attachView(MvpView) before" + - " requesting data to the Presenter" - ) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/base/MvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/base/MvpView.kt deleted file mode 100644 index dee6644cefa..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/base/MvpView.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.mifos.mifosxdroid.base - -/** - * Base interface that any class that wants to act as a View in the MVP (Model View Presenter) - * pattern must implement. Generally this interface will be extended by a more specific interface - * that then usually will be implemented by an Activity or Fragment. - */ -interface MvpView { - fun showProgressbar(b: Boolean) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/base/Presenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/base/Presenter.kt deleted file mode 100644 index e02a99649eb..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/base/Presenter.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.mifos.mifosxdroid.base - -/** - * Every presenter in the app must either implement this interface or extend BasePresenter - * indicating the MvpView type that wants to be attached with. - */ -interface Presenter { - fun attachView(mvpView: V) - fun detachView() -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncclientpayloads/SyncClientPayloadsMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncclientpayloads/SyncClientPayloadsMvpView.kt deleted file mode 100644 index ba8dd8607ba..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncclientpayloads/SyncClientPayloadsMvpView.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.mifos.mifosxdroid.offline.syncclientpayloads - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.client.ClientPayload - -/** - * Created by Rajan Maurya on 08/07/16. - */ -interface SyncClientPayloadsMvpView : MvpView { - fun showPayloads(clientPayload: List) - fun showError(stringId: Int) - fun showSyncResponse() - fun showClientSyncFailed(errorMessage: String) - fun showOfflineModeDialog() - fun showClientPayloadUpdated(clientPayload: ClientPayload) - fun showPayloadDeletedAndUpdatePayloads(clientPayloads: List) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncclientpayloads/SyncClientPayloadsPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncclientpayloads/SyncClientPayloadsPresenter.kt deleted file mode 100644 index b042be024d8..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/offline/syncclientpayloads/SyncClientPayloadsPresenter.kt +++ /dev/null @@ -1,116 +0,0 @@ -package com.mifos.mifosxdroid.offline.syncclientpayloads - -import com.mifos.api.datamanager.DataManagerClient -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.client.Client -import com.mifos.objects.client.ClientPayload -import com.mifos.utils.MFErrorParser.errorMessage -import rx.Observer -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 08/07/16. - */ -class SyncClientPayloadsPresenter @Inject constructor(private val mDataManagerClient: DataManagerClient) : - BasePresenter() { - private val mSubscriptions: CompositeSubscription = CompositeSubscription() - - override fun attachView(mvpView: SyncClientPayloadsMvpView) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - mSubscriptions.unsubscribe() - } - - fun loadDatabaseClientPayload() { - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscriptions.add(mDataManagerClient.allDatabaseClientPayload - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - mvpView?.showError(R.string.failed_to_load_clientpayload) - } - - override fun onNext(clientPayloads: List) { - mvpView?.showProgressbar(false) - mvpView?.showPayloads(clientPayloads) - } - }) - ) - } - - fun syncClientPayload(clientPayload: ClientPayload?) { - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscriptions.add(mDataManagerClient.createClient(clientPayload!!) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Observer { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - mvpView?.showClientSyncFailed(errorMessage(e)!!) - } - - override fun onNext(client: Client) { - mvpView?.showProgressbar(false) - mvpView?.showSyncResponse() - } - }) - ) - } - - fun deleteAndUpdateClientPayload(id: Int, clientCreationTIme: Long) { - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscriptions.add(mDataManagerClient.deleteAndUpdatePayloads(id, clientCreationTIme) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Observer> { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - mvpView?.showError(R.string.failed_to_update_list) - } - - override fun onNext(clientPayloads: List) { - mvpView?.showProgressbar(false) - mvpView?.showPayloadDeletedAndUpdatePayloads(clientPayloads) - } - }) - ) - } - - fun updateClientPayload(clientPayload: ClientPayload?) { - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscriptions.add( - mDataManagerClient.updateClientPayload(clientPayload!!) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - mvpView?.showError(R.string.failed_to_update_list) - } - - override fun onNext(clientPayload: ClientPayload) { - mvpView?.showProgressbar(false) - mvpView?.showClientPayloadUpdated(clientPayload) - } - }) - ) - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListMvpView.kt deleted file mode 100644 index dd46bb116b3..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListMvpView.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.mifos.mifosxdroid.online.centerlist - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.group.Center -import com.mifos.objects.group.CenterWithAssociations - -/** - * Created by Rajan Maurya on 5/6/16. - */ -interface CenterListMvpView : MvpView { - fun showUserInterface() - fun showCenters(centers: List
) - fun showMoreCenters(centers: List
) - fun showEmptyCenters(message: Int) - fun showMessage(message: Int) - fun unregisterSwipeAndScrollListener() - fun showCentersGroupAndMeeting(centerWithAssociations: CenterWithAssociations?, id: Int) - fun showFetchingError() -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListPresenter.kt deleted file mode 100644 index 6f0c146a4d9..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListPresenter.kt +++ /dev/null @@ -1,181 +0,0 @@ -package com.mifos.mifosxdroid.online.centerlist - -import com.mifos.api.datamanager.DataManagerCenter -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.client.Page -import com.mifos.objects.group.Center -import com.mifos.objects.group.CenterWithAssociations -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 5/6/16. - */ -class CenterListPresenter @Inject constructor(private val mDataManagerCenter: DataManagerCenter) : - BasePresenter() { - private val mSubscriptions: CompositeSubscription = CompositeSubscription() - private var mDbCenterList: List
- private var mSyncCenterList: List
- private val limit = 100 - private var loadmore = false - private var mRestApiCenterSyncStatus = false - private var mDatabaseCenterSyncStatus = false - - override fun detachView() { - super.detachView() - mSubscriptions.unsubscribe() - } - - /** - * This Method for loading the first 100 centers. - * - * @param loadmore - * @param offset - */ - fun loadCenters(loadmore: Boolean, offset: Int) { - this.loadmore = loadmore - loadCenters(true, offset, limit) - } - - /** - * This Method For showing Center List in UI. - * - * @param centers - */ - fun showCenters(centers: List
) { - if (loadmore) { - mvpView?.showMoreCenters(centers) - } else { - mvpView?.showCenters(centers) - } - } - - /** - * Setting CenterSync Status True when mRestApiCenterSyncStatus && mDatabaseCenterSyncStatus - * are true. - */ - fun setAlreadyCenterSyncStatus() { - if (mRestApiCenterSyncStatus && mDatabaseCenterSyncStatus) { - showCenters(checkCenterAlreadySyncedOrNot(mSyncCenterList)) - } - } - - /** - * @param paged True Enabling the Pagination of the API - * @param offset Value given from which position Center List will be fetched. - * @param limit Number of Centers to fetch. - */ - private fun loadCenters(paged: Boolean, offset: Int, limit: Int) { - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscriptions.add(mDataManagerCenter.getCenters(paged, offset, limit) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - if (loadmore) { - mvpView?.showMessage(R.string.failed_to_fetch_centers) - } else { - mvpView?.showFetchingError() - } - } - - override fun onNext(centerPage: Page
) { - mSyncCenterList = centerPage.pageItems - if (mSyncCenterList.isEmpty() && !loadmore) { - mvpView?.showEmptyCenters(R.string.center) - mvpView?.unregisterSwipeAndScrollListener() - } else if (mSyncCenterList.isEmpty() && loadmore) { - mvpView?.showMessage(R.string.no_more_centers_available) - } else { - showCenters(mSyncCenterList) - mRestApiCenterSyncStatus = true - setAlreadyCenterSyncStatus() - } - mvpView?.showProgressbar(false) - } - }) - ) - } - - fun loadCentersGroupAndMeeting(id: Int) { - mvpView?.showProgressbar(true) - mSubscriptions.add(mDataManagerCenter.getCentersGroupAndMeeting(id) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - mvpView?.showMessage(R.string.failed_to_fetch_Group_and_meeting) - } - - override fun onNext(centerWithAssociations: CenterWithAssociations?) { - mvpView?.showProgressbar(false) - mvpView?.showCentersGroupAndMeeting(centerWithAssociations, id) - } - }) - ) - } - - /** - * This Method Loading the Center From Database. It request Observable to DataManagerCenter - * and DataManagerCenter Request to DatabaseHelperCenter to load the Center List Page from the - * Center_Table and As the Center List Page is loaded DataManagerCenter gives the Center List - * Page after getting response from DatabaseHelperCenter - */ - fun loadDatabaseCenters() { - checkViewAttached() - mSubscriptions.add( - mDataManagerCenter.allDatabaseCenters - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showMessage(R.string.failed_to_load_db_centers) - } - - override fun onNext(centerPage: Page
) { - mDatabaseCenterSyncStatus = true - if (centerPage != null) { - mDbCenterList = centerPage.pageItems - } - setAlreadyCenterSyncStatus() - } - }) - ) - } - - /** - * This Method Filtering the Centers Loaded from Server is already sync or not. If yes the - * put the center.setSync(true) and view will show those centers as sync already to user - * - * @param - * @return Page
-
*/ - private fun checkCenterAlreadySyncedOrNot(centers: List
): List
{ - if (mDbCenterList.isNotEmpty()) { - for (dbCenter in mDbCenterList) { - for (syncCenter in centers) { - if (dbCenter.id == syncCenter.id) { - syncCenter.sync = true - break - } - } - } - } - return centers - } - - init { - mDbCenterList = ArrayList() - mSyncCenterList = ArrayList() - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeMvpView.kt deleted file mode 100644 index 96194e94776..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargeMvpView.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.mifos.mifosxdroid.online.clientcharge - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.client.Charges -import com.mifos.objects.client.Page - -/** - * Created by Rajan Maurya on 5/6/16. - */ -interface ClientChargeMvpView : MvpView { - fun showChargesList(chargesPage: Page) - fun showFetchingErrorCharges(s: String) - fun showEmptyCharges() -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargePresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargePresenter.kt deleted file mode 100644 index de6293101b5..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientcharge/ClientChargePresenter.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.mifos.mifosxdroid.online.clientcharge - -import com.mifos.api.datamanager.DataManagerCharge -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.client.Charges -import com.mifos.objects.client.Page -import com.mifos.utils.MFErrorParser -import retrofit2.HttpException -import rx.Subscriber -import rx.Subscription -import rx.android.schedulers.AndroidSchedulers -import rx.plugins.RxJavaPlugins -import rx.schedulers.Schedulers -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 5/6/16. - */ -class ClientChargePresenter @Inject constructor(private val mDataManagerCharge: DataManagerCharge) : BasePresenter() { - private var mSubscription: Subscription? = null - override fun attachView(mvpView: ClientChargeMvpView) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - if (mSubscription != null) mSubscription?.unsubscribe() - } - - fun loadCharges(clientId: Int, offset: Int, limit: Int) { - mvpView?.showProgressbar(true) - if (mSubscription != null) mSubscription?.unsubscribe() - mSubscription = mDataManagerCharge.getClientCharges(clientId, offset, limit) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() { - mvpView?.showProgressbar(false) - } - - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - try { - if (e is HttpException) { - val errorMessage = e.response()?.errorBody() - ?.string() - mvpView?.showFetchingErrorCharges(MFErrorParser - .parseError(errorMessage) - .errors[0].defaultUserMessage) - } - } catch (throwable: Throwable) { - RxJavaPlugins.getInstance().errorHandler.handleError(e) - } - } - - override fun onNext(chargesPage: Page) { - mvpView?.showProgressbar(false) - if (chargesPage.pageItems.size > 0) { - mvpView?.showChargesList(chargesPage) - } else { - mvpView?.showEmptyCharges() - } - } - }) - } - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListMvpView.kt deleted file mode 100644 index e6765a3f30e..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListMvpView.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.mifos.mifosxdroid.online.clientlist - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.client.Client - -/** - * Created by Rajan Maurya on 6/6/16. - */ -interface ClientListMvpView : MvpView { - fun showUserInterface() - fun showClientList(clients: List) - fun showLoadMoreClients(clients: List?) - fun showEmptyClientList(message: Int) - fun unregisterSwipeAndScrollListener() - fun showMessage(message: Int) - fun showError() -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListPresenter.kt deleted file mode 100644 index 70a335096cc..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/clientlist/ClientListPresenter.kt +++ /dev/null @@ -1,190 +0,0 @@ -package com.mifos.mifosxdroid.online.clientlist - -import com.mifos.api.datamanager.DataManagerClient -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.client.Client -import com.mifos.objects.client.Page -import com.mifos.utils.EspressoIdlingResource -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import java.util.* -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 6/6/16. - * This Presenter Holds the All Logic to request to DataManagerClient and DataManagerClient, Take - * care of that From Where Data will come Database or REST API. - */ -class ClientListPresenter @Inject constructor(private val mDataManagerClient: DataManagerClient) : BasePresenter() { - private var mSubscriptions: CompositeSubscription? = null - private var mDbClientList: List - private var mSyncClientList: List - private val limit = 100 - private var loadmore = false - private var mRestApiClientSyncStatus = false - private var mDatabaseClientSyncStatus = false - override fun attachView(mvpView: ClientListMvpView?) { - super.attachView(mvpView) - mSubscriptions = CompositeSubscription() - } - - override fun detachView() { - super.detachView() - mSubscriptions?.unsubscribe() - } - - /** - * Loading Client List from Rest API and setting loadmore status - * - * @param loadmore Status, need ClientList page other then first. - * @param offset Index from Where ClientList will be fetched. - */ - fun loadClients(loadmore: Boolean, offset: Int) { - this.loadmore = loadmore - loadClients(true, offset, limit) - } - - /** - * Showing Client List in View, If loadmore is true call showLoadMoreClients(...) and else - * call showClientList(...). - */ - private fun showClientList(clients: List) { - if (loadmore) { - mvpView?.showLoadMoreClients(clients) - } else { - mvpView?.showClientList(clients) - } - } - - /** - * This Method will called, when Parent (Fragment or Activity) will be true. - * If Parent Fragment is true there is no need to fetch ClientList, Just show the Parent - * (Fragment or Activity) ClientList in View - * - * @param clients List> - */ - fun showParentClients(clients: List?) { - mvpView?.unregisterSwipeAndScrollListener() - if (clients != null) { - if (clients.isEmpty()) { - mvpView?.showEmptyClientList(R.string.client) - } else { - mRestApiClientSyncStatus = true - mSyncClientList = clients - setAlreadyClientSyncStatus() - } - } - } - - /** - * Setting ClientSync Status True when mRestApiClientSyncStatus && mDatabaseClientSyncStatus - * are true. - */ - fun setAlreadyClientSyncStatus() { - if (mRestApiClientSyncStatus && mDatabaseClientSyncStatus) { - showClientList(checkClientAlreadySyncedOrNot(mSyncClientList)) - } - } - - /** - * This Method fetching Client List from Rest API. - * - * @param paged True Enabling the Pagination of the API - * @param offset Value give from which position Fetch ClientList - * @param limit Maximum size of the Center - */ - private fun loadClients(paged: Boolean, offset: Int, limit: Int) { - EspressoIdlingResource.increment() // App is busy until further notice. - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscriptions?.add(mDataManagerClient.getAllClients(paged, offset, limit) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - if (loadmore) { - mvpView?.showMessage(R.string.failed_to_load_client) - } else { - mvpView?.showError() - } - EspressoIdlingResource.decrement() // App is idle. - } - - override fun onNext(clientPage: Page) { - mSyncClientList = clientPage.pageItems - if (mSyncClientList.isEmpty() && !loadmore) { - mvpView?.showEmptyClientList(R.string.client) - mvpView?.unregisterSwipeAndScrollListener() - } else if (mSyncClientList.isEmpty() && loadmore) { - mvpView?.showMessage(R.string.no_more_clients_available) - } else { - mRestApiClientSyncStatus = true - setAlreadyClientSyncStatus() - } - mvpView?.showProgressbar(false) - EspressoIdlingResource.decrement() // App is idle. - } - })) - } - - /** - * This Method Loading the Client From Database. It request Observable to DataManagerClient - * and DataManagerClient Request to DatabaseHelperClient to load the Client List Page from the - * Client_Table and As the Client List Page is loaded DataManagerClient gives the Client List - * Page after getting response from DatabaseHelperClient - */ - fun loadDatabaseClients() { - checkViewAttached() - mSubscriptions?.add(mDataManagerClient.allDatabaseClients - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showMessage(R.string.failed_to_load_db_clients) - } - - override fun onNext(clientPage: Page) { - mDatabaseClientSyncStatus = true - mDbClientList = clientPage.pageItems - setAlreadyClientSyncStatus() - } - }) - ) - } - - /** - * This Method Filtering the Clients Loaded from Server is already sync or not. If yes the - * put the client.setSync(true) and view will show those clients as sync already to user - * - * @param - * @return Page - */ - private fun checkClientAlreadySyncedOrNot(clients: List): List { - if (mDbClientList.isNotEmpty()) { - for (dbClient in mDbClientList) { - for (syncClient in clients) { - if (dbClient.id == syncClient.id) { - syncClient.sync = true - break - } - } - } - } - return clients - } - - companion object { - private val LOG_TAG = ClientListPresenter::class.java.simpleName - } - - init { - mDbClientList = ArrayList() - mSyncClientList = ArrayList() - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/documentlist/DocumentListMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/documentlist/DocumentListMvpView.kt deleted file mode 100644 index 65d4b207c19..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/documentlist/DocumentListMvpView.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.mifos.mifosxdroid.online.documentlist - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.noncore.Document -import okhttp3.ResponseBody - -/** - * Created by Rajan Maurya on 06/06/16. - */ -interface DocumentListMvpView : MvpView { - fun showDocumentList(documents: List) - fun showDocumentFetchSuccessfully(responseBody: ResponseBody?) - fun checkPermissionAndRequest() - fun requestPermission() - fun showDocumentActions(documentId: Int) - fun checkExternalStorageAndCreateDocument() - fun showDocumentRemovedSuccessfully() - fun showDocumentDialog(documentAction: String?) - fun showEmptyDocuments() - fun showFetchingError(errorMessage: Int) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/documentlist/DocumentListPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/documentlist/DocumentListPresenter.kt deleted file mode 100644 index 8455031c40d..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/documentlist/DocumentListPresenter.kt +++ /dev/null @@ -1,94 +0,0 @@ -package com.mifos.mifosxdroid.online.documentlist - -import com.mifos.api.GenericResponse -import com.mifos.api.datamanager.DataManagerDocument -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.noncore.Document -import okhttp3.ResponseBody -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 06/06/16. - */ -class DocumentListPresenter @Inject constructor(private val mDataManagerDocument: DataManagerDocument) : BasePresenter() { - private val mSubscriptions: CompositeSubscription - override fun attachView(mvpView: DocumentListMvpView?) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - mSubscriptions.clear() - } - - fun loadDocumentList(type: String?, id: Int) { - checkViewAttached() - mvpView!!.showProgressbar(true) - mSubscriptions.add(mDataManagerDocument.getDocumentsList(type, id) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber?>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showFetchingError(R.string.failed_to_fetch_documents) - } - - override fun onNext(documents: List?) { - mvpView!!.showProgressbar(false) - mvpView!!.showDocumentList(documents as List) - } - })) - } - - fun downloadDocument(entityType: String?, entityId: Int, documentId: Int) { - checkViewAttached() - mvpView!!.showProgressbar(true) - mSubscriptions.add(mDataManagerDocument.downloadDocument(entityType, entityId, documentId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showFetchingError(R.string.failed_to_fetch_documents) - } - - override fun onNext(responseBody: ResponseBody?) { - mvpView!!.showProgressbar(false) - mvpView!!.showDocumentFetchSuccessfully(responseBody) - } - }) - ) - } - - fun removeDocument(entityType: String?, entityId: Int, documentId: Int) { - checkViewAttached() - mvpView!!.showProgressbar(true) - mSubscriptions.add(mDataManagerDocument.removeDocument(entityType, entityId, documentId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - mvpView!!.showFetchingError(R.string.failed_to_remove_document) - } - - override fun onNext(genericResponse: GenericResponse?) { - mvpView!!.showProgressbar(false) - mvpView!!.showDocumentRemovedSuccessfully() - } - }) - ) - } - - init { - mSubscriptions = CompositeSubscription() - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListMvpView.kt deleted file mode 100644 index bd3fb07ef85..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListMvpView.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.mifos.mifosxdroid.online.groupslist - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.group.Group - -/** - * Created by Rajan Maurya on 7/6/16. - */ -interface GroupsListMvpView : MvpView { - fun showGroups(groups: List) - fun showUserInterface() - fun showLoadMoreGroups(clients: List) - fun showEmptyGroups(message: Int) - fun unregisterSwipeAndScrollListener() - fun showMessage(message: Int) - fun showFetchingError() -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListPresenter.kt deleted file mode 100644 index 88acd6ab669..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/groupslist/GroupsListPresenter.kt +++ /dev/null @@ -1,158 +0,0 @@ -package com.mifos.mifosxdroid.online.groupslist - -import com.mifos.api.datamanager.DataManagerGroups -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.client.Page -import com.mifos.objects.group.Group -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import rx.subscriptions.CompositeSubscription -import java.util.* -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 7/6/16. - */ -class GroupsListPresenter @Inject constructor(private val mDataManagerGroups: DataManagerGroups) : BasePresenter() { - private val mSubscriptions: CompositeSubscription = CompositeSubscription() - private var mDbGroupList: List - private var mSyncGroupList: List - private val limit = 100 - private var loadmore = false - private var mRestApiGroupSyncStatus = false - private var mDatabaseGroupSyncStatus = false - override fun attachView(mvpView: GroupsListMvpView) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - mSubscriptions.unsubscribe() - } - - fun loadGroups(loadmore: Boolean, offset: Int) { - this.loadmore = loadmore - loadGroups(true, offset, limit) - } - - /** - * Showing Groups List in View, If loadmore is true call showLoadMoreGroups(...) and else - * call showGroupsList(...). - */ - private fun showClientList(clients: List) { - if (loadmore) { - mvpView?.showLoadMoreGroups(clients) - } else { - mvpView?.showGroups(clients) - } - } - - /** - * This Method will called, when Parent (Fragment or Activity) will be true. - * If Parent Fragment is true then there is no need to fetch ClientList, Just show the Parent - * (Fragment or Activity)'s Groups in View - * - * @param groups List> - */ - fun showParentClients(groups: List) { - mvpView?.unregisterSwipeAndScrollListener() - if (groups.isEmpty()) { - mvpView?.showEmptyGroups(R.string.group) - } else { - mRestApiGroupSyncStatus = true - mSyncGroupList = groups - setAlreadyClientSyncStatus() - } - } - - /** - * Setting GroupSync Status True when mRestApiGroupSyncStatus && mDatabaseGroupSyncStatus - * are true. - */ - fun setAlreadyClientSyncStatus() { - if (mRestApiGroupSyncStatus && mDatabaseGroupSyncStatus) { - showClientList(checkGroupAlreadySyncedOrNot(mSyncGroupList)) - } - } - - private fun loadGroups(paged: Boolean, offset: Int, limit: Int) { - checkViewAttached() - mvpView?.showProgressbar(true) - mSubscriptions.add(mDataManagerGroups.getGroups(paged, offset, limit) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showProgressbar(false) - if (loadmore) { - mvpView?.showMessage(R.string.failed_to_fetch_groups) - } else { - mvpView?.showFetchingError() - } - } - - override fun onNext(groupPage: Page) { - mSyncGroupList = groupPage.pageItems - if (mSyncGroupList.isEmpty() && !loadmore) { - mvpView?.showEmptyGroups(R.string.group) - mvpView?.unregisterSwipeAndScrollListener() - } else if (mSyncGroupList.isEmpty() && loadmore) { - mvpView?.showMessage(R.string.no_more_groups_available) - } else { - mRestApiGroupSyncStatus = true - setAlreadyClientSyncStatus() - } - mvpView?.showProgressbar(false) - } - })) - } - - fun loadDatabaseGroups() { - checkViewAttached() - mSubscriptions.add(mDataManagerGroups.databaseGroups - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showMessage(R.string.failed_to_load_db_groups) - } - - override fun onNext(groupPage: Page) { - mDatabaseGroupSyncStatus = true - mDbGroupList = groupPage.pageItems - setAlreadyClientSyncStatus() - } - }) - ) - } - - /** - * This Method Filtering the Groups Loaded from Server, is already sync or not. If yes the - * put the client.setSync(true) and view will show to user that group already synced - * - * @param groups - * @return List - */ - private fun checkGroupAlreadySyncedOrNot(groups: List): List { - if (mDbGroupList.isNotEmpty()) { - for (dbGroup in mDbGroupList) { - for (syncGroup in groups) { - if (dbGroup.id?.toInt() == syncGroup.id?.toInt()) { - syncGroup.sync = true - break - } - } - } - } - return groups - } - - init { - mDbGroupList = ArrayList() - mSyncGroupList = ArrayList() - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargeMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargeMvpView.kt deleted file mode 100644 index 3869a8bf915..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargeMvpView.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.mifos.mifosxdroid.online.loancharge - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.client.Charges - -/** - * Created by Rajan Maurya on 07/06/16. - */ -interface LoanChargeMvpView : MvpView { - fun showLoanChargesList(charges: MutableList) - fun showFetchingError(s: String) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargePresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargePresenter.kt deleted file mode 100644 index f7289cf5e62..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/loancharge/LoanChargePresenter.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.mifos.mifosxdroid.online.loancharge - -import com.mifos.api.DataManager -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.client.Charges -import com.mifos.utils.MFErrorParser -import retrofit2.HttpException -import rx.Subscriber -import rx.Subscription -import rx.android.schedulers.AndroidSchedulers -import rx.plugins.RxJavaPlugins -import rx.schedulers.Schedulers -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 07/06/16. - */ -class LoanChargePresenter @Inject constructor(private val mDataManager: DataManager) : BasePresenter() { - private var mSubscription: Subscription? = null - override fun attachView(mvpView: LoanChargeMvpView?) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - if (mSubscription != null) mSubscription!!.unsubscribe() - } - - fun loadLoanChargesList(loanId: Int) { - checkViewAttached() - mvpView!!.showProgressbar(true) - if (mSubscription != null) mSubscription!!.unsubscribe() - mSubscription = mDataManager.getListOfLoanCharges(loanId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber?>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView!!.showProgressbar(false) - try { - if (e is HttpException) { - val errorMessage = e.response()?.errorBody() - ?.string() - mvpView!!.showFetchingError(MFErrorParser - .parseError(errorMessage) - .errors[0].defaultUserMessage) - } - } catch (throwable: Throwable) { - RxJavaPlugins.getInstance().errorHandler.handleError(e) - } - } - - override fun onNext(chargesPage: List?) { - mvpView!!.showProgressbar(false) - mvpView!!.showLoanChargesList(chargesPage as MutableList) - } - }) - } - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/search/SearchMvpView.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/search/SearchMvpView.kt deleted file mode 100644 index 5cdbed3f02c..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/search/SearchMvpView.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.mifos.mifosxdroid.online.search - -import com.mifos.mifosxdroid.base.MvpView -import com.mifos.objects.SearchedEntity - -/** - * Created by Rajan Maurya on 06/06/16. - */ -interface SearchMvpView : MvpView { - fun showUserInterface() - fun showSearchedResources(searchedEntities: List) - fun showNoResultFound() - fun showMessage(message: Int) -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/search/SearchPresenter.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/search/SearchPresenter.kt deleted file mode 100644 index 7f27f19623d..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/search/SearchPresenter.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.mifos.mifosxdroid.online.search - -import com.mifos.App -import com.mifos.api.datamanager.DataManagerSearch -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.base.BasePresenter -import com.mifos.objects.SearchedEntity -import com.mifos.utils.Network -import rx.Subscriber -import rx.Subscription -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import javax.inject.Inject - -/** - * Created by Rajan Maurya on 06/06/16. - */ -class SearchPresenter @Inject constructor(private val dataManagerSearch: DataManagerSearch) : - BasePresenter() { - private var mSubscription: Subscription? = null - override fun attachView(mvpView: SearchMvpView) { - super.attachView(mvpView) - } - - override fun detachView() { - super.detachView() - if (mSubscription != null) mSubscription?.unsubscribe() - } - - fun searchResources(query: String?, resources: String?, exactMatch: Boolean?) { - checkViewAttached() - val context = App.context - if (context != null && !Network.isOnline(context)) { - mvpView?.showProgressbar(false) - mvpView?.showMessage(R.string.no_internet_connection) - return - } - mvpView?.showProgressbar(true) - if (mSubscription != null) mSubscription?.unsubscribe() - mSubscription = dataManagerSearch.searchResources(query, resources, exactMatch) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - mvpView?.showMessage(R.string.failed_to_fetch_resources_of_query) - mvpView?.showProgressbar(false) - } - - override fun onNext(searchedEntities: List) { - mvpView?.showProgressbar(false) - if (searchedEntities.isEmpty()) { - mvpView?.showNoResultFound() - } else { - mvpView?.showSearchedResources(searchedEntities) - } - } - }) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/mifosxdroid/offline/syncclientpayloads/SyncClientPayloadsPresenterTest.kt b/mifosng-android/src/test/java/com/mifos/mifosxdroid/offline/syncclientpayloads/SyncClientPayloadsPresenterTest.kt deleted file mode 100644 index 33f8bfe1afd..00000000000 --- a/mifosng-android/src/test/java/com/mifos/mifosxdroid/offline/syncclientpayloads/SyncClientPayloadsPresenterTest.kt +++ /dev/null @@ -1,136 +0,0 @@ -package com.mifos.mifosxdroid.offline.syncclientpayloads - -import com.mifos.api.datamanager.DataManagerClient -import com.mifos.mifosxdroid.FakeRemoteDataSource -import com.mifos.mifosxdroid.FakeRemoteDataSource.failureServerResponse -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import com.mifos.objects.client.Client -import com.mifos.objects.client.ClientPayload -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by rajan on 11/07/16. - */ -@RunWith(MockitoJUnitRunner::class) -class SyncClientPayloadsPresenterTest { - @get:Rule - val mOverrideSchedulersRule = RxSchedulersOverrideRule() - private lateinit var syncClientPayloadsPresenter: SyncClientPayloadsPresenter - - @Mock - lateinit var mDataManagerClient: DataManagerClient - - @Mock - lateinit var mSyncClientPayloadsMvpView: SyncClientPayloadsMvpView - private lateinit var clientPayloads: List - private lateinit var errorSyncServerMessage: String - var clientCreationTime: Long = 0 - - @Before - fun setUp() { - syncClientPayloadsPresenter = SyncClientPayloadsPresenter(mDataManagerClient) - syncClientPayloadsPresenter.attachView(mSyncClientPayloadsMvpView) - clientPayloads = FakeRemoteDataSource.clientPayloads - errorSyncServerMessage = failureServerResponse.errors[0].defaultUserMessage - clientCreationTime = System.currentTimeMillis() - } - - @After - fun tearDown() { - syncClientPayloadsPresenter.detachView() - } - - @Test - fun testLoadDatabaseClientPayload() { - Mockito.`when`(mDataManagerClient.allDatabaseClientPayload) - .thenReturn( - Observable.just(clientPayloads) - ) - syncClientPayloadsPresenter.loadDatabaseClientPayload() - Mockito.verify(mSyncClientPayloadsMvpView)?.showPayloads( - clientPayloads - ) - Mockito.verify(mSyncClientPayloadsMvpView, Mockito.never()) - ?.showError(R.string.failed_to_load_clientpayload) - } - - @Test - fun testLoadDatabaseClientPayloadFails() { - Mockito.`when`(mDataManagerClient.allDatabaseClientPayload) - .thenReturn(Observable.error(RuntimeException())) - syncClientPayloadsPresenter.loadDatabaseClientPayload() - Mockito.verify(mSyncClientPayloadsMvpView)?.showError(R.string.failed_to_load_clientpayload) - Mockito.verify(mSyncClientPayloadsMvpView, Mockito.never())?.showPayloads( - clientPayloads - ) - } - - @Test - fun testSyncClientPayload() { - //Syncing the first Client Payload of FakeDataSource - Mockito.`when`( - mDataManagerClient.createClient( - clientPayloads[0] - ) - ).thenReturn(Observable.just(Client())) - syncClientPayloadsPresenter.syncClientPayload(clientPayloads[0]) - Mockito.verify(mSyncClientPayloadsMvpView)?.showSyncResponse() - Mockito.verify(mSyncClientPayloadsMvpView, Mockito.never()) - ?.showClientSyncFailed(errorSyncServerMessage) - } - - @Test - fun testSyncClientPayloadFails() { - Mockito.`when`( - mDataManagerClient.createClient( - clientPayloads[0] - ) - ) - .thenReturn(Observable.error(RuntimeException())) - syncClientPayloadsPresenter.syncClientPayload(clientPayloads[0]) - - //TODO Fix this test showClientSyncFailed, It is failing because this is calling a - //TODO Schedulers in Fragment View Class. - //verify(mSyncClientPayloadsMvpView).showClientSyncFailed(errorSyncServerMessage); - Mockito.verify(mSyncClientPayloadsMvpView, Mockito.never())?.showSyncResponse() - } - - @Test - @Throws(Exception::class) - fun testDeleteAndUpdateClientPayload() { - //Deleting the Client Payload of Id = 1, Id is transient. it will not serialize and - // deserialize during retrofit request. It is for just numbering the payload in Table. - Mockito.`when`>>( - mDataManagerClient.deleteAndUpdatePayloads( - 1, - clientCreationTime - ) - ) - .thenReturn(Observable.just(clientPayloads)) - syncClientPayloadsPresenter.deleteAndUpdateClientPayload(1, clientCreationTime) - Mockito.verify(mSyncClientPayloadsMvpView)?.showPayloadDeletedAndUpdatePayloads( - clientPayloads - ) - Mockito.verify(mSyncClientPayloadsMvpView, Mockito.never()) - ?.showError(R.string.failed_to_update_list) - } - - @Test - fun testDeleteAndUpdateClientPayloadFails() { - Mockito.`when`(mDataManagerClient.deleteAndUpdatePayloads(1, clientCreationTime)) - .thenReturn(Observable.error(RuntimeException())) - syncClientPayloadsPresenter.deleteAndUpdateClientPayload(1, clientCreationTime) - Mockito.verify(mSyncClientPayloadsMvpView)?.showError(R.string.failed_to_update_list) - Mockito.verify(mSyncClientPayloadsMvpView, Mockito.never()) - ?.showPayloadDeletedAndUpdatePayloads(clientPayloads) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/CenterListPresenterTest.kt b/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/CenterListPresenterTest.kt deleted file mode 100644 index f4844ade9f1..00000000000 --- a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/CenterListPresenterTest.kt +++ /dev/null @@ -1,149 +0,0 @@ -package com.mifos.mifosxdroid.online - -import com.mifos.api.datamanager.DataManagerCenter -import com.mifos.mifosxdroid.FakeRemoteDataSource.centers -import com.mifos.mifosxdroid.FakeRemoteDataSource.centersGroupAndMeeting -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.online.centerlist.CenterListMvpView -import com.mifos.mifosxdroid.online.centerlist.CenterListPresenter -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import com.mifos.objects.client.Page -import com.mifos.objects.group.Center -import com.mifos.objects.group.CenterWithAssociations -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by Rajan Maurya on 19/6/16. - */ -@RunWith(MockitoJUnitRunner::class) -class CenterListPresenterTest { - @get:Rule - val mOverrideSchedulersRule = RxSchedulersOverrideRule() - private lateinit var centerListPresenter: CenterListPresenter - - @Mock - lateinit var mDataManagerCenter: DataManagerCenter - - @Mock - lateinit var mCenterListMvpView: CenterListMvpView - private lateinit var centerPage: Page
- private lateinit var centerWithAssociations: CenterWithAssociations - private val offset = 0 - private val limit = 100 - private val centerId = 1 - - @Before - @Throws(Exception::class) - fun setUp() { - centerListPresenter = CenterListPresenter(mDataManagerCenter) - centerListPresenter.attachView(mCenterListMvpView) - centerPage = centers - centerWithAssociations = centersGroupAndMeeting - } - - @After - @Throws(Exception::class) - fun tearDown() { - centerListPresenter.detachView() - } - - @Test - fun testLoadCenters() { - stubDataManagerGetCenters(Observable.just(centerPage)) - centerListPresenter.loadCenters(false, offset) - Mockito.verify(mCenterListMvpView).showProgressbar(true) - Mockito.verify(mCenterListMvpView).showCenters(centerPage.pageItems) - Mockito.verify(mCenterListMvpView, Mockito.never())?.showFetchingError() - Mockito.verify(mCenterListMvpView).showProgressbar(false) - } - - @Test - fun testLoadCentersFails() { - stubDataManagerGetCenters(Observable.error(RuntimeException())) - centerListPresenter.loadCenters(false, offset) - Mockito.verify(mCenterListMvpView).showProgressbar(true) - Mockito.verify(mCenterListMvpView).showFetchingError() - Mockito.verify(mCenterListMvpView, Mockito.never()).showCenters( - centerPage.pageItems - ) - Mockito.verify(mCenterListMvpView).showProgressbar(false) - } - - @Test - fun testLoadMoreCenters() { - stubDataManagerGetCenters(Observable.just(centerPage)) - centerListPresenter.loadCenters(true, offset) - Mockito.verify(mCenterListMvpView).showProgressbar(true) - Mockito.verify(mCenterListMvpView).showMoreCenters(centerPage.pageItems) - Mockito.verify(mCenterListMvpView, Mockito.never()) - .showMessage(R.string.failed_to_fetch_centers) - Mockito.verify(mCenterListMvpView).showProgressbar(false) - } - - @Test - fun testLoadMoreCentersFails() { - stubDataManagerGetCenters(Observable.error(RuntimeException())) - centerListPresenter.loadCenters(true, offset) - Mockito.verify(mCenterListMvpView).showProgressbar(true) - Mockito.verify(mCenterListMvpView).showMessage(R.string.failed_to_fetch_centers) - Mockito.verify(mCenterListMvpView, Mockito.never()).showFetchingError() - Mockito.verify(mCenterListMvpView).showProgressbar(false) - } - - @Test - fun testEmptyCenters() { - stubDataManagerGetCenters(Observable.just(Page
())) - centerListPresenter.loadCenters(false, offset) - Mockito.verify(mCenterListMvpView).showProgressbar(true) - Mockito.verify(mCenterListMvpView).showEmptyCenters(R.string.center) - Mockito.verify(mCenterListMvpView, Mockito.never()).showFetchingError() - Mockito.verify(mCenterListMvpView).showProgressbar(false) - } - - @Test - fun testNoMoreGroupsAvailable() { - stubDataManagerGetCenters(Observable.just(Page
())) - centerListPresenter.loadCenters(true, offset) - Mockito.verify(mCenterListMvpView).showProgressbar(true) - Mockito.verify(mCenterListMvpView).showMessage(R.string.no_more_centers_available) - Mockito.verify(mCenterListMvpView, Mockito.never()).showFetchingError() - Mockito.verify(mCenterListMvpView).showProgressbar(false) - } - - @Test - fun testLoadCentersGroupAndMeeting() { - Mockito.`when`>( - mDataManagerCenter.getCentersGroupAndMeeting( - centerId - ) - ) - .thenReturn(Observable.just(centerWithAssociations)) - centerListPresenter.loadCentersGroupAndMeeting(centerId) - Mockito.verify(mCenterListMvpView) - .showCentersGroupAndMeeting(centerWithAssociations, centerId) - Mockito.verify(mCenterListMvpView, Mockito.never()) - .showMessage(R.string.failed_to_fetch_Group_and_meeting) - } - - @Test - fun testLoadCenterGroupAndMeetingFails() { - Mockito.`when`(mDataManagerCenter.getCentersGroupAndMeeting(centerId)) - .thenReturn(Observable.error(RuntimeException())) - centerListPresenter.loadCentersGroupAndMeeting(centerId) - Mockito.verify(mCenterListMvpView).showMessage(R.string.failed_to_fetch_Group_and_meeting) - Mockito.verify(mCenterListMvpView, Mockito.never()) - .showCentersGroupAndMeeting(centerWithAssociations, centerId) - } - - private fun stubDataManagerGetCenters(observable: Observable>) { - Mockito.`when`(mDataManagerCenter.getCenters(true, offset, limit)).thenReturn(observable) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/ClientChargePresenterTest.kt b/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/ClientChargePresenterTest.kt deleted file mode 100644 index a2ab70a6f9f..00000000000 --- a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/ClientChargePresenterTest.kt +++ /dev/null @@ -1,72 +0,0 @@ -package com.mifos.mifosxdroid.online - -import com.mifos.api.datamanager.DataManagerCharge -import com.mifos.mifosxdroid.FakeRemoteDataSource.clientCharges -import com.mifos.mifosxdroid.online.clientcharge.ClientChargeMvpView -import com.mifos.mifosxdroid.online.clientcharge.ClientChargePresenter -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import com.mifos.objects.client.Charges -import com.mifos.objects.client.Page -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by Rajan Maurya on 20/06/16. - */ -@RunWith(MockitoJUnitRunner::class) -class ClientChargePresenterTest { - @get:Rule - val mOverrideSchedulersRule = RxSchedulersOverrideRule() - private lateinit var mClientChargePresenter: ClientChargePresenter - - @Mock - lateinit var mDataManagerCharge: DataManagerCharge - - @Mock - lateinit var mClientChargeMvpView: ClientChargeMvpView - private lateinit var chargesPage: Page - var clientId = 1 - var offset = 0 - var limit = 10 - - @Before - fun setUp() { - mClientChargePresenter = ClientChargePresenter(mDataManagerCharge) - mClientChargePresenter.attachView(mClientChargeMvpView) - chargesPage = clientCharges - } - - @After - fun tearDown() { - mClientChargePresenter.detachView() - } - - @Test - fun testLoadCharges() { - Mockito.`when`>>( - mDataManagerCharge.getClientCharges(clientId, offset, limit) - ) - .thenReturn(Observable.just(chargesPage)) - mClientChargePresenter.loadCharges(clientId, offset, limit) - Mockito.verify(mClientChargeMvpView).showChargesList(chargesPage) - } - - @Test - fun testLoadChargesFails() { - Mockito.`when`( - mDataManagerCharge.getClientCharges(clientId, offset, limit) - ) - .thenReturn(Observable.error(RuntimeException())) - mClientChargePresenter.loadCharges(clientId, offset, limit) - Mockito.verify(mClientChargeMvpView, Mockito.never()).showChargesList( - chargesPage - ) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/ClientListPresenterTest.kt b/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/ClientListPresenterTest.kt deleted file mode 100644 index 1d5a6e0c0cd..00000000000 --- a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/ClientListPresenterTest.kt +++ /dev/null @@ -1,151 +0,0 @@ -package com.mifos.mifosxdroid.online - -import com.mifos.api.datamanager.DataManagerClient -import com.mifos.mifosxdroid.FakeRemoteDataSource.clientList -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.online.clientlist.ClientListMvpView -import com.mifos.mifosxdroid.online.clientlist.ClientListPresenter -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import com.mifos.objects.client.Client -import com.mifos.objects.client.Page -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by Rajan Maurya on 15/06/16. - */ -@RunWith(MockitoJUnitRunner::class) -class ClientListPresenterTest { - @get:Rule - val mOverrideSchedulersRule = RxSchedulersOverrideRule() - private lateinit var mClientListPresenter: ClientListPresenter - - @Mock - lateinit var mDataManagerClient: DataManagerClient - - @Mock - lateinit var mClientListMvpView: ClientListMvpView - var offset = 0 - var limit = 100 - private lateinit var clientPage: Page - - @Before - @Throws(Exception::class) - fun setUp() { - mClientListPresenter = ClientListPresenter(mDataManagerClient) - mClientListPresenter.attachView(mClientListMvpView) - clientPage = Page() - clientPage = clientList - } - - @After - fun tearDown() { - mClientListPresenter.detachView() - } - - @Test - fun testLoadClients() { - stubDatabaseGetAllClients(Observable.just(clientPage)) - mClientListPresenter.loadDatabaseClients() - mClientListPresenter.setAlreadyClientSyncStatus() - Mockito.verify(mClientListMvpView, Mockito.never()) - .showMessage(R.string.failed_to_load_db_clients) - stubDataManagerGetClients(Observable.just(clientPage)) - mClientListPresenter.loadClients(false, offset) - Mockito.verify(mClientListMvpView).showProgressbar(true) - Mockito.verify(mClientListMvpView).showClientList(clientPage.pageItems) - Mockito.verify(mClientListMvpView, Mockito.never()).showError() - Mockito.verify(mClientListMvpView).showProgressbar(false) - } - - @Test - fun testLoadClientFails() { - stubDataManagerGetClients(Observable.error>(RuntimeException())) - mClientListPresenter.loadClients(false, offset) - Mockito.verify(mClientListMvpView).showError() - Mockito.verify(mClientListMvpView, Mockito.never()).showClientList( - clientPage.pageItems - ) - } - - @Test - fun testLoadMoreClients() { - stubDatabaseGetAllClients(Observable.just(clientPage)) - mClientListPresenter.loadDatabaseClients() - mClientListPresenter.setAlreadyClientSyncStatus() - Mockito.verify(mClientListMvpView, Mockito.never()) - .showMessage(R.string.failed_to_load_db_clients) - stubDataManagerGetClients(Observable.just(clientPage)) - mClientListPresenter.loadClients(true, offset) - Mockito.verify(mClientListMvpView).showProgressbar(true) - Mockito.verify(mClientListMvpView).showLoadMoreClients(clientPage.pageItems) - Mockito.verify(mClientListMvpView, Mockito.never()).showError() - Mockito.verify(mClientListMvpView).showProgressbar(false) - } - - @Test - fun testLoadMoreClientFails() { - stubDataManagerGetClients(Observable.error>(RuntimeException())) - mClientListPresenter.loadClients(true, offset) - Mockito.verify(mClientListMvpView).showMessage(R.string.failed_to_load_client) - Mockito.verify(mClientListMvpView, Mockito.never()).showClientList( - clientPage.pageItems - ) - } - - @Test - fun testEmptyClientList() { - stubDataManagerGetClients(Observable.just(Page())) - mClientListPresenter.loadClients(false, offset) - Mockito.verify(mClientListMvpView).showProgressbar(true) - Mockito.verify(mClientListMvpView).showEmptyClientList(R.string.client) - Mockito.verify(mClientListMvpView).unregisterSwipeAndScrollListener() - Mockito.verify(mClientListMvpView, Mockito.never()).showError() - Mockito.verify(mClientListMvpView).showProgressbar(false) - } - - @Test - fun testNoMoreClientsAvailable() { - stubDataManagerGetClients(Observable.just(Page())) - mClientListPresenter.loadClients(true, offset) - Mockito.verify(mClientListMvpView).showProgressbar(true) - Mockito.verify(mClientListMvpView).showMessage(R.string.no_more_clients_available) - Mockito.verify(mClientListMvpView, Mockito.never()).showError() - Mockito.verify(mClientListMvpView).showProgressbar(false) - } - - @Test - fun testLoadDatabaseClients() { - stubDatabaseGetAllClients(Observable.just(clientPage)) - mClientListPresenter.loadDatabaseClients() - mClientListPresenter.setAlreadyClientSyncStatus() - Mockito.verify(mClientListMvpView, Mockito.never()) - .showMessage(R.string.failed_to_load_db_clients) - } - - @Test - fun testLoadDatabaseClientsFails() { - stubDatabaseGetAllClients(Observable.error(RuntimeException())) - mClientListPresenter.loadDatabaseClients() - Mockito.verify(mClientListMvpView).showMessage(R.string.failed_to_load_db_clients) - } - - private fun stubDataManagerGetClients(observable: Observable>) { - Mockito.`when`( - mDataManagerClient.getAllClients(true, offset, limit) - ).thenReturn(observable) - } - - private fun stubDatabaseGetAllClients(observable: Observable>) { - Mockito.`when`( - mDataManagerClient.allDatabaseClients - ).thenReturn(observable) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/DocumentListPresenterTest.kt b/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/DocumentListPresenterTest.kt deleted file mode 100644 index 9dfb267f4e5..00000000000 --- a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/DocumentListPresenterTest.kt +++ /dev/null @@ -1,88 +0,0 @@ -package com.mifos.mifosxdroid.online - -import com.mifos.api.datamanager.DataManagerDocument -import com.mifos.mifosxdroid.FakeRemoteDataSource.documents -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.online.documentlist.DocumentListMvpView -import com.mifos.mifosxdroid.online.documentlist.DocumentListPresenter -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import com.mifos.objects.noncore.Document -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by Rajan Maurya on 21/06/16. - */ -@RunWith(MockitoJUnitRunner::class) -class DocumentListPresenterTest { - @get:Rule - val mOverrideSchedulersRule = RxSchedulersOverrideRule() - private lateinit var mDocumentListPresenter: DocumentListPresenter - - @Mock - lateinit var mDataManager: DataManagerDocument - - @Mock - lateinit var mDocumentListMvpView: DocumentListMvpView - private lateinit var documentList: List - private val entityType = "clients" - private val entityId = 9 - - @Before - fun setUp() { - mDocumentListPresenter = DocumentListPresenter(mDataManager) - mDocumentListPresenter.attachView(mDocumentListMvpView) - documentList = documents - } - - @After - fun tearDown() { - mDocumentListPresenter.detachView() - } - - @Test - fun testLoadDocumentList() { - stubDataManagerGetDocuments(Observable.just(documentList)) - mDocumentListPresenter.loadDocumentList(entityType, entityId) - Mockito.verify(mDocumentListMvpView).showDocumentList(documentList) - Mockito.verify(mDocumentListMvpView, Mockito.never()).showEmptyDocuments() - Mockito.verify(mDocumentListMvpView, Mockito.never()) - .showFetchingError(R.string.failed_to_fetch_documents) - } - - @Test - fun testLoadDocumentEmptyList() { - val emptyDocuments: List = ArrayList() - stubDataManagerGetDocuments(Observable.just(emptyDocuments)) - mDocumentListPresenter.loadDocumentList(entityType, entityId) - Mockito.verify(mDocumentListMvpView, Mockito.never()).showDocumentList( - documentList - ) - Mockito.verify(mDocumentListMvpView, Mockito.never()) - .showFetchingError(R.string.failed_to_fetch_documents) - } - - @Test - fun testLoadDocumentListFails() { - stubDataManagerGetDocuments(Observable.error(RuntimeException())) - mDocumentListPresenter.loadDocumentList(entityType, entityId) - Mockito.verify(mDocumentListMvpView).showFetchingError(R.string.failed_to_fetch_documents) - Mockito.verify(mDocumentListMvpView, Mockito.never()).showDocumentList( - documentList - ) - Mockito.verify(mDocumentListMvpView, Mockito.never()).showEmptyDocuments() - } - - private fun stubDataManagerGetDocuments(observable: Observable<*>) { - Mockito.doReturn(observable) - .`when`(mDataManager) - .getDocumentsList(entityType, entityId) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/GroupsListPresenterTest.kt b/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/GroupsListPresenterTest.kt deleted file mode 100644 index a2f28c37eeb..00000000000 --- a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/GroupsListPresenterTest.kt +++ /dev/null @@ -1,145 +0,0 @@ -package com.mifos.mifosxdroid.online - -import com.mifos.api.datamanager.DataManagerGroups -import com.mifos.mifosxdroid.FakeRemoteDataSource.groups -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.online.groupslist.GroupsListMvpView -import com.mifos.mifosxdroid.online.groupslist.GroupsListPresenter -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import com.mifos.objects.client.Page -import com.mifos.objects.group.Group -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by Rajan Maurya on 28/6/16. - */ -@RunWith(MockitoJUnitRunner::class) -class GroupsListPresenterTest { - @get:Rule - val mOverrideSchedulersRule = RxSchedulersOverrideRule() - private lateinit var mGroupsListPresenter: GroupsListPresenter - - @Mock - lateinit var mDataManagerGroups: DataManagerGroups - - @Mock - lateinit var mGroupsListMvpView: GroupsListMvpView - private lateinit var groupPage: Page - var offset = 0 - var limit = 100 - - @Before - fun setUp() { - mGroupsListPresenter = GroupsListPresenter(mDataManagerGroups) - mGroupsListPresenter.attachView(mGroupsListMvpView) - groupPage = groups - } - - @After - fun tearDown() { - mGroupsListPresenter.detachView() - } - - @Test - fun testLoadGroup() { - stubDatabaseGetAllGroups(Observable.just(groupPage)) - mGroupsListPresenter.loadDatabaseGroups() - mGroupsListPresenter.setAlreadyClientSyncStatus() - Mockito.verify(mGroupsListMvpView, Mockito.never()) - .showMessage(R.string.failed_to_load_db_groups) - stubDataManagerGetGroups(Observable.just(groupPage)) - mGroupsListPresenter.loadGroups(false, offset) - Mockito.verify(mGroupsListMvpView).showProgressbar(true) - Mockito.verify(mGroupsListMvpView).showGroups(groupPage.pageItems) - Mockito.verify(mGroupsListMvpView, Mockito.never()).showFetchingError() - Mockito.verify(mGroupsListMvpView).showProgressbar(false) - } - - @Test - fun testLoadGroupFails() { - stubDataManagerGetGroups(Observable.error(RuntimeException())) - mGroupsListPresenter.loadGroups(false, offset) - Mockito.verify(mGroupsListMvpView).showFetchingError() - Mockito.verify(mGroupsListMvpView, Mockito.never()).showGroups(groupPage.pageItems) - } - - @Test - fun testLoadMoreGroups() { - stubDatabaseGetAllGroups(Observable.just(groupPage)) - mGroupsListPresenter.loadDatabaseGroups() - mGroupsListPresenter.setAlreadyClientSyncStatus() - Mockito.verify(mGroupsListMvpView, Mockito.never()) - .showMessage(R.string.failed_to_load_db_groups) - stubDataManagerGetGroups(Observable.just(groupPage)) - mGroupsListPresenter.loadGroups(true, offset) - Mockito.verify(mGroupsListMvpView).showProgressbar(true) - Mockito.verify(mGroupsListMvpView).showLoadMoreGroups(groupPage.pageItems) - Mockito.verify(mGroupsListMvpView, Mockito.never()).showFetchingError() - Mockito.verify(mGroupsListMvpView).showProgressbar(false) - } - - @Test - fun testLoadMoreGroupFails() { - stubDataManagerGetGroups(Observable.error(RuntimeException())) - mGroupsListPresenter.loadGroups(true, offset) - Mockito.verify(mGroupsListMvpView).showMessage(R.string.failed_to_fetch_groups) - Mockito.verify(mGroupsListMvpView, Mockito.never()).showGroups(groupPage.pageItems) - } - - @Test - fun testEmptyGroupList() { - stubDataManagerGetGroups(Observable.just(Page())) - mGroupsListPresenter.loadGroups(false, offset) - Mockito.verify(mGroupsListMvpView).showProgressbar(true) - Mockito.verify(mGroupsListMvpView).showEmptyGroups(R.string.group) - Mockito.verify(mGroupsListMvpView).unregisterSwipeAndScrollListener() - Mockito.verify(mGroupsListMvpView, Mockito.never()).showFetchingError() - Mockito.verify(mGroupsListMvpView).showProgressbar(false) - } - - @Test - fun testNoMoreGroupsAvailable() { - stubDataManagerGetGroups(Observable.just(Page())) - mGroupsListPresenter.loadGroups(true, offset) - Mockito.verify(mGroupsListMvpView).showProgressbar(true) - Mockito.verify(mGroupsListMvpView).showMessage(R.string.no_more_groups_available) - Mockito.verify(mGroupsListMvpView, Mockito.never()).showFetchingError() - Mockito.verify(mGroupsListMvpView).showProgressbar(false) - } - - @Test - fun testLoadDatabaseGroups() { - stubDatabaseGetAllGroups(Observable.just(groupPage)) - mGroupsListPresenter.loadDatabaseGroups() - mGroupsListPresenter.setAlreadyClientSyncStatus() - Mockito.verify(mGroupsListMvpView, Mockito.never()) - .showMessage(R.string.failed_to_load_db_groups) - } - - @Test - fun testLoadDatabaseGroupsFails() { - stubDatabaseGetAllGroups(Observable.error(RuntimeException())) - mGroupsListPresenter.loadDatabaseGroups() - Mockito.verify(mGroupsListMvpView).showMessage(R.string.failed_to_load_db_groups) - } - - private fun stubDataManagerGetGroups(observable: Observable>) { - Mockito.`when`( - mDataManagerGroups.getGroups(true, offset, limit) - ).thenReturn(observable) - } - - private fun stubDatabaseGetAllGroups(observable: Observable>) { - Mockito.`when`( - mDataManagerGroups.databaseGroups - ).thenReturn(observable) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/LoanChargePresenterTest.kt b/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/LoanChargePresenterTest.kt deleted file mode 100644 index b564172254d..00000000000 --- a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/LoanChargePresenterTest.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.mifos.mifosxdroid.online - -import com.mifos.api.DataManager -import com.mifos.mifosxdroid.FakeRemoteDataSource.loanCharges -import com.mifos.mifosxdroid.online.loancharge.LoanChargeMvpView -import com.mifos.mifosxdroid.online.loancharge.LoanChargePresenter -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import com.mifos.objects.client.Charges -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by Rajan Maurya on 20/06/16. - */ -@RunWith(MockitoJUnitRunner::class) -class LoanChargePresenterTest { - @get:Rule - val mOverrideSchedulersRule = RxSchedulersOverrideRule() - lateinit var mLoanChargePresenter: LoanChargePresenter - - @Mock - lateinit var mDataManager: DataManager - - @Mock - lateinit var mLoanChargeMvpView: LoanChargeMvpView - private lateinit var chargesList: List - var loanId = 441 - - @Before - @Throws(Exception::class) - fun setUp() { - mLoanChargePresenter = LoanChargePresenter(mDataManager) - mLoanChargePresenter.attachView(mLoanChargeMvpView) - chargesList = loanCharges - } - - @After - @Throws(Exception::class) - fun tearDown() { - mLoanChargePresenter.detachView() - } - - @Test - @Throws(Exception::class) - fun testLoadLoanChargesList() { - Mockito.`when`( - mDataManager.getListOfLoanCharges(loanId) - ) - .thenReturn(Observable.just(chargesList)) - mLoanChargePresenter.loadLoanChargesList(loanId) - Mockito.verify(mLoanChargeMvpView).showLoanChargesList(chargesList as MutableList) - Mockito.verify(mLoanChargeMvpView, Mockito.never()) - .showFetchingError("Failed to load Charges") - } - - @Test - fun testLoadChargesFails() { - Mockito.`when`( - mDataManager.getListOfLoanCharges(loanId) - ) - .thenReturn(Observable.error(RuntimeException())) - mLoanChargePresenter.loadLoanChargesList(loanId) - Mockito.verify(mLoanChargeMvpView, Mockito.never()) - .showLoanChargesList(chargesList as MutableList) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/SearchPresenterTest.kt b/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/SearchPresenterTest.kt deleted file mode 100644 index 90a818b0543..00000000000 --- a/mifosng-android/src/test/java/com/mifos/mifosxdroid/online/SearchPresenterTest.kt +++ /dev/null @@ -1,265 +0,0 @@ -package com.mifos.mifosxdroid.online - -import com.mifos.api.datamanager.DataManagerSearch -import com.mifos.mifosxdroid.FakeRemoteDataSource.searchedEntity -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.online.search.SearchMvpView -import com.mifos.mifosxdroid.online.search.SearchPresenter -import com.mifos.mifosxdroid.util.RxSchedulersOverrideRule -import com.mifos.objects.SearchedEntity -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.junit.MockitoJUnitRunner -import rx.Observable - -/** - * Created by Rajan Maurya on 17/6/16. - */ -@RunWith(MockitoJUnitRunner::class) -class SearchPresenterTest { - @get:Rule - val mOverrideSchedulersRule = RxSchedulersOverrideRule() - private lateinit var searchPresenter: SearchPresenter - - @Mock - lateinit var dataManager: DataManagerSearch - - @Mock - lateinit var searchMvpView: SearchMvpView - private lateinit var searchedEntities: List - private var query = "1" - private var resources: String? = null - private val exactMatch = false - - @Before - fun setUp() { - searchPresenter = SearchPresenter(dataManager) - searchPresenter.attachView(searchMvpView) - searchedEntities = searchedEntity - } - - @After - fun tearDown() { - searchPresenter.detachView() - } - - @Test - fun testSearchAll() { - resources = "clients,groups,loans,savingsaccounts" - stubDataManagerGetSearch(Observable.just(searchedEntities), exactMatch) - searchPresenter.searchResources(query, resources, exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showSearchedResources(searchedEntities) - Mockito.verify(searchMvpView, Mockito.never()) - .showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView).showProgressbar(false) - } - - @Test - fun testSearchAllFails() { - resources = "clients,groups,loans,savingsaccounts" - stubDataManagerGetSearch( - Observable.error(RuntimeException()), - exactMatch - ) - searchPresenter.searchResources(query, resources, exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView, Mockito.never()).showSearchedResources( - searchedEntities - ) - Mockito.verify(searchMvpView).showProgressbar(false) - } - - @Test - fun testSearchClients() { - resources = "clients" - val clientSearch = filterEntities("CLIENT") - stubDataManagerGetSearch(Observable.just(clientSearch), exactMatch) - searchPresenter.searchResources(query, resources, exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showSearchedResources(clientSearch) - Mockito.verify(searchMvpView, Mockito.never()) - .showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView).showProgressbar(false) - } - - @Test - fun testSearchClientsFails() { - resources = "clients" - stubDataManagerGetSearch( - Observable.error(RuntimeException()), - exactMatch - ) - searchPresenter.searchResources(query, resources, exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView, Mockito.never()).showSearchedResources( - searchedEntities - ) - Mockito.verify(searchMvpView).showProgressbar(false) - } - - @Test - fun testSearchGroups() { - resources = "groups" - val groupSearch = filterEntities("GROUP") - stubDataManagerGetSearch(Observable.just(groupSearch), exactMatch) - searchPresenter.searchResources(query, resources, exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showSearchedResources(groupSearch) - Mockito.verify(searchMvpView, Mockito.never()) - .showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView).showProgressbar(false) - } - - @Test - fun testSearchGroupsFails() { - resources = "groups" - stubDataManagerGetSearch( - Observable.error(RuntimeException()), - exactMatch - ) - searchPresenter.searchResources(query, resources, exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView, Mockito.never()).showSearchedResources( - searchedEntities - ) - Mockito.verify(searchMvpView).showProgressbar(false) - } - - @Test - fun testSearchLoans() { - resources = "loans" - val loansSearch = filterEntities("LOAN") - stubDataManagerGetSearch(Observable.just(loansSearch), exactMatch) - searchPresenter.searchResources(query, resources, exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showSearchedResources(loansSearch) - Mockito.verify(searchMvpView, Mockito.never()) - .showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView, Mockito.never()).showNoResultFound() - Mockito.verify(searchMvpView).showProgressbar(false) - } - - @Test - fun testSearchLoansFails() { - resources = "loans" - stubDataManagerGetSearch( - Observable.error(RuntimeException()), - exactMatch - ) - searchPresenter.searchResources(query, resources, exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView, Mockito.never()).showSearchedResources( - searchedEntities - ) - Mockito.verify(searchMvpView).showProgressbar(false) - } - - @Test - fun testSearchSavings() { - resources = "savingsaccounts" - val savingSearch = filterEntities("SAVING") - stubDataManagerGetSearch(Observable.just(savingSearch), exactMatch) - searchPresenter.searchResources(query, resources, exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showSearchedResources(savingSearch) - Mockito.verify(searchMvpView, Mockito.never()) - .showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView).showProgressbar(false) - } - - @Test - fun testSearchSavingsFails() { - resources = "savingsaccounts" - stubDataManagerGetSearch( - Observable.error(RuntimeException()), - exactMatch - ) - searchPresenter.searchResources(query, resources, exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView, Mockito.never()).showSearchedResources( - searchedEntities - ) - Mockito.verify(searchMvpView).showProgressbar(false) - } - - @Test - fun testSearchExactMatch() { - query = "Madenge Pimbi" - resources = "clients" - val exactSearch: MutableList = ArrayList() - Observable.from(searchedEntities) - .subscribe { searchedEntity -> - if (searchedEntity.entityName == "Madenge Pimbi") { - exactSearch.add(searchedEntity) - } - } - stubDataManagerGetSearch(Observable.just(exactSearch), !exactMatch) - searchPresenter.searchResources(query, resources, !exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showSearchedResources(exactSearch) - Mockito.verify(searchMvpView, Mockito.never()) - .showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView).showProgressbar(false) - } - - @Test - fun testSearchExactMatchFails() { - query = "Smith R" - resources = "clients" - stubDataManagerGetSearch( - Observable.error(RuntimeException()), - !exactMatch - ) - searchPresenter.searchResources(query, resources, !exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView, Mockito.never()).showSearchedResources( - searchedEntities - ) - Mockito.verify(searchMvpView).showProgressbar(false) - } - - @Test - fun testSearchNoResultFound() { - resources = "savingsaccounts" - val savingSearch: List = ArrayList() - stubDataManagerGetSearch(Observable.just(savingSearch), exactMatch) - searchPresenter.searchResources(query, resources, exactMatch) - Mockito.verify(searchMvpView).showProgressbar(true) - Mockito.verify(searchMvpView).showNoResultFound() - Mockito.verify(searchMvpView, Mockito.never()).showSearchedResources(savingSearch) - Mockito.verify(searchMvpView, Mockito.never()) - .showMessage(R.string.failed_to_fetch_resources_of_query) - Mockito.verify(searchMvpView).showProgressbar(false) - } - - private fun filterEntities(entityType: String): List { - val search: MutableList = ArrayList() - Observable.from(searchedEntities) - .subscribe { searchedEntity -> - if (searchedEntity.entityType == entityType) { - search.add(searchedEntity) - } - } - return search - } - - private fun stubDataManagerGetSearch( - observable: Observable>, - exactMatch: Boolean - ) { - Mockito.`when`(dataManager.searchResources(query, resources, exactMatch)) - .thenReturn(observable) - } -} \ No newline at end of file diff --git a/mifosng-android/src/test/java/com/mifos/viewmodels/ClientChargeViewModelTest.kt b/mifosng-android/src/test/java/com/mifos/viewmodels/ClientChargeViewModelTest.kt index dab39b81b85..5c46fa32ba0 100644 --- a/mifosng-android/src/test/java/com/mifos/viewmodels/ClientChargeViewModelTest.kt +++ b/mifosng-android/src/test/java/com/mifos/viewmodels/ClientChargeViewModelTest.kt @@ -20,6 +20,9 @@ import org.mockito.MockitoAnnotations import org.mockito.junit.MockitoJUnitRunner import rx.Observable +/** + * Created by Aditya Gupta on 02/09/23. + */ @RunWith(MockitoJUnitRunner::class) class ClientChargeViewModelTest { diff --git a/mifosng-android/src/test/java/com/mifos/viewmodels/LoanChargeViewModelTest.kt b/mifosng-android/src/test/java/com/mifos/viewmodels/LoanChargeViewModelTest.kt index 13b831a947b..3e5c11af782 100644 --- a/mifosng-android/src/test/java/com/mifos/viewmodels/LoanChargeViewModelTest.kt +++ b/mifosng-android/src/test/java/com/mifos/viewmodels/LoanChargeViewModelTest.kt @@ -18,6 +18,9 @@ import org.mockito.MockitoAnnotations import org.mockito.junit.MockitoJUnitRunner import rx.Observable +/** + * Created by Aditya Gupta on 02/09/23. + */ @RunWith(MockitoJUnitRunner::class) class LoanChargeViewModelTest { diff --git a/mifosng-android/src/test/java/com/mifos/viewmodels/LoginViewModelTest.kt b/mifosng-android/src/test/java/com/mifos/viewmodels/LoginViewModelTest.kt index 3af5761a27d..aef350aaa8c 100644 --- a/mifosng-android/src/test/java/com/mifos/viewmodels/LoginViewModelTest.kt +++ b/mifosng-android/src/test/java/com/mifos/viewmodels/LoginViewModelTest.kt @@ -17,6 +17,9 @@ import org.mockito.MockitoAnnotations import org.mockito.junit.MockitoJUnitRunner import rx.Observable +/** + * Created by Aditya Gupta on 02/09/23. + */ @RunWith(MockitoJUnitRunner::class) class LoginViewModelTest { diff --git a/mifosng-android/src/test/java/com/mifos/viewmodels/SearchViewModelTest.kt b/mifosng-android/src/test/java/com/mifos/viewmodels/SearchViewModelTest.kt index d0c127dd3a0..e1f3978ccb3 100644 --- a/mifosng-android/src/test/java/com/mifos/viewmodels/SearchViewModelTest.kt +++ b/mifosng-android/src/test/java/com/mifos/viewmodels/SearchViewModelTest.kt @@ -18,6 +18,9 @@ import org.mockito.MockitoAnnotations import org.mockito.junit.MockitoJUnitRunner import rx.Observable +/** + * Created by Aditya Gupta on 02/09/23. + */ @RunWith(MockitoJUnitRunner::class) class SearchViewModelTest {