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
{{ message }}
This repository was archived by the owner on Jun 17, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: android-components/components/service/pocket/src/main/java/mozilla/components/service/pocket/stories/api/PocketJSONParser.kt
+22-11Lines changed: 22 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -33,23 +33,34 @@ internal class PocketJSONParser {
33
33
val stories = storiesJSON.mapNotNull(JSONArray::getJSONObject) { jsonToPocketApiStory(it) }
34
34
35
35
// We return null, rather than the empty list, because devs might forget to check an empty list.
36
-
if (stories.isNotEmpty()) stories elsenull
36
+
stories.ifEmpty { null }
37
37
} catch (e:JSONException) {
38
38
logger.warn("invalid JSON from the Pocket endpoint", e)
Copy file name to clipboardExpand all lines: android-components/components/service/pocket/src/test/java/mozilla/components/service/pocket/helpers/PocketTestResources.kt
+13-1Lines changed: 13 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -18,14 +18,26 @@ private const val POCKET_DIR = "pocket"
Copy file name to clipboardExpand all lines: android-components/components/service/pocket/src/test/java/mozilla/components/service/pocket/stories/api/PocketJSONParserTest.kt
+31-7Lines changed: 31 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ class PocketJSONParserTest {
35
35
@Test
36
36
fun`GIVEN PocketJSONParser WHEN parsing valid stories recommendations THEN PocketApiStories are returned`() {
37
37
val expectedStories =PocketTestResources.apiExpectedPocketStoriesRecommendations
38
-
val pocketJSON =PocketTestResources.pocketEndointFiveStoriesResponse
38
+
val pocketJSON =PocketTestResources.pocketEndpointFiveStoriesResponse
39
39
val actualStories = parser.jsonToPocketApiStories(pocketJSON)
40
40
41
41
assertNotNull(actualStories)
@@ -45,7 +45,7 @@ class PocketJSONParserTest {
45
45
46
46
@Test
47
47
fun`WHEN parsing stories recommendations with missing titles THEN those entries are dropped`() {
48
-
val pocketJSON =PocketTestResources.pocketEndointFiveStoriesResponse
48
+
val pocketJSON =PocketTestResources.pocketEndpointFiveStoriesResponse
49
49
val expectedStoriesIfMissingTitle =ArrayList(PocketTestResources.apiExpectedPocketStoriesRecommendations)
50
50
.apply { removeAt(4) }
51
51
val pocketJsonWithMissingTitle = removeJsonFieldFromArrayIndex("title", 4, pocketJSON)
0 commit comments