diff --git a/api/src/androidTest/assets/localfeed/json/json_items_no_date.json b/api/src/androidTest/assets/localfeed/json/json_items_no_date.json new file mode 100644 index 00000000..ce9aa1fc --- /dev/null +++ b/api/src/androidTest/assets/localfeed/json/json_items_no_date.json @@ -0,0 +1,10 @@ +{ + "items": [ + { + "id": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html", + "title": "Acorn and 10.13", + "content_html": "
Happy Mac OS High Sierra release day everyone.
\nI'm happy to say that there are no known issues with Acorn 6.0.3 or Acorn 5.6.6 when running on Mac OS 10.13 High Sierra. In fact, you might even notice that some things are actually faster and it can now open HEIF images. How awesome is that?
\nI'm also working on some 10.13 goodies for Acorn 6 folks later this year. I can't wait to share that with you, but you'll have to wait just a little bit.
\n", + "url": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html" + } + ] +} \ No newline at end of file diff --git a/api/src/androidTest/assets/localfeed/json/json_items_no_link.json b/api/src/androidTest/assets/localfeed/json/json_items_no_link.json new file mode 100644 index 00000000..e23377e6 --- /dev/null +++ b/api/src/androidTest/assets/localfeed/json/json_items_no_link.json @@ -0,0 +1,10 @@ +{ + "items": [ + { + "id": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html", + "title": "Acorn and 10.13", + "content_html": "Happy Mac OS High Sierra release day everyone.
\nI'm happy to say that there are no known issues with Acorn 6.0.3 or Acorn 5.6.6 when running on Mac OS 10.13 High Sierra. In fact, you might even notice that some things are actually faster and it can now open HEIF images. How awesome is that?
\nI'm also working on some 10.13 goodies for Acorn 6 folks later this year. I can't wait to share that with you, but you'll have to wait just a little bit.
\n", + "date_published": "2017-09-25T14:27:27-07:00" + } + ] +} \ No newline at end of file diff --git a/api/src/androidTest/assets/localfeed/json/json_items_no_title.json b/api/src/androidTest/assets/localfeed/json/json_items_no_title.json new file mode 100644 index 00000000..e63cae47 --- /dev/null +++ b/api/src/androidTest/assets/localfeed/json/json_items_no_title.json @@ -0,0 +1,10 @@ +{ + "items": [ + { + "id": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html", + "content_html": "Happy Mac OS High Sierra release day everyone.
\nI'm happy to say that there are no known issues with Acorn 6.0.3 or Acorn 5.6.6 when running on Mac OS 10.13 High Sierra. In fact, you might even notice that some things are actually faster and it can now open HEIF images. How awesome is that?
\nI'm also working on some 10.13 goodies for Acorn 6 folks later this year. I can't wait to share that with you, but you'll have to wait just a little bit.
\n", + "date_published": "2017-09-25T14:27:27-07:00", + "url": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html" + } + ] +} \ No newline at end of file diff --git a/api/src/androidTest/assets/localfeed/json/json_items_required_elements.json b/api/src/androidTest/assets/localfeed/json/json_items_required_elements.json deleted file mode 100644 index f46aa9a1..00000000 --- a/api/src/androidTest/assets/localfeed/json/json_items_required_elements.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "items": [ - { - "id": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html", - "content_html": "Happy Mac OS High Sierra release day everyone.
\nI'm happy to say that there are no known issues with Acorn 6.0.3 or Acorn 5.6.6 when running on Mac OS 10.13 High Sierra. In fact, you might even notice that some things are actually faster and it can now open HEIF images. How awesome is that?
\nI'm also working on some 10.13 goodies for Acorn 6 folks later this year. I can't wait to share that with you, but you'll have to wait just a little bit.
\n", - "date_published": "2017-09-25T14:27:27-07:00", - "url": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html" - }, - { - "id": "http://flyingmeat.com/blog/archives/2018/2/acorn_6.1_is_out.html", - "title": "Acorn 6.1 Is Out", - "content_html": "\nYou can read a longer post about it over on Gus's blog, but the short of it is: Better, faster, smoother, stronger. And now with Metal 2 support.
\n", - "date_published": "2018-02-16T09:59:11-08:00", - }, - { - "id": "http://flyingmeat.com/blog/archives/2018/6/a_pair_of_updates.html", - "title": "A Pair of Updates", - "content_html": "Happy summer solstice everybody! (at least for folks in the northern hemisphere, and for folks in the south… sorry. It's going to start getting brighter for you though).
\nToday I've got a pair of minor app updates to annouce for you.
\nFirst up is Acorn 6.1.3, which fixes a number of bugs including one that stemmed from trying to use QuickLook on a file that was created with Acorn 1.0. For the one or two of you that this was affecting, hurray!
\nNext up is Retrobatch, which also includes some bug fixes, the beginnings of Voice Over support, performance improvements, and more.
\nWhat's next for these apps? Work on Acorn 6.2 will begin shortly, as will Retrobatch 1.1. WWDC introduced some great new APIs that I want to take advantage of (cool new machine learning things), so that'll be a focus- as well as Dark Mode for Acorn and one other major thing I've got planned. Retrobatch will probably also get the Dark Mode treatment, but not until I've done it for Acorn first.
\nSo it's going to be a busy summer, but I'm looking forward to it.
\n", - "url": "http://flyingmeat.com/blog/archives/2018/6/a_pair_of_updates.html" - } - ] -} \ No newline at end of file diff --git a/api/src/androidTest/java/com/readrops/api/localfeed/json/JSONItemsAdapterTest.kt b/api/src/androidTest/java/com/readrops/api/localfeed/json/JSONItemsAdapterTest.kt index 474ecbff..3d62a836 100644 --- a/api/src/androidTest/java/com/readrops/api/localfeed/json/JSONItemsAdapterTest.kt +++ b/api/src/androidTest/java/com/readrops/api/localfeed/json/JSONItemsAdapterTest.kt @@ -8,8 +8,7 @@ import com.readrops.api.utils.ParseException import com.readrops.db.entities.Item import com.squareup.moshi.Moshi import com.squareup.moshi.Types -import junit.framework.TestCase.assertEquals -import junit.framework.TestCase.assertNotNull +import junit.framework.TestCase.* import okio.Buffer import org.junit.Assert import org.junit.Test @@ -31,7 +30,7 @@ class JSONItemsAdapterTest { val stream = context.resources.assets.open("localfeed/json/json_feed.json") val items = adapter.fromJson(Buffer().readFrom(stream))!! - val item = items[0] + val item = items.first() assertEquals(items.size, 10) assertEquals(item.guid, "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html") @@ -46,7 +45,7 @@ class JSONItemsAdapterTest { fun otherCasesTest() { val stream = context.resources.assets.open("localfeed/json/json_items_other_cases.json") - val item = adapter.fromJson(Buffer().readFrom(stream))!![0] + val item = adapter.fromJson(Buffer().readFrom(stream))!!.first() assertEquals(item.description, "This is a summary") assertEquals(item.content, "content_html") @@ -55,23 +54,27 @@ class JSONItemsAdapterTest { } @Test - fun nullTitleTest() { - val stream = context.resources.assets.open("localfeed/json/json_items_required_elements.json") + fun nullDateTest() { + val stream = context.resources.assets.open("localfeed/json/json_items_no_date.json") - Assert.assertThrows("Item title is required", ParseException::class.java) { adapter.fromJson(Buffer().readFrom(stream))!![0] } + val item = adapter.fromJson(Buffer().readFrom(stream))!!.first() + assertNotNull(item.pubDate) + } + + @Test + fun nullTitleTest() { + val stream = context.resources.assets.open("localfeed/json/json_items_no_title.json") + + val exception = Assert.assertThrows(ParseException::class.java) { adapter.fromJson(Buffer().readFrom(stream)) } + assertTrue(exception.message!!.contains("Item title is required")) } @Test fun nullLinkTest() { - val stream = context.resources.assets.open("localfeed/json/json_items_required_elements.json") + val stream = context.resources.assets.open("localfeed/json/json_items_no_link.json") - Assert.assertThrows("Item link is required", ParseException::class.java) { adapter.fromJson(Buffer().readFrom(stream))!![1] } + val exception = Assert.assertThrows(ParseException::class.java) { adapter.fromJson(Buffer().readFrom(stream)) } + assertTrue(exception.message!!.contains("Item link is required")) } - @Test - fun nullDateTest() { - val stream = context.resources.assets.open("localfeed/json/json_items_required_elements.json") - - Assert.assertThrows("Item date is required", ParseException::class.java) { adapter.fromJson(Buffer().readFrom(stream))!![2] } - } } \ No newline at end of file diff --git a/api/src/main/java/com/readrops/api/localfeed/json/JSONFeedAdapter.kt b/api/src/main/java/com/readrops/api/localfeed/json/JSONFeedAdapter.kt index 772caeec..81ff0828 100644 --- a/api/src/main/java/com/readrops/api/localfeed/json/JSONFeedAdapter.kt +++ b/api/src/main/java/com/readrops/api/localfeed/json/JSONFeedAdapter.kt @@ -15,7 +15,7 @@ class JSONFeedAdapter { @FromJson fun fromJson(reader: JsonReader): Feed { - try { + return try { val feed = Feed() reader.beginObject() @@ -32,7 +32,7 @@ class JSONFeedAdapter { } reader.endObject() - return feed + feed } catch (e: Exception) { throw ParseException(e.message) } diff --git a/api/src/main/java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt b/api/src/main/java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt index 6dcdc239..e209ff3f 100644 --- a/api/src/main/java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt +++ b/api/src/main/java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt @@ -9,6 +9,7 @@ import com.readrops.db.entities.Item import com.squareup.moshi.JsonAdapter import com.squareup.moshi.JsonReader import com.squareup.moshi.JsonWriter +import org.joda.time.LocalDateTime class JSONItemsAdapter : JsonAdapter