@@ -20,6 +20,7 @@ import com.google.samples.apps.nowinandroid.core.model.data.NewsResource
2020import com.google.samples.apps.nowinandroid.core.model.data.Topic
2121import com.google.samples.apps.nowinandroid.core.network.model.NetworkNewsResource
2222import com.google.samples.apps.nowinandroid.core.network.model.NetworkTopic
23+ import com.google.samples.apps.nowinandroid.core.network.model.asExternalModel
2324import kotlinx.datetime.Instant
2425import org.junit.Test
2526import kotlin.test.assertEquals
@@ -69,6 +70,29 @@ class NetworkEntityTest {
6970 assertEquals(" Article 📚" , entity.type)
7071 }
7172
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+
7296 @Test
7397 fun networkNewsResourceMapsToExternalModel () {
7498 val networkNewsResource = NetworkNewsResource (
@@ -109,24 +133,7 @@ class NetworkEntityTest {
109133 headerImageUrl = " headerImageUrl" ,
110134 publishDate = Instant .fromEpochMilliseconds(1 ),
111135 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),
130137 )
131138 assertEquals(expected, networkNewsResource.asExternalModel(networkTopics))
132139 }
0 commit comments