Skip to content

Commit

Permalink
Merge pull request #2870 from wordpress-mobile/analysis/add-missing-n…
Browse files Browse the repository at this point in the history
…ullability-annotations-to-all-comment-sqlutils-model-classes

[Nullability Annotations to Java Classes] Add Missing Nullability Annotations to All `Comment` SqlUtils & Model Classes (`breaking`)
  • Loading branch information
ParaskP7 authored Oct 19, 2023
2 parents 6eee26f + 1b43bf0 commit 5f7448d
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public void testInstantiateAndCreateNewComment() throws InterruptedException {

// Check comment has been modified in the DB
CommentModel comment = mCommentStore.getCommentByLocalId(mNewComment.getId());
assertNotNull(comment);
assertTrue(comment.getContent().contains(mNewComment.getContent()));
}

Expand All @@ -174,6 +175,7 @@ public void testLikeAndUnlikeComment() throws InterruptedException {

// Check comment has been modified in the DB
CommentModel comment = mCommentStore.getCommentByLocalId(firstComment.getId());
assertNotNull(comment);
assertTrue(comment.getILike());

// Unlike comment
Expand All @@ -185,6 +187,7 @@ public void testLikeAndUnlikeComment() throws InterruptedException {

// Check comment has been modified in the DB
comment = mCommentStore.getCommentByLocalId(firstComment.getId());
assertNotNull(comment);
assertFalse(comment.getILike());
}

Expand All @@ -205,6 +208,7 @@ public void testDeleteCommentOnce() throws InterruptedException {

// Check comment has been modified in the DB
CommentModel comment = mCommentStore.getCommentByLocalId(mNewComment.getId());
assertNotNull(comment);
assertTrue(comment.getContent().contains(mNewComment.getContent()));

// Delete
Expand All @@ -216,6 +220,7 @@ public void testDeleteCommentOnce() throws InterruptedException {

// Make sure the comment is still here but state changed
comment = mCommentStore.getCommentByLocalId(mNewComment.getId());
assertNotNull(comment);
assertEquals(CommentStatus.TRASH.toString(), comment.getStatus());
}

Expand All @@ -236,6 +241,7 @@ public void testDeleteCommentTwice() throws InterruptedException {

// Check comment has been modified in the DB
CommentModel comment = mCommentStore.getCommentByLocalId(mNewComment.getId());
assertNotNull(comment);
assertTrue(comment.getContent().contains(mNewComment.getContent()));

// Delete once (ie. move to trash)
Expand Down Expand Up @@ -326,6 +332,7 @@ public void testInstantiateAndCreateReplyComment() throws InterruptedException {
CommentModel comment = mCommentStore.getCommentByLocalId(mNewComment.getId());

// Using .contains() in the assert below because server might wrap the response in <p>
assertNotNull(comment);
assertTrue(comment.getContent().contains(mNewComment.getContent()));
assertNotSame(mNewComment.getRemoteCommentId(), comment.getRemoteCommentId());
assertNotSame(mNewComment.getRemoteSiteId(), comment.getRemoteSiteId());
Expand Down Expand Up @@ -415,6 +422,7 @@ public void testCommentResponseContainsURL() throws InterruptedException {

// Check the new comment response contains URL
CommentModel comment = mCommentStore.getCommentByLocalId(mNewComment.getId());
assertNotNull(comment);
assertNotNull(comment.getUrl());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void testInstantiateAndCreateNewComment() throws InterruptedException {

// Check comment has been modified in the DB
CommentModel comment = mCommentStore.getCommentByLocalId(mNewComment.getId());
assertNotNull(comment);
assertTrue(comment.getContent().contains(mNewComment.getContent()));
}

Expand Down Expand Up @@ -172,6 +173,7 @@ public void testInstantiateAndCreateReplyComment() throws InterruptedException {

// Check comment has been modified in the DB
CommentModel comment = mCommentStore.getCommentByLocalId(mNewComment.getId());
assertNotNull(comment);
assertEquals(comment.getContent(), mNewComment.getContent());
assertEquals(comment.getAuthorId(), firstComment.getAuthorId());
assertEquals(comment.getParentId(), firstComment.getRemoteCommentId());
Expand All @@ -196,6 +198,7 @@ public void testEditValidComment() throws InterruptedException {
assertTrue(mCountDownLatch.await(TestUtils.DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS));

CommentModel comment = mCommentStore.getCommentByLocalId(firstComment.getId());
assertNotNull(comment);
assertEquals(comment.getContent(), firstComment.getContent());
}

Expand Down Expand Up @@ -235,6 +238,7 @@ public void testDeleteCommentOnce() throws InterruptedException {

// Check comment has been modified in the DB
CommentModel comment = mCommentStore.getCommentByLocalId(mNewComment.getId());
assertNotNull(comment);
assertTrue(comment.getContent().contains(mNewComment.getContent()));

// Delete
Expand All @@ -246,6 +250,7 @@ public void testDeleteCommentOnce() throws InterruptedException {

// Make sure the comment is still here but state changed
comment = mCommentStore.getCommentByLocalId(mNewComment.getId());
assertNotNull(comment);
assertEquals(CommentStatus.TRASH.toString(), comment.getStatus());
}

Expand All @@ -266,6 +271,7 @@ public void testDeleteCommentTwice() throws InterruptedException {

// Check comment has been modified in the DB
CommentModel comment = mCommentStore.getCommentByLocalId(mNewComment.getId());
assertNotNull(comment);
assertTrue(comment.getContent().contains(mNewComment.getContent()));

// Delete once (ie. move to trash)
Expand Down Expand Up @@ -302,6 +308,7 @@ public void testCommentResponseContainsURL() throws InterruptedException {

// Check the new comment response contains URL
CommentModel comment = mCommentStore.getCommentByLocalId(mNewComment.getId());
assertNotNull(comment);
assertNotNull(comment.getUrl());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ class CommentsMapperTest {
authorEmail = entity.authorEmail
authorProfileImageUrl = entity.authorProfileImageUrl
postTitle = entity.postTitle
status = entity.status
datePublished = entity.datePublished
status = entity.status ?: ""
datePublished = entity.datePublished ?: ""
publishedTimestamp = entity.publishedTimestamp
content = entity.content
url = entity.authorProfileImageUrl
content = entity.content ?: ""
url = entity.authorProfileImageUrl ?: ""
hasParent = entity.hasParent
parentId = entity.parentId
iLike = entity.iLike
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.wordpress.android.fluxc.model;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.yarolegovich.wellsql.core.Identifiable;
import com.yarolegovich.wellsql.core.annotation.Column;
import com.yarolegovich.wellsql.core.annotation.PrimaryKey;
Expand All @@ -11,6 +14,7 @@
import java.io.Serializable;

@Table
@SuppressWarnings("NotNullFieldNotInitialized")
public class CommentModel extends Payload<BaseNetworkError> implements Identifiable, Serializable {
private static final long serialVersionUID = 3454722213760369852L;

Expand All @@ -23,19 +27,19 @@ public class CommentModel extends Payload<BaseNetworkError> implements Identifia
@Column private long mRemoteSiteId;

// Comment author
@Column private String mAuthorUrl;
@Column private String mAuthorName;
@Column private String mAuthorEmail;
@Nullable @Column private String mAuthorUrl;
@Nullable @Column private String mAuthorName;
@Nullable @Column private String mAuthorEmail;
@Column private long mAuthorId;
@Column private String mAuthorProfileImageUrl;
@Nullable @Column private String mAuthorProfileImageUrl;

// Comment data
@Column private String mPostTitle;
@Column private String mStatus;
@Column private String mDatePublished;
@Nullable @Column private String mPostTitle;
@NonNull @Column private String mStatus;
@NonNull @Column private String mDatePublished;
@Column private long mPublishedTimestamp;
@Column private String mContent;
@Column private String mUrl;
@NonNull @Column private String mContent;
@NonNull @Column private String mUrl;

// Parent Comment Data
@Column private boolean mHasParent;
Expand All @@ -54,9 +58,6 @@ public void setId(int id) {
mId = id;
}

// not stored in db - denotes the hierarchical level of this comment
public transient int level = 0;

public long getRemoteCommentId() {
return mRemoteCommentId;
}
Expand All @@ -73,67 +74,75 @@ public void setRemotePostId(long remotePostId) {
mRemotePostId = remotePostId;
}

@Nullable
public String getAuthorUrl() {
return mAuthorUrl;
}

public void setAuthorUrl(String authorUrl) {
public void setAuthorUrl(@Nullable String authorUrl) {
this.mAuthorUrl = authorUrl;
}

@Nullable
public String getAuthorName() {
return mAuthorName;
}

public void setAuthorName(String authorName) {
public void setAuthorName(@Nullable String authorName) {
this.mAuthorName = authorName;
}

@Nullable
public String getAuthorEmail() {
return mAuthorEmail;
}

public void setAuthorEmail(String authorEmail) {
public void setAuthorEmail(@Nullable String authorEmail) {
this.mAuthorEmail = authorEmail;
}

@Nullable
public String getAuthorProfileImageUrl() {
return mAuthorProfileImageUrl;
}

public void setAuthorProfileImageUrl(String authorProfileImageUrl) {
public void setAuthorProfileImageUrl(@Nullable String authorProfileImageUrl) {
this.mAuthorProfileImageUrl = authorProfileImageUrl;
}

@Nullable
public String getPostTitle() {
return mPostTitle;
}

public void setPostTitle(String postTitle) {
public void setPostTitle(@Nullable String postTitle) {
this.mPostTitle = postTitle;
}

@NonNull
public String getStatus() {
return mStatus;
}

public void setStatus(String status) {
public void setStatus(@NonNull String status) {
this.mStatus = status;
}

@NonNull
public String getDatePublished() {
return mDatePublished;
}

public void setDatePublished(String datePublished) {
public void setDatePublished(@NonNull String datePublished) {
this.mDatePublished = datePublished;
}

@NonNull
public String getContent() {
return mContent;
}

public void setContent(String content) {
public void setContent(@NonNull String content) {
this.mContent = content;
}

Expand Down Expand Up @@ -169,11 +178,12 @@ public void setILike(boolean iLike) {
mILike = iLike;
}

@NonNull
public String getUrl() {
return mUrl;
}

public void setUrl(String url) {
public void setUrl(@NonNull String url) {
mUrl = url;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ class CommentsMapper @Inject constructor(
this.authorEmail = entity.authorEmail
this.authorProfileImageUrl = entity.authorProfileImageUrl
this.postTitle = entity.postTitle
this.status = entity.status
this.datePublished = entity.datePublished
this.status = entity.status ?: ""
this.datePublished = entity.datePublished ?: ""
this.publishedTimestamp = entity.publishedTimestamp
this.content = entity.content
this.url = entity.url
this.content = entity.content ?: ""
this.url = entity.url ?: ""
this.hasParent = entity.hasParent
this.parentId = entity.parentId
this.iLike = entity.iLike
Expand Down
Loading

0 comments on commit 5f7448d

Please sign in to comment.