-
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.
- Loading branch information
Souleymane Sidibe
committed
Aug 14, 2021
1 parent
bdbcc88
commit ff93a60
Showing
6 changed files
with
84 additions
and
7 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
45 changes: 45 additions & 0 deletions
45
domain/src/test/kotlin/com/soulesidibe/domain/GetTodoUseCaseTest.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,45 @@ | ||
package com.soulesidibe.domain | ||
|
||
import com.soulesidibe.domain.entity.TodoEntity | ||
import com.soulesidibe.domain.exception.NoTodoFoundException | ||
import com.soulesidibe.domain.repository.TodoRepository | ||
import junit.framework.TestCase.assertEquals | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.runBlockingTest | ||
import org.junit.Test | ||
import org.mockito.Mockito.`when` | ||
import org.mockito.Mockito.mock | ||
|
||
@ExperimentalCoroutinesApi | ||
class GetTodoUseCaseTest { | ||
|
||
@Test | ||
fun `should get a todo`() = runBlockingTest { | ||
val fakeId = "12345" | ||
val repository = mock(TodoRepository::class.java) | ||
`when`(repository.byId(fakeId)).thenReturn(TodoEntity("12345", "Test")) | ||
|
||
val usecase = GetTodoUseCase(repository) | ||
|
||
val response = usecase.execute(fakeId) | ||
assertEquals( | ||
Response.success(TodoEntity("12345", "Test")), | ||
response | ||
) | ||
} | ||
|
||
@Test | ||
fun `should get an error when no todo id do no exist`() = runBlockingTest { | ||
val fakeId = "12345" | ||
val repository = mock(TodoRepository::class.java) | ||
`when`(repository.byId(fakeId)).thenReturn(null) | ||
|
||
val usecase = GetTodoUseCase(repository) | ||
|
||
val response = usecase.execute(fakeId) | ||
assertEquals( | ||
Response.failure<NoTodoFoundException>(NoTodoFoundException), | ||
response | ||
) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
domain/src/test/kotlin/com/soulesidibe/domain/RemoveTodoUseCaseTest.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,38 @@ | ||
package com.soulesidibe.domain | ||
|
||
import com.soulesidibe.domain.entity.TodoEntity | ||
import com.soulesidibe.domain.exception.NoTodoFoundException | ||
import com.soulesidibe.domain.repository.TodoRepository | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.runBlockingTest | ||
import org.junit.Assert.* | ||
import org.junit.Test | ||
import org.mockito.Mockito.`when` | ||
import org.mockito.Mockito.mock | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class RemoveTodoUseCaseTest { | ||
|
||
|
||
@Test | ||
fun `should remove the todo if exsist`() = runBlockingTest { | ||
val repository = mock(TodoRepository::class.java) | ||
`when`(repository.byId("12345")).thenReturn(TodoEntity("12345", "test")) | ||
`when`(repository.remove(TodoEntity("12345", "test"))).thenReturn(true) | ||
|
||
|
||
val usecase = RemoveTodoUseCase(repository) | ||
val response = usecase.execute("12345") | ||
assertEquals(Response.success(true), response) | ||
} | ||
|
||
@Test | ||
fun `should not remove the todo if not exsist`() = runBlockingTest { | ||
val repository = mock(TodoRepository::class.java) | ||
`when`(repository.byId("12345")).thenReturn(null) | ||
|
||
val usecase = RemoveTodoUseCase(repository) | ||
val response = usecase.execute("12345") | ||
assertEquals(Response.Error<NoTodoFoundException>(NoTodoFoundException), response) | ||
} | ||
} |