Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Dependencies (okHttp, RecyclerView, PlayServices, OSS, Coroutines, Crashlytics, Fragment, ComposeCompiler, Material Lifecycle) #2350

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ dependencies {
androidTestImplementation "junit:junit:$rootProject.jUnitVersion"
androidTestImplementation "org.mockito:mockito-core:$rootProject.mockitoVersion"
androidTestImplementation "org.mockito:mockito-android:$rootProject.mockitoVersion"
androidTestImplementation "androidx.annotation:annotation:1.0.0"
androidTestImplementation "androidx.annotation:annotation:1.7.0"
implementation "androidx.arch.core:core-testing:$rootProject.archCoreVersion"
androidTestImplementation("androidx.test.espresso:espresso-contrib:$rootProject.espressoVersion") {
exclude group: 'com.android.support', module: 'appcompat'
Expand Down
4 changes: 3 additions & 1 deletion app/src/commonTest/java/org/mifos/mobile/RetrofitUtils.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.mifos.mobile

import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.Protocol
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import retrofit2.HttpException
import retrofit2.Response

Expand All @@ -13,7 +15,7 @@ object RetrofitUtils {
fun getResponseForError(errorCode: Int): Exception {
val message = if (errorCode == 401) "UnAuthorized" else "Not Found"
val responseBody =
ResponseBody.create(MediaType.parse("application/json"), "{\"message\":\"$message\"}")
"{\"message\":\"$message\"}".toResponseBody("application/json".toMediaTypeOrNull())
val response = okhttp3.Response.Builder().code(errorCode)
.message(message)
.protocol(Protocol.HTTP_1_1)
Expand Down
16 changes: 10 additions & 6 deletions app/src/debug/java/org/mifos/mobile/api/SelfServiceInterceptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ class SelfServiceInterceptor(private val tenant: String?, private val authToken:
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val chainRequest = chain.request()
val builder = chainRequest.newBuilder()
.header(HEADER_TENANT, tenant)
.header(CONTENT_TYPE, "application/json")
val builder = tenant?.let {
chainRequest.newBuilder()
.header(HEADER_TENANT, it)
.header(CONTENT_TYPE, "application/json")
}
if (!TextUtils.isEmpty(authToken)) {
builder.header(HEADER_AUTH, authToken)
if (authToken != null) {
builder?.header(HEADER_AUTH, authToken)
}
}
val request = builder.build()
return chain.proceed(request)
val request = builder?.build()
return chain.proceed(request!!)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import org.mifos.mobile.FakeRemoteDataSource
import org.mifos.mobile.api.DataManager
import org.mifos.mobile.models.guarantor.GuarantorApplicationPayload
Expand All @@ -30,10 +32,8 @@ class GuarantorRepositoryImp @Inject constructor(private val dataManager: DataMa
return flow {
emit(dataManager.createGuarantor(loanId, payload))
}.catch {
val responseBody = ResponseBody.create(
MediaType.parse("text/plain"),
"Guarantor Added Successfully"
)
val responseBody = "Guarantor Added Successfully"
.toResponseBody("text/plain".toMediaTypeOrNull())
emit(responseBody)
}
}
Expand All @@ -46,10 +46,8 @@ class GuarantorRepositoryImp @Inject constructor(private val dataManager: DataMa
return flow {
emit(dataManager.updateGuarantor(payload, loanId, guarantorId))
}.catch {
val response = ResponseBody.create(
MediaType
.parse("plain/text"),
"Guarantor Updated Successfully",
val response = "Guarantor Updated Successfully".toResponseBody(
"plain/text".toMediaTypeOrNull()
)
emit(response)
}
Expand All @@ -59,10 +57,8 @@ class GuarantorRepositoryImp @Inject constructor(private val dataManager: DataMa
return flow {
emit(dataManager.deleteGuarantor(loanId, guarantorId))
}.catch {
val response = ResponseBody.create(
MediaType
.parse("plain/text"),
"Guarantor Deleted Successfully",
val response = "Guarantor Deleted Successfully".toResponseBody(
"plain/text".toMediaTypeOrNull()
)
emit(response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class HomeActivity :
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
.show()
?.show()
} else {
Log.i(HomeActivity::class.java.name, "This device is not supported.")
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LocationsFragment : BaseFragment(), OnMapReadyCallback {
binding.map.onCreate(savedInstanceState)
binding.map.onResume()
try {
MapsInitializer.initialize(activity?.applicationContext)
activity?.applicationContext?.let { MapsInitializer.initialize(it) }
} catch (e: Exception) {
Log.d(LocationsFragment::class.java.simpleName, e.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import junit.framework.Assert.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -54,7 +55,7 @@ class BeneficiaryRepositoryImpTest {
@Test
fun testBeneficiaryTemplate_Unsuccessful() = runBlocking {
val error: Response<BeneficiaryTemplate?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
`when`(dataManager.beneficiaryTemplate()).thenReturn(error)

val result = beneficiaryRepositoryImp.beneficiaryTemplate()
Expand All @@ -81,7 +82,7 @@ class BeneficiaryRepositoryImpTest {
@Test
fun testCreateBeneficiary_Unsuccessful() = runBlocking {
val error: Response<ResponseBody?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
val beneficiaryPayload = mock(BeneficiaryPayload::class.java)

`when`(dataManager.createBeneficiary(beneficiaryPayload)).thenReturn(error)
Expand All @@ -108,7 +109,7 @@ class BeneficiaryRepositoryImpTest {
@Test
fun testUpdateBeneficiary_Unsuccessful() = runBlocking {
val error: Response<ResponseBody?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))

val beneficiaryUpdatePayload = mock(BeneficiaryUpdatePayload::class.java)

Expand All @@ -133,7 +134,7 @@ class BeneficiaryRepositoryImpTest {
@Test
fun testDeleteBeneficiary_Unsuccessful() = runBlocking {
val error: Response<ResponseBody?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))

`when`(dataManager.deleteBeneficiary(123L)).thenReturn(error)

Expand All @@ -155,7 +156,7 @@ class BeneficiaryRepositoryImpTest {
@Test
fun testBeneficiaryList_Unsuccessful() = runBlocking {
val error: Response<List<Beneficiary?>?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))

`when`(dataManager.beneficiaryList()).thenReturn(error)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import junit.framework.Assert.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -51,7 +52,7 @@ class ClientChargeRepositoryImpTest {
@Test
fun testGetClientCharges_Unsuccessful() = runBlocking {
val error: Response<Page<Charge?>?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))

`when`(dataManager.getClientCharges(123L)).thenReturn(error)

Expand All @@ -73,7 +74,7 @@ class ClientChargeRepositoryImpTest {
@Test
fun testGetLoanCharges_Unsuccessful() = runBlocking {
val error: Response<List<Charge?>?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))

`when`(dataManager.getLoanCharges(123L)).thenReturn(error)

Expand All @@ -95,7 +96,7 @@ class ClientChargeRepositoryImpTest {
@Test
fun testGetSavingsCharges_Unsuccessful() = runBlocking {
val error: Response<List<Charge?>?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))

`when`(dataManager.getSavingsCharges(123L)).thenReturn(error)

Expand All @@ -117,7 +118,7 @@ class ClientChargeRepositoryImpTest {
@Test
fun testClientLocalCharges_Unsuccessful() = runBlocking {
val error: Response<Page<Charge?>?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))

`when`(dataManager.clientLocalCharges()).thenReturn(error)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import okhttp3.Credentials
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import org.junit.Assert
import org.junit.Before
import org.junit.Test
Expand Down Expand Up @@ -61,7 +62,7 @@ class ClientRepositoryImpTest {
fun testLoadClient_ErrorResponseReceivedFromDataManager_ReturnsError() = runBlocking{
Dispatchers.setMain(Dispatchers.Unconfined)
val errorResponse: Response<Page<Client?>?> =
Response.error(404, ResponseBody.create(null,"error"))
Response.error(404, "error".toResponseBody(null))
Mockito.`when`(
dataManager.clients()
).thenReturn(errorResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -63,7 +64,7 @@ class LoanRepositoryImpTest {
fun testGetLoanWithAssociations_Unsuccessful() = runBlocking {
Dispatchers.setMain(Dispatchers.Unconfined)
val error: Response<LoanWithAssociations?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
`when`(
dataManager.getLoanWithAssociations(
Mockito.anyString(),
Expand Down Expand Up @@ -98,7 +99,7 @@ class LoanRepositoryImpTest {
fun testWithdrawLoanAccount_Unsuccessful() = runBlocking {
Dispatchers.setMain(Dispatchers.Unconfined)
val error: Response<ResponseBody?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
`when`(dataManager.withdrawLoanAccount(1, loanWithdraw)).thenReturn(error)

val result = loanRepositoryImp.withdrawLoanAccount(1, loanWithdraw)
Expand All @@ -124,7 +125,7 @@ class LoanRepositoryImpTest {
fun testTemplate_Unsuccessful() = runBlocking {
Dispatchers.setMain(Dispatchers.Unconfined)
val error: Response<LoanTemplate?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
`when`(dataManager.loanTemplate()).thenReturn(error)

val result = loanRepositoryImp.template()
Expand All @@ -150,7 +151,7 @@ class LoanRepositoryImpTest {
fun testGetLoanTemplateByProduct_Unsuccessful() = runBlocking {
Dispatchers.setMain(Dispatchers.Unconfined)
val error: Response<LoanTemplate?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
`when`(dataManager.getLoanTemplateByProduct(1)).thenReturn(error)

val result = loanRepositoryImp.getLoanTemplateByProduct(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CoroutineTestRule
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -55,7 +56,7 @@ class RecentTransactionRepositoryImpTest {
@Test
fun recentTransaction_unsuccessful_response_from_dataManger() = runBlocking {
val error: Response<Page<Transaction?>?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
val offset = 0
val limit = 50

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CoroutineTestRule
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -67,7 +68,7 @@ class SavingsAccountRepositoryImpTest {
fun testGetSavingsWithAssociations_ErrorResponseReceivedFromDataManager_ReturnsError() =
runBlocking {
val errorResponse: Response<SavingsWithAssociations?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
Mockito.`when`(
dataManager.getSavingsWithAssociations(mockAccountId, mockAssociationType)
).thenReturn(errorResponse)
Expand Down Expand Up @@ -102,7 +103,7 @@ class SavingsAccountRepositoryImpTest {
fun testGetSavingsAccountApplicationTemplate_ErrorResponseFromDataManager_ReturnsError() =
runBlocking {
val errorResponse: Response<SavingsAccountTemplate?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
Mockito.`when`(
dataManager.getSavingAccountApplicationTemplate(mockClientId)
).thenReturn(errorResponse)
Expand Down Expand Up @@ -140,7 +141,7 @@ class SavingsAccountRepositoryImpTest {
val mockSavingsAccountApplicationPayload =
Mockito.mock(SavingsAccountApplicationPayload::class.java)
val errorResponse: Response<ResponseBody?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
Mockito.`when`(
dataManager.submitSavingAccountApplication(mockSavingsAccountApplicationPayload)
).thenReturn(errorResponse)
Expand Down Expand Up @@ -177,7 +178,7 @@ class SavingsAccountRepositoryImpTest {
fun testUpdateSavingsAccount_ErrorResponseFromDataManager_ReturnsError() = runBlocking {
val mockSavingsAccountUpdatePayload = Mockito.mock(SavingsAccountUpdatePayload::class.java)
val errorResponse: Response<ResponseBody?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
Mockito.`when`(
dataManager.updateSavingsAccount(mockAccountId, mockSavingsAccountUpdatePayload)
).thenReturn(errorResponse)
Expand Down Expand Up @@ -223,7 +224,7 @@ class SavingsAccountRepositoryImpTest {
val mockSavingsAccountWithdrawPayload =
Mockito.mock(SavingsAccountWithdrawPayload::class.java)
val errorResponse: Response<ResponseBody?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
Mockito.`when`(
dataManager.submitWithdrawSavingsAccount(
mockAccountId,
Expand Down Expand Up @@ -259,7 +260,7 @@ class SavingsAccountRepositoryImpTest {
@Test
fun testLoanAccountTransferTemplate_ErrorResponseFromDataManager_ReturnsError() = runBlocking {
val errorResponse: Response<AccountOptionsTemplate?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
Mockito.`when`(
dataManager.accountTransferTemplate()
).thenReturn(errorResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import junit.framework.Assert.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -52,7 +53,7 @@ class ThirdPartyTransferRepositoryImpTest {
@Test
fun testThirdPartyTransferTemplate_Unsuccessful() = runBlocking {
val error: Response<AccountOptionsTemplate?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))
`when`(dataManager.thirdPartyTransferTemplate()).thenReturn(error)

val result = transferRepositoryImp.thirdPartyTransferTemplate()
Expand All @@ -76,7 +77,7 @@ class ThirdPartyTransferRepositoryImpTest {
@Test
fun testBeneficiaryList_Unsuccessful() = runBlocking {
val error: Response<List<Beneficiary?>?> =
Response.error(404, ResponseBody.create(null, "error"))
Response.error(404, "error".toResponseBody(null))

`when`(dataManager.beneficiaryList()).thenReturn(error)

Expand Down
Loading