-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Analysis: Add missing n-a to comment wp com rest response fields
FYI: 'n-a' stands for 'nullability annotations'. PS: This 'NotNullFieldNotInitialized' warning got suppressed because a 'response' class can never have its fields initialized via a constructor initialization, or otherwise for that matter.
- Loading branch information
Showing
5 changed files
with
70 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 protected]", | ||
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 protected]", | ||
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") | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 protected]" | ||
|
@@ -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 | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 19 additions & 15 deletions
34
...java/org/wordpress/android/fluxc/network/rest/wpcom/comment/CommentWPComRestResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CommentWPComRestResponse> comments; | ||
@Nullable public List<CommentWPComRestResponse> 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; | ||
} |