File tree Expand file tree Collapse file tree 7 files changed +17
-25
lines changed
Task-Tracker-Usecases/src
commonMain/kotlin/com/garbereder/tasktracker/usecases
commonTest/kotlin/com/garbereder/tasktracker/usecases/tasks Expand file tree Collapse file tree 7 files changed +17
-25
lines changed Original file line number Diff line number Diff line change 1
1
package com.garbereder.tasktracker.usecases
2
2
3
- interface UseCase {
4
- fun invoke ()
3
+ interface UseCase < out T > {
4
+ fun invoke (): T
5
5
}
Original file line number Diff line number Diff line change @@ -4,6 +4,6 @@ import com.garbereder.tasktracker.entities.Task
4
4
import com.garbereder.tasktracker.entities.TaskCollection
5
5
import com.garbereder.tasktracker.usecases.UseCase
6
6
7
- class AddTask constructor(private val collection : TaskCollection , private val task : Task ) : UseCase {
8
- override fun invoke () = collection.add(task )
7
+ class AddTask constructor(private val collection : TaskCollection , private val taskName : String ) : UseCase<Unit> {
8
+ override fun invoke () = collection.add(Task ( " ${collection.size() + 1 } " , taskName) )
9
9
}
Original file line number Diff line number Diff line change @@ -3,12 +3,6 @@ package com.garbereder.tasktracker.usecases.tasks
3
3
import com.garbereder.tasktracker.entities.TaskCollection
4
4
import com.garbereder.tasktracker.usecases.UseCase
5
5
6
- class LoadTasks (private val reader : TaskCollectionReader ) : UseCase {
7
-
8
- lateinit var tasks: TaskCollection
9
-
10
- override fun invoke () {
11
- tasks = this .reader.read()
12
- }
13
-
6
+ class LoadTasks (private val reader : TaskCollectionReader ) : UseCase<TaskCollection> {
7
+ override fun invoke (): TaskCollection = this .reader.read()
14
8
}
Original file line number Diff line number Diff line change @@ -4,6 +4,6 @@ import com.garbereder.tasktracker.entities.Task
4
4
import com.garbereder.tasktracker.entities.TaskCollection
5
5
import com.garbereder.tasktracker.usecases.UseCase
6
6
7
- class RemoveTask (private val collection : TaskCollection , private val task : Task ): UseCase {
7
+ class RemoveTask (private val collection : TaskCollection , private val task : Task ): UseCase<Unit> {
8
8
override fun invoke () = collection.remove(task)
9
9
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -5,18 +5,22 @@ import com.garbereder.tasktracker.entities.TaskCollection
5
5
import io.mockative.*
6
6
import kotlin.test.*
7
7
8
- class AddTaskTes {
8
+ class AddTaskTests {
9
9
@Mock
10
10
val collection = mock(classOf<TaskCollection >())
11
11
12
12
@Test
13
13
fun invoke_noInput_callsThrough () {
14
- val task = Task (" TaskId " , " TaskName" )
14
+ val task = Task (" 1 " , " TaskName" )
15
15
given(collection).invocation { add(task) }
16
16
.thenDoNothing()
17
+ given(collection).invocation { size() }
18
+ .then { 0 }
17
19
18
- AddTask (collection, task ).invoke()
20
+ AddTask (collection, " TaskName " ).invoke()
19
21
22
+ verify(collection).invocation { size() }
23
+ .wasInvoked(exactly = once)
20
24
verify(collection).invocation { add(task) }
21
25
.wasInvoked(exactly = once)
22
26
}
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import com.garbereder.tasktracker.entities.TaskCollection
5
5
import com.garbereder.tasktracker.usecases.UseCase
6
6
import io.mockative.*
7
7
import kotlin.test.Test
8
+ import kotlin.test.assertEquals
8
9
import kotlin.test.assertNotNull
9
10
import kotlin.test.assertTrue
10
11
@@ -18,7 +19,8 @@ class LoadTasksTests {
18
19
given(reader).invocation { read() }
19
20
.then { collection }
20
21
21
- LoadTasks (reader).invoke()
22
+ val col = LoadTasks (reader).invoke()
23
+ assertEquals(collection, col)
22
24
23
25
verify(reader).invocation { read() }
24
26
.wasInvoked(exactly = once)
You can’t perform that action at this time.
0 commit comments