Skip to content

Commit

Permalink
applied spotless and detekt on core:testing MIFOSAC-300 (#2261)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsPronay authored Dec 9, 2024
1 parent 63e0650 commit cf3c70c
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import androidx.paging.PagingSource
import androidx.paging.testing.TestPager
import com.mifos.core.objects.group.Group
import com.mifos.core.testing.repository.TestGroupsListRepository
import com.mifos.core.testing.repository.errorMessage
import com.mifos.core.testing.repository.ERROR_MESSAGE
import com.mifos.core.testing.repository.getPagedData
import com.mifos.core.testing.repository.sampleGroups
import com.mifos.core.testing.util.MainDispatcherRule
Expand Down Expand Up @@ -166,7 +166,7 @@ class GroupListPagingSourceTest {
val result = pager.refresh()
assertTrue(result is PagingSource.LoadResult.Error)

assertEquals(errorMessage, result.throwable.message)
assertEquals(ERROR_MESSAGE, result.throwable.message)

val page = pager.getLastLoadedPage()
assertNull(page)
Expand Down
9 changes: 9 additions & 0 deletions core/testing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifos.android.library)
alias(libs.plugins.mifos.android.library.compose)
Expand Down
9 changes: 9 additions & 0 deletions core/testing/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 Mifos Initiative
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/.
See https://github.com/openMF/android-client/blob/master/LICENSE.md
-->
<manifest>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.testing

import android.app.Application
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.testing.di

import dagger.Module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.testing.di

import com.mifos.core.common.network.Dispatcher
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.testing.repository

import com.mifos.core.data.repository.GroupsListRepository
Expand All @@ -6,14 +15,14 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.emptyFlow

const val errorMessage = "Unable to load data from server"
const val ERROR_MESSAGE = "Unable to load data from server"

class TestGroupsListRepository : GroupsListRepository {
private val data = MutableStateFlow<List<Group>?>(sampleGroups)

override suspend fun getAllGroups(paged: Boolean, offset: Int, limit: Int): List<Group> {
return if (data.value == null) {
throw RuntimeException(errorMessage)
throw RuntimeException(ERROR_MESSAGE)
} else {
data.value!!.getPagedData(offset, limit)
}
Expand Down Expand Up @@ -178,7 +187,7 @@ val sampleGroups = listOf(
id = 30,
accountNo = "ACC-030",
name = "Group 30",
)
),
)

fun <T> List<T>.getPagedData(offset: Int, limit: Int): List<T> {
Expand All @@ -191,4 +200,4 @@ fun <T> List<T>.getPagedData(offset: Int, limit: Int): List<T> {
}
val endIndex = (adjustedOffset + limit).coerceAtMost(size)
return subList(adjustedOffset, endIndex)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.testing.repository

import com.mifos.core.data.repository.SearchRepository
Expand All @@ -15,26 +24,29 @@ class TestSearchRepository : SearchRepository {
override suspend fun searchResources(
query: String,
resources: String?,
exactMatch: Boolean?
exactMatch: Boolean?,
): Flow<List<SearchedEntity>> {
return sampleResults.map { list ->
when {
query.isBlank() && resources.isNullOrBlank() -> emptyList()
else -> {
list.asSequence().filter { entity ->
(resources.isNullOrBlank() || entity.entityType.equals(
resources,
ignoreCase = true
)) && (query.isBlank() || when {
exactMatch == true -> entity.entityName.equals(query, ignoreCase = true) ||
(
resources.isNullOrBlank() || entity.entityType.equals(
resources,
ignoreCase = true,
)
) && (
query.isBlank() || when {
exactMatch == true -> entity.entityName.equals(query, ignoreCase = true) ||
entity.entityAccountNo.equals(query, ignoreCase = true) ||
entity.parentName.equals(query, true)

else -> entity.entityName?.contains(query, ignoreCase = true) == true ||
else -> entity.entityName?.contains(query, ignoreCase = true) == true ||
entity.entityAccountNo?.contains(query, ignoreCase = true) == true ||
entity.parentName?.contains(query, true) == true
}
)
}
)
}.toList()
}
}
Expand All @@ -45,4 +57,4 @@ class TestSearchRepository : SearchRepository {
fun addSampleResults(results: List<SearchedEntity>) {
sampleResults.update { results }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.testing.util

import kotlinx.coroutines.Dispatchers
Expand Down

0 comments on commit cf3c70c

Please sign in to comment.