@@ -20,6 +20,7 @@ import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
20
20
import com.google.samples.apps.nowinandroid.core.model.data.Topic
21
21
import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource
22
22
import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic
23
+ import com.google.samples.apps.nowinandroid.core.network.model.asExternalModel
23
24
import kotlinx.datetime.Instant
24
25
import org.junit.Test
25
26
import kotlin.test.assertEquals
@@ -69,6 +70,29 @@ class NetworkEntityTest {
69
70
assertEquals(" Article 📚" , entity.type)
70
71
}
71
72
73
+ @Test
74
+ fun networkTopicMapsToExternalModel () {
75
+ val networkTopic = NetworkTopic (
76
+ id = " 0" ,
77
+ name = " Test" ,
78
+ shortDescription = " short description" ,
79
+ longDescription = " long description" ,
80
+ url = " URL" ,
81
+ imageUrl = " imageUrl"
82
+ )
83
+
84
+ val expected = Topic (
85
+ id = " 0" ,
86
+ name = " Test" ,
87
+ shortDescription = " short description" ,
88
+ longDescription = " long description" ,
89
+ url = " URL" ,
90
+ imageUrl = " imageUrl" ,
91
+ )
92
+
93
+ assertEquals(expected, networkTopic.asExternalModel())
94
+ }
95
+
72
96
@Test
73
97
fun networkNewsResourceMapsToExternalModel () {
74
98
val networkNewsResource = NetworkNewsResource (
@@ -109,24 +133,7 @@ class NetworkEntityTest {
109
133
headerImageUrl = " headerImageUrl" ,
110
134
publishDate = Instant .fromEpochMilliseconds(1 ),
111
135
type = " Article 📚" ,
112
- topics = listOf (
113
- Topic (
114
- id = " 1" ,
115
- name = " Test 1" ,
116
- shortDescription = " short description 1" ,
117
- longDescription = " long description 1" ,
118
- url = " url 1" ,
119
- imageUrl = " imageUrl 1" ,
120
- ),
121
- Topic (
122
- id = " 2" ,
123
- name = " Test 2" ,
124
- shortDescription = " short description 2" ,
125
- longDescription = " long description 2" ,
126
- url = " url 2" ,
127
- imageUrl = " imageUrl 2" ,
128
- ),
129
- ),
136
+ topics = networkTopics.map(NetworkTopic ::asExternalModel),
130
137
)
131
138
assertEquals(expected, networkNewsResource.asExternalModel(networkTopics))
132
139
}
0 commit comments