@@ -5,8 +5,6 @@ import android.os.Build
5
5
import androidx.test.core.app.ApplicationProvider
6
6
import dev.hotwire.turbo.BaseRepositoryTest
7
7
import dev.hotwire.turbo.http.TurboHttpClient
8
- import dev.hotwire.turbo.util.toObject
9
- import com.google.gson.reflect.TypeToken
10
8
import kotlinx.coroutines.Dispatchers
11
9
import kotlinx.coroutines.ExperimentalCoroutinesApi
12
10
import kotlinx.coroutines.launch
@@ -39,38 +37,49 @@ class TurboPathConfigurationRepositoryTest : BaseRepositoryTest() {
39
37
val json = repository.getRemoteConfiguration(baseUrl())
40
38
assertThat(json).isNotNull()
41
39
42
- val config = load (json)
40
+ val config = repository.parseFromJson (json!! )
43
41
assertThat(config?.rules?.size).isEqualTo(2 )
44
42
}
45
43
}
46
44
}
47
45
46
+ @Test
47
+ fun getMalformedRemoteConfiguration () {
48
+ enqueueResponse(" test-configuration-malformed.json" )
49
+
50
+ runBlocking {
51
+ launch(Dispatchers .Main ) {
52
+ val json = repository.getRemoteConfiguration(baseUrl())
53
+ assertThat(json).isNotNull()
54
+
55
+ val config = repository.parseFromJson(json!! )
56
+ assertThat(config).isNull()
57
+ }
58
+ }
59
+ }
60
+
48
61
@Test
49
62
fun getBundledAssetConfiguration () {
50
63
val json = repository.getBundledConfiguration(context, " json/test-configuration.json" )
51
64
assertThat(json).isNotNull()
52
65
53
- val config = load (json)
66
+ val config = repository.parseFromJson (json)
54
67
assertThat(config?.rules?.size).isEqualTo(10 )
55
68
}
56
69
57
70
@Test
58
71
fun getCachedConfiguration () {
59
72
val url = " https://turbo.hotwired.dev/demo/configurations/android-v1.json"
60
- val config = requireNotNull(load (json()))
73
+ val config = requireNotNull(repository.parseFromJson (json()))
61
74
repository.cacheConfigurationForUrl(context, url, config)
62
75
63
76
val json = repository.getCachedConfigurationForUrl(context, url)
64
77
assertThat(json).isNotNull()
65
78
66
- val cachedConfig = load (json)
79
+ val cachedConfig = repository.parseFromJson (json!! )
67
80
assertThat(cachedConfig?.rules?.size).isEqualTo(1 )
68
81
}
69
82
70
- private fun load (json : String? ): TurboPathConfiguration ? {
71
- return json?.toObject(object : TypeToken <TurboPathConfiguration >() {})
72
- }
73
-
74
83
private fun json (): String {
75
84
return """
76
85
{
0 commit comments