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

refactor: applied spotless and detekt on core:testing #2261

Merged
merged 1 commit into from
Dec 9, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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 @@ -158,7 +158,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
Loading