-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…usecase #210 [feat] SearchUsecase 구현
- Loading branch information
Showing
7 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
13 changes: 13 additions & 0 deletions
13
domain/src/main/java/hous/release/domain/usecase/SearchRuleUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
domain/src/test/java/hous/release/domain/usecase/SearchRuleUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, " 강원용 "))) | ||
} | ||
} |