diff --git a/example/src/test/java/org/wordpress/android/fluxc/common/CommentsMapperTest.kt b/example/src/test/java/org/wordpress/android/fluxc/common/CommentsMapperTest.kt index 06f654c98f9..2ad7d10fecb 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/common/CommentsMapperTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/common/CommentsMapperTest.kt @@ -43,7 +43,10 @@ class CommentsMapperTest { @Test fun `xmlrpc dto list is converted to entity list`() { - val commentList = getDefaultCommentList(false).map { it.copy(id = 0, authorProfileImageUrl = null) } + val commentList = getDefaultCommentList(false).map { it.copy( + id = 0, + authorProfileImageUrl = null + ) } val site = SiteModel().apply { id = commentList.first().localSiteId selfHostedSiteId = commentList.first().remoteSiteId @@ -120,27 +123,27 @@ class CommentsMapperTest { val entity = this return CommentWPComRestResponse().apply { ID = entity.remoteCommentId - URL = entity.url + URL = entity.url ?: "" author = Author().apply { ID = entity.authorId - URL = entity.authorUrl - avatar_URL = entity.authorProfileImageUrl - email = entity.authorEmail - name = entity.authorName + URL = entity.authorUrl ?: "" + avatar_URL = entity.authorProfileImageUrl ?: "" + email = entity.authorEmail ?: "" + name = entity.authorName ?: "" } - content = entity.content - date = entity.datePublished + content = entity.content ?: "" + date = entity.datePublished ?: "" i_like = entity.iLike parent = CommentParent().apply { ID = entity.parentId } post = Post().apply { type = "post" - title = entity.postTitle + title = entity.postTitle ?: "" link = "https://public-api.wordpress.com/rest/v1.1/sites/185464053/posts/85" ID = entity.remotePostId } - status = entity.status + status = entity.status ?: "" } } @@ -188,22 +191,22 @@ class CommentsMapperTest { private fun getDefaultComment(allowNulls: Boolean): CommentEntity { return CommentEntity( - id = 0, - remoteCommentId = 10, - remotePostId = 100, - authorId = 44, + id = 0L, + remoteCommentId = 10L, + remotePostId = 100L, + authorId = 44L, localSiteId = 10_000, - remoteSiteId = 100_000, - authorUrl = if (allowNulls) null else "https://test-debug-site.wordpress.com", - authorName = if (allowNulls) null else "authorname", - authorEmail = if (allowNulls) null else "email@wordpress.com", - authorProfileImageUrl = if (allowNulls) null else "https://gravatar.com/avatar/111222333", - postTitle = if (allowNulls) null else "again", + remoteSiteId = 100_000L, + authorUrl = if (allowNulls) "" else "https://test-debug-site.wordpress.com", + authorName = if (allowNulls) "" else "authorname", + authorEmail = if (allowNulls) "" else "email@wordpress.com", + authorProfileImageUrl = if (allowNulls) "" else "https://gravatar.com/avatar/111222333", + postTitle = if (allowNulls) "" else "again", status = APPROVED.toString(), - datePublished = if (allowNulls) null else "2021-05-12T15:10:40+02:00", + datePublished = if (allowNulls) "" else "2021-05-12T15:10:40+02:00", publishedTimestamp = 1_000_000, - content = if (allowNulls) null else "content example", - url = if (allowNulls) null else "https://test-debug-site.wordpress.com/2021/02/25/again/#comment-137", + content = if (allowNulls) "" else "content example", + url = if (allowNulls) "" else "https://test-debug-site.wordpress.com/2021/02/25/again/#comment-137", hasParent = true, parentId = 1_000L, iLike = false @@ -213,10 +216,10 @@ class CommentsMapperTest { private fun getDefaultCommentList(allowNulls: Boolean): CommentEntityList { val comment = getDefaultComment(allowNulls) return listOf( - comment.copy(id = 1, remoteCommentId = 10, datePublished = "2021-07-24T00:51:43+02:00"), - comment.copy(id = 2, remoteCommentId = 20, datePublished = "2021-07-24T00:51:43+02:00"), - comment.copy(id = 3, remoteCommentId = 30, datePublished = "2021-07-24T00:51:43+02:00"), - comment.copy(id = 4, remoteCommentId = 40, datePublished = "2021-07-24T00:51:43+02:00") + comment.copy(id = 1L, remoteCommentId = 10L, datePublished = "2021-07-24T00:51:43+02:00"), + comment.copy(id = 2L, remoteCommentId = 20L, datePublished = "2021-07-24T00:51:43+02:00"), + comment.copy(id = 3L, remoteCommentId = 30L, datePublished = "2021-07-24T00:51:43+02:00"), + comment.copy(id = 4L, remoteCommentId = 40L, datePublished = "2021-07-24T00:51:43+02:00") ) } } diff --git a/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/comments/CommentsRestClientTest.kt b/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/comments/CommentsRestClientTest.kt index aa712967d08..e7fd5cd663f 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/comments/CommentsRestClientTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/comments/CommentsRestClientTest.kt @@ -96,7 +96,7 @@ class CommentsRestClientTest { assertThat(payload.isError).isFalse val comments = payload.response!! - assertThat(comments.size).isEqualTo(commentsResponse.comments.size) + assertThat(comments.size).isEqualTo(commentsResponse.comments?.size) assertThat(urlCaptor.lastValue).isEqualTo( "https://public-api.wordpress.com/rest/v1.1/sites/${site.siteId}/comments/" ) @@ -600,10 +600,10 @@ class CommentsRestClientTest { private fun getDefaultDto(): CommentWPComRestResponse { return CommentWPComRestResponse().apply { - ID = 137 + ID = 137L URL = "https://test-site.wordpress.com/2021/02/25/again/#comment-137" author = Author().apply { - ID = 0 + ID = 0L URL = "https://debugging-test.wordpress.com" avatar_URL = "https://gravatar.com/avatar/avatarurl" email = "email@mydomain.com" @@ -612,9 +612,9 @@ class CommentsRestClientTest { content = "example content" date = "2021-05-12T15:10:40+02:00" i_like = true - parent = CommentParent().apply { ID = 41 } + parent = CommentParent().apply { ID = 41L } post = Post().apply { - ID = 85 + ID = 85L link = "https://public-api.wordpress.com/rest/v1.1/sites/11111111/posts/85" title = "again" type = "post" @@ -627,31 +627,31 @@ class CommentsRestClientTest { return CommentLikeWPComRestResponse().apply { success = true i_like = iLike - like_count = 100 + like_count = 100L } } private fun CommentWPComRestResponse.toEntity(): CommentEntity { val dto = this return CommentEntity( - id = 0, + id = 0L, remoteCommentId = dto.ID, - remotePostId = dto.post.ID, - authorId = dto.author.ID, + remotePostId = dto.post?.ID ?: 0L, + authorId = dto.author?.ID ?: 0L, localSiteId = 10, - remoteSiteId = 200, - authorUrl = dto.author.URL, - authorName = dto.author.name, - authorEmail = dto.author.email, - authorProfileImageUrl = dto.author.avatar_URL, - postTitle = dto.post.title, + remoteSiteId = 200L, + authorUrl = dto.author?.URL, + authorName = dto.author?.name, + authorEmail = dto.author?.email, + authorProfileImageUrl = dto.author?.avatar_URL, + postTitle = dto.post?.title, status = dto.status, datePublished = dto.date, - publishedTimestamp = 132456, + publishedTimestamp = 132456L, content = dto.content, url = dto.URL, hasParent = dto.parent != null, - parentId = dto.parent.ID, + parentId = dto.parent?.ID ?: 0L, iLike = dto.i_like ) } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/comments/CommentsMapper.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/model/comments/CommentsMapper.kt index 9d30630cb46..1cf142805c4 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/comments/CommentsMapper.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/comments/CommentsMapper.kt @@ -37,7 +37,7 @@ class CommentsMapper @Inject constructor( } }, authorProfileImageUrl = commentDto.author?.avatar_URL, - remotePostId = commentDto.post?.ID ?: 0, + remotePostId = commentDto.post?.ID ?: 0L, postTitle = StringEscapeUtils.unescapeHtml4(commentDto.post?.title), status = commentDto.status, datePublished = commentDto.date, @@ -46,7 +46,7 @@ class CommentsMapper @Inject constructor( url = commentDto.URL, authorId = commentDto.author?.ID ?: 0L, hasParent = commentDto.parent != null, - parentId = commentDto.parent?.ID ?: 0, + parentId = commentDto.parent?.ID ?: 0L, iLike = commentDto.i_like ) } @@ -139,7 +139,7 @@ class CommentsMapper @Inject constructor( content = XMLRPCUtils.safeGetMapValue(commentMap, "content", ""), url = XMLRPCUtils.safeGetMapValue(commentMap, "link", ""), hasParent = remoteParentCommentId > 0, - parentId = if (remoteParentCommentId > 0) remoteParentCommentId else 0, + parentId = if (remoteParentCommentId > 0) remoteParentCommentId else 0L, iLike = false ) } diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentRestClient.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentRestClient.java index 3b721bdd65e..5d2c99ce2cf 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentRestClient.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentRestClient.java @@ -296,6 +296,7 @@ private CommentModel commentResponseToComment( comment.setPublishedTimestamp(DateTimeUtils.timestampFromIso8601(response.date)); if (response.author != null) { + comment.setAuthorId(response.author.ID); comment.setAuthorUrl(response.author.URL); comment.setAuthorName(StringEscapeUtils.unescapeHtml4(response.author.name)); if ("false".equals(response.author.email)) { @@ -311,10 +312,6 @@ private CommentModel commentResponseToComment( comment.setPostTitle(StringEscapeUtils.unescapeHtml4(response.post.title)); } - if (response.author != null) { - comment.setAuthorId(response.author.ID); - } - if (response.parent != null) { comment.setHasParent(true); comment.setParentId(response.parent.ID); diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentWPComRestResponse.java b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentWPComRestResponse.java index 7806177310a..8483191af31 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentWPComRestResponse.java +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentWPComRestResponse.java @@ -1,34 +1,38 @@ package org.wordpress.android.fluxc.network.rest.wpcom.comment; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import java.util.List; +@SuppressWarnings("NotNullFieldNotInitialized") public class CommentWPComRestResponse { public static class CommentsWPComRestResponse { - public List comments; + @Nullable public List comments; } public static class Post { public long ID; - public String title; - public String type; - public String link; + @NonNull public String title; + @NonNull public String type; + @NonNull public String link; } public static class Author { public long ID; - public String email; // can be boolean "false" if not set - public String name; - public String URL; - public String avatar_URL; + @NonNull public String email; // can be boolean "false" if not set + @NonNull public String name; + @NonNull public String URL; + @NonNull public String avatar_URL; } public long ID; - public CommentParent parent; - public Post post; - public Author author; - public String date; - public String status; - public String content; + @Nullable public CommentParent parent; + @Nullable public Post post; + @Nullable public Author author; + @NonNull public String date; + @NonNull public String status; + @NonNull public String content; public boolean i_like; - public String URL; + @NonNull public String URL; }