You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskScreenTest.kt
Copy file name to clipboardExpand all lines: app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/data/source/local/TaskDaoTest.kt
+55-28Lines changed: 55 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ import org.junit.runner.RunWith
34
34
@ExperimentalCoroutinesApi
35
35
@RunWith(AndroidJUnit4::class)
36
36
@SmallTest
37
-
classTasksDaoTest {
37
+
classTaskDaoTest {
38
38
39
39
// using an in-memory database because the information stored here disappears when the
40
40
// process is killed
@@ -59,11 +59,16 @@ class TasksDaoTest {
59
59
@Test
60
60
funinsertTaskAndGetById() = runTest {
61
61
// GIVEN - insert a task
62
-
val task =LocalTask(title ="title", description ="description", id ="id")
63
-
database.taskDao().insertTask(task)
62
+
val task =LocalTask(
63
+
title ="title",
64
+
description ="description",
65
+
id ="id",
66
+
isCompleted =false,
67
+
)
68
+
database.taskDao().upsert(task)
64
69
65
70
// WHEN - Get the task by id from the database
66
-
val loaded = database.taskDao().getTaskById(task.id)
71
+
val loaded = database.taskDao().getById(task.id)
67
72
68
73
// THEN - The loaded data contains the expected values
69
74
assertNotNull(loaded asLocalTask)
@@ -76,8 +81,13 @@ class TasksDaoTest {
76
81
@Test
77
82
funinsertTaskReplacesOnConflict() = runTest {
78
83
// Given that a task is inserted
79
-
val task =LocalTask(title ="title", description ="description", id ="id")
80
-
database.taskDao().insertTask(task)
84
+
val task =LocalTask(
85
+
title ="title",
86
+
description ="description",
87
+
id ="id",
88
+
isCompleted =false,
89
+
)
90
+
database.taskDao().upsert(task)
81
91
82
92
// When a task with the same id is inserted
83
93
val newTask =LocalTask(
@@ -86,10 +96,10 @@ class TasksDaoTest {
86
96
isCompleted =true,
87
97
id = task.id
88
98
)
89
-
database.taskDao().insertTask(newTask)
99
+
database.taskDao().upsert(newTask)
90
100
91
101
// THEN - The loaded data contains the expected values
92
-
val loaded = database.taskDao().getTaskById(task.id)
102
+
val loaded = database.taskDao().getById(task.id)
93
103
assertEquals(task.id, loaded?.id)
94
104
assertEquals("title2", loaded?.title)
95
105
assertEquals("description2", loaded?.description)
@@ -99,11 +109,16 @@ class TasksDaoTest {
99
109
@Test
100
110
funinsertTaskAndGetTasks() = runTest {
101
111
// GIVEN - insert a task
102
-
val task =LocalTask(title ="title", description ="description", id ="id")
103
-
database.taskDao().insertTask(task)
112
+
val task =LocalTask(
113
+
title ="title",
114
+
description ="description",
115
+
id ="id",
116
+
isCompleted =false,
117
+
)
118
+
database.taskDao().upsert(task)
104
119
105
120
// WHEN - Get tasks from the database
106
-
val tasks = database.taskDao().getTasks()
121
+
val tasks = database.taskDao().getAll()
107
122
108
123
// THEN - There is only 1 task in the database, and contains the expected values
109
124
assertEquals(1, tasks.size)
@@ -116,8 +131,14 @@ class TasksDaoTest {
116
131
@Test
117
132
funupdateTaskAndGetById() = runTest {
118
133
// When inserting a task
119
-
val originalTask =LocalTask(title ="title", description ="description", id ="id")
120
-
database.taskDao().insertTask(originalTask)
134
+
val originalTask =LocalTask(
135
+
title ="title",
136
+
description ="description",
137
+
id ="id",
138
+
isCompleted =false,
139
+
)
140
+
141
+
database.taskDao().upsert(originalTask)
121
142
122
143
// When the task is updated
123
144
val updatedTask =LocalTask(
@@ -126,10 +147,10 @@ class TasksDaoTest {
126
147
isCompleted =true,
127
148
id = originalTask.id
128
149
)
129
-
database.taskDao().updateTask(updatedTask)
150
+
database.taskDao().upsert(updatedTask)
130
151
131
152
// THEN - The loaded data contains the expected values
132
-
val loaded = database.taskDao().getTaskById(originalTask.id)
153
+
val loaded = database.taskDao().getById(originalTask.id)
Copy file name to clipboardExpand all lines: app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/statistics/StatisticsScreenTest.kt
Copy file name to clipboardExpand all lines: app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailScreenTest.kt
0 commit comments