mirror of https://github.com/readrops/Readrops.git
Improve jsonfeed items tests and fallback to current date time if it is missing
This commit is contained in:
parent
5c4cc81628
commit
6733890c16
|
@ -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": "<p>Happy Mac OS High Sierra release day everyone.</p>\n<p>I'm happy to say that there are no known issues with <a href=\"https://flyingmeat.com/acorn/\">Acorn</a> 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?</p>\n<p>I'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.</p>\n",
|
||||
"url": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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": "<p>Happy Mac OS High Sierra release day everyone.</p>\n<p>I'm happy to say that there are no known issues with <a href=\"https://flyingmeat.com/acorn/\">Acorn</a> 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?</p>\n<p>I'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.</p>\n",
|
||||
"date_published": "2017-09-25T14:27:27-07:00"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"items": [
|
||||
{
|
||||
"id": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html",
|
||||
"content_html": "<p>Happy Mac OS High Sierra release day everyone.</p>\n<p>I'm happy to say that there are no known issues with <a href=\"https://flyingmeat.com/acorn/\">Acorn</a> 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?</p>\n<p>I'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.</p>\n",
|
||||
"date_published": "2017-09-25T14:27:27-07:00",
|
||||
"url": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"items": [
|
||||
{
|
||||
"id": "http://flyingmeat.com/blog/archives/2017/9/acorn_and_10.13.html",
|
||||
"content_html": "<p>Happy Mac OS High Sierra release day everyone.</p>\n<p>I'm happy to say that there are no known issues with <a href=\"https://flyingmeat.com/acorn/\">Acorn</a> 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?</p>\n<p>I'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.</p>\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": "<p><a href=\"https://flyingmeat.com/acorn/\">Acorn 6.1 has been released</a>.</p>\n<p>You can <a href=\"http://shapeof.com/archives/2018/2/acorn_6.1_is_out.html\">read a longer post about it</a> over on Gus's blog, but the short of it is: Better, faster, smoother, stronger. And now with Metal 2 support.</p>\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": "<p>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).</p>\n<p>Today I've got a pair of minor app updates to annouce for you.</p>\n<p>First up is <a href=\"https://flyingmeat.com/acorn/\">Acorn 6.1.3</a>, which <a href=\"https://flyingmeat.com/acorn/releasenotes.html\">fixes a number of bugs</a> 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!</p>\n<p>Next up is <a href=\"https://flyingmeat.com/retrobatch/\">Retrobatch</a>, which also <a href=\"https://flyingmeat.com/retrobatch/releasenotes.html\">includes some bug fixes</a>, the beginnings of Voice Over support, performance improvements, and more.</p>\n<p>What'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.</p>\n<p>So it's going to be a busy summer, but I'm looking forward to it.</p>\n",
|
||||
"url": "http://flyingmeat.com/blog/archives/2018/6/a_pair_of_updates.html"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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] }
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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<List<Item>>() {
|
||||
|
||||
|
@ -54,7 +55,7 @@ class JSONItemsAdapter : JsonAdapter<List<Item>>() {
|
|||
4 -> contentText = reader.nextNullableString()
|
||||
5 -> description = reader.nextNullableString()
|
||||
6 -> imageLink = reader.nextNullableString()
|
||||
7 -> pubDate = DateUtils.parse(reader.nextNonEmptyString())
|
||||
7 -> pubDate = DateUtils.parse(reader.nextNullableString())
|
||||
8 -> author = parseAuthor(reader) // jsonfeed 1.0
|
||||
9 -> author = parseAuthors(reader) // jsonfeed 1.1
|
||||
else -> reader.skipValue()
|
||||
|
@ -64,6 +65,7 @@ class JSONItemsAdapter : JsonAdapter<List<Item>>() {
|
|||
|
||||
validateItem(item)
|
||||
item.content = if (contentHtml != null) contentHtml else contentText
|
||||
if (item.pubDate == null) item.pubDate = LocalDateTime.now()
|
||||
|
||||
reader.endObject()
|
||||
items += item
|
||||
|
@ -105,7 +107,6 @@ class JSONItemsAdapter : JsonAdapter<List<Item>>() {
|
|||
when {
|
||||
item.title == null -> throw ParseException("Item title is required")
|
||||
item.link == null -> throw ParseException("Item link is required")
|
||||
item.pubDate == null -> throw ParseException("Item date id required")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue