Skip to content

Commit

Permalink
Merge pull request #214 from Hous-Release/feature/#210-create-search-…
Browse files Browse the repository at this point in the history
…usecase

#210 [feat] SearchUsecase 구현
  • Loading branch information
KWY0218 authored May 28, 2023
2 parents 1080dd9 + dbca120 commit 10f1dab
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ plugins {
id("androidx.navigation.safeargs.kotlin")
}

tasks.withType<Test> {
useJUnitPlatform()
}

val properties = Properties()
properties.load(project.rootProject.file("local.properties").inputStream())
android {
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/java/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ object Deps {
const val junit5ParameterizedTest = "org.junit.jupiter:junit-jupiter-params:${junit5Ver}"
const val junit4 = "junit:junit:4.13.2"
const val junit4Engine = "org.junit.vintage:junit-vintage-engine:${junit5Ver}"
const val thruth = "com.google.truth:truth:1.1.3"

private const val mockkVer = "1.13.3"
const val mockk = "io.mockk:mockk:${mockkVer}"
Expand All @@ -122,6 +123,7 @@ fun DependencyHandlerScope.testImplementation() {
"testRuntimeOnly"(junit4Engine)
"testImplementation"(mockk)
"testImplementation"(kotlin)
"testImplementation"(thruth)
}
"testImplementation"(Deps.Coroutines.test)
}
Expand Down
5 changes: 5 additions & 0 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ android {
}
}

tasks.withType<Test> {
useJUnitPlatform()
}

dependencies {
implementation(project(":domain"))

Expand Down Expand Up @@ -65,6 +69,7 @@ dependencies {
implementation(platform(firebaseBom))
implementation(firebaseMessaging)
}
testImplementation()
}

ktlint {
Expand Down
5 changes: 5 additions & 0 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ plugins {
id("org.jlleitschuh.gradle.ktlint") version ktlintVersion
}

tasks.withType<Test> {
useJUnitPlatform()
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -20,6 +24,7 @@ dependencies {
implementation(core)
implementation(android)
}
testImplementation()
}

ktlint {
Expand Down
6 changes: 6 additions & 0 deletions domain/src/main/java/hous/release/domain/entity/Rule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package hous.release.domain.entity

abstract class Rule(
open val id: Int,
open val name: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package hous.release.domain.usecase

import hous.release.domain.entity.Rule
import javax.inject.Inject

class SearchRuleUseCase @Inject constructor() {
operator fun invoke(search: String, rules: List<Rule>): List<Rule> {
val clear = search.lowercase().trim()
return rules.filter {
it.name.lowercase().trim().contains(clear)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package hous.release.domain.usecase

import com.google.common.truth.Truth.assertThat
import hous.release.domain.entity.Rule
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test

internal class SearchRuleUseCaseTest {

data class MainTodo(
val isNew: Boolean,
override val id: Int,
override val name: String
) : Rule(id, name)

private val searchUseCase = SearchRuleUseCase()

@Test
@DisplayName("영어 rule name 반환")
fun useCaseTest() {
// given
val expectList =
listOf(MainTodo(true, 1, "KWY"), MainTodo(true, 2, "KWY2"), MainTodo(true, 1, "LJW"))
// when
val result: List<MainTodo> = searchUseCase("kw", expectList).filterIsInstance<MainTodo>()
// then
assertThat(result).isEqualTo(listOf(MainTodo(true, 1, "KWY"), MainTodo(true, 2, "KWY2")))
}

@Test
@DisplayName("한국 rule name 반환")
fun useCaseTest2() {
// given
val expectList = listOf(
MainTodo(true, 1, " 강원용 "),
MainTodo(true, 2, "깡원용"),
MainTodo(true, 1, "ㄱ ㅏ ㅇ ㅜ ㅓ ㅇ ㅛㅇ ")
)
// when
val result: List<MainTodo> = searchUseCase("", expectList).filterIsInstance<MainTodo>()
// then
assertThat(result).isEqualTo(listOf(MainTodo(true, 1, " 강원용 ")))
}
}

0 comments on commit 10f1dab

Please sign in to comment.