Skip to content

Commit 8c3ba55

Browse files
committed
Merge branch 'release/1.4.15'
2 parents 5e914f3 + 69f92ee commit 8c3ba55

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

pam-android-kotlin/src/main/java/ai/pams/android/kotlin/models/notification/NotificationIist.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ai.pams.android.kotlin.models.notification
22

33
import ai.pams.android.kotlin.utils.DateUtils
44
import android.content.Context
5+
import org.json.JSONException
56
import org.json.JSONObject
67

78
class NotificationList(
@@ -19,7 +20,14 @@ class NotificationList(
1920
val noti = NotificationList();
2021
val list = mutableListOf<NotificationItem>()
2122

22-
val json = JSONObject(jsonString)
23+
var json:JSONObject?
24+
try {
25+
json = JSONObject(jsonString)
26+
}catch(e: JSONException){
27+
noti.items = listOf()
28+
return noti
29+
}
30+
2331
val itemsArray = json.optJSONArray("items")
2432
val count = itemsArray?.length() ?: 0
2533
for(i in 0 until count){
@@ -34,7 +42,7 @@ class NotificationList(
3442
val iterator = jsonPayload?.keys()
3543
while(iterator?.hasNext() == true){
3644
val key = iterator.next()
37-
jsonPayload?.get(key)?.let{ data ->
45+
jsonPayload?.opt(key)?.let{ data->
3846
payload[key] = data
3947
}
4048
}

pam-android-kotlin/src/test/java/ai/pams/android/kotlin/ExampleUnitTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package ai.pams.android.kotlin
22

3+
import ai.pams.android.kotlin.models.notification.NotificationList
34
import ai.pams.android.kotlin.utils.DateUtils
5+
import android.content.Context
6+
import androidx.test.platform.app.InstrumentationRegistry
47
import org.junit.Assert.*
8+
import org.junit.Before
59
import org.junit.Test
610
import org.junit.runner.RunWith
711
import org.robolectric.RobolectricTestRunner
@@ -13,10 +17,22 @@ import org.robolectric.RobolectricTestRunner
1317
*/
1418
@RunWith(RobolectricTestRunner::class)
1519
class ExampleUnitTest {
20+
lateinit var instrumentationContext: Context
21+
22+
@Before
23+
fun setup() {
24+
instrumentationContext = InstrumentationRegistry.getInstrumentation().context
25+
}
26+
1627
@Test
1728
fun testParseDate() {
1829
val str = "2022-06-29 03:53:51"
1930
val date = DateUtils.localDateTimeFromString(str)
2031
assertEquals(date.hour, 10)
2132
}
33+
34+
@Test
35+
fun testNotificationJSONError(){
36+
NotificationList.parse("<some html>", instrumentationContext)
37+
}
2238
}

0 commit comments

Comments
 (0)