Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nullability Annotations to Java Classes] Add Missing Nullability Annotations to All Taxonomy & Term SqlUtils & Model Classes (breaking) #2851

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
458ef95
Analysis: Add missing n-a to fetch terms payload
ParaskP7 Sep 5, 2023
2882210
Analysis: Add missing n-a to taxonomy model
ParaskP7 Sep 5, 2023
a51d38b
Analysis: Suppress condition covered by further condition warning
ParaskP7 Sep 5, 2023
4deacc9
Analysis: Add missing n-a to fetch terms response payload
ParaskP7 Sep 5, 2023
f37428a
Analysis: Add missing n-a to on term uploaded store
ParaskP7 Sep 5, 2023
0b49e4c
Analysis: Add missing n-a to on term update/remove term store methods
ParaskP7 Sep 5, 2023
41c56a5
Analysis: Add missing n-a to on get tags for post store method
ParaskP7 Sep 5, 2023
a8d1f27
Analysis: Add missing n-a to on get categories for post store method
ParaskP7 Sep 5, 2023
8d75e7b
Analysis: Add missing n-a to on get term by name store methods
ParaskP7 Sep 5, 2023
a075f39
Analysis: Add missing n-a to on get term by remote id store methods
ParaskP7 Sep 6, 2023
05a852f
Analysis: Add missing n-a to on get terms for site store methods
ParaskP7 Sep 6, 2023
7de7470
Test: Add missing final keyword on taxonomy store unit test fields
ParaskP7 Sep 6, 2023
c66f686
Test: Resolve robolectric related application deprecation warning
ParaskP7 Sep 6, 2023
25118ec
Test: Create missing switch branches for on taxonomy changed
ParaskP7 Sep 6, 2023
21e6424
Test: Suppress new class naming convention for connected test
ParaskP7 Sep 6, 2023
646d2c6
Test: Simplify assertion for check update existing term
ParaskP7 Sep 6, 2023
9547923
Analysis: Create missing switch cases for store actions
ParaskP7 Sep 6, 2023
30e6133
Analysis: Suppress unused warnings on get related store methods
ParaskP7 Sep 6, 2023
ab81837
Analysis: Suppress raw types warnings for store action method
ParaskP7 Sep 6, 2023
4db457a
Analysis: Use inserted term on instantiate term model store method
ParaskP7 Sep 6, 2023
7d823c9
Analysis: Add missing n-a to remove term sql utils methods
ParaskP7 Sep 6, 2023
74fe47a
Analysis: Add missing n-a to insert term for result sql utils methods
ParaskP7 Sep 6, 2023
42dba85
Analysis: Add missing n-a to insert or update term sql utils methods
ParaskP7 Sep 6, 2023
1d5b073
Test: Assert for deleted term models on taxonomy store test
ParaskP7 Sep 6, 2023
8ff128c
Analysis: Add missing n-a to clear taxonomy for site sql utils methods
ParaskP7 Sep 6, 2023
2fd3d9d
Analysis: Add missing n-a to handle fetch single term completed method
ParaskP7 Sep 6, 2023
0849403
Analysis: Add missing n-a to handle delete/push term completed methods
ParaskP7 Sep 6, 2023
42e8bec
Analysis: Add missing n-a to on taxonomy changed
ParaskP7 Sep 6, 2023
7b53e45
Refactor: Remove unnecessary taxonomy name field from taxonomy changed
ParaskP7 Sep 6, 2023
8602356
Test: Remove unnecessary interrupted exception from private test methods
ParaskP7 Sep 6, 2023
30f1880
Test: Guard usages of instantiate term model methods
ParaskP7 Sep 6, 2023
52cf542
Analysis: Add missing n-a to taxonomy error
ParaskP7 Sep 6, 2023
b34ed2f
Analysis: Add missing n-a to term model
ParaskP7 Sep 7, 2023
2f9ad78
Analysis: Suppress condition covered by further condition warning
ParaskP7 Sep 7, 2023
f902b5e
Analysis: Add missing n-a to terms model
ParaskP7 Sep 7, 2023
0d408d3
Refactor: Remove test only taxonomy store methods
ParaskP7 Sep 7, 2023
fdbcdc0
Analysis: Add default and non-default constructors for taxonomy model
ParaskP7 Sep 7, 2023
11b5817
Analysis: Add default and non-default constructors for term model
ParaskP7 Sep 8, 2023
22e6a84
Merge branch 'trunk' of github.com:wordpress-mobile/WordPress-FluxC-A…
ParaskP7 Sep 19, 2023
a32ed9f
Merge branch 'trunk' of github.com:wordpress-mobile/WordPress-FluxC-A…
ParaskP7 Oct 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.wordpress.android.fluxc.release;

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

import com.yarolegovich.wellsql.WellSql;

import org.greenrobot.eventbus.Subscribe;
import org.junit.Test;
import org.wordpress.android.fluxc.TestUtils;
import org.wordpress.android.fluxc.example.utils.RandomStringUtils;
import org.wordpress.android.fluxc.generated.TaxonomyActionBuilder;
import org.wordpress.android.fluxc.model.SiteModel;
import org.wordpress.android.fluxc.model.TaxonomyModel;
import org.wordpress.android.fluxc.model.TermModel;
import org.wordpress.android.fluxc.store.TaxonomyStore;
Expand All @@ -26,11 +30,12 @@
import javax.inject.Inject;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

@SuppressWarnings("NewClassNamingConvention")
public class ReleaseStack_TaxonomyTestWPCom extends ReleaseStack_WPComBase {
@Inject TaxonomyStore mTaxonomyStore;

Expand Down Expand Up @@ -95,8 +100,7 @@ public void testFetchTermsForInvalidTaxonomy() throws InterruptedException {
mNextEvent = TestEvents.ERROR_INVALID_TAXONOMY;
mCountDownLatch = new CountDownLatch(1);

TaxonomyModel taxonomyModel = new TaxonomyModel();
taxonomyModel.setName("roads");
TaxonomyModel taxonomyModel = new TaxonomyModel("roads");

FetchTermsPayload payload = new FetchTermsPayload(sSite, taxonomyModel);
mDispatcher.dispatch(TaxonomyActionBuilder.newFetchTermsAction(payload));
Expand All @@ -109,8 +113,7 @@ public void testFetchSingleCategory() throws InterruptedException {
mNextEvent = TestEvents.TERM_UPDATED;
mCountDownLatch = new CountDownLatch(1);

TermModel term = new TermModel();
term.setTaxonomy(TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY);
TermModel term = new TermModel(TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY);
term.setSlug("uncategorized");
mDispatcher.dispatch(TaxonomyActionBuilder.newFetchTermAction(new RemoteTermPayload(term, sSite)));

Expand Down Expand Up @@ -184,8 +187,7 @@ public void testDeleteTag() throws InterruptedException {

@Test
public void testUploadNewCategoryAsTerm() throws InterruptedException {
TaxonomyModel taxonomyModel = new TaxonomyModel();
taxonomyModel.setName(TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY);
TaxonomyModel taxonomyModel = new TaxonomyModel(TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY);

// Instantiate new term
TermModel term = createNewTerm(taxonomyModel);
Expand All @@ -204,8 +206,7 @@ public void testUploadNewCategoryAsTerm() throws InterruptedException {

@Test
public void testUploadTermForInvalidTaxonomy() throws InterruptedException {
TaxonomyModel taxonomyModel = new TaxonomyModel();
taxonomyModel.setName("roads");
TaxonomyModel taxonomyModel = new TaxonomyModel("roads");

// Instantiate new term
TermModel term = createNewTerm(taxonomyModel);
Expand Down Expand Up @@ -246,7 +247,7 @@ public void testUploadNewCategoryDuplicate() throws InterruptedException {

@SuppressWarnings("unused")
@Subscribe
public void onTaxonomyChanged(OnTaxonomyChanged event) {
public void onTaxonomyChanged(@NonNull OnTaxonomyChanged event) {
AppLog.i(T.API, "Received OnTaxonomyChanged, causeOfChange: " + event.causeOfChange);
if (event.isError()) {
AppLog.i(T.API, "OnTaxonomyChanged has error: " + event.error.type + " - " + event.error.message);
Expand Down Expand Up @@ -280,7 +281,7 @@ public void onTaxonomyChanged(OnTaxonomyChanged event) {
break;
case FETCH_TERMS:
if (mNextEvent.equals(TestEvents.TERMS_FETCHED)) {
AppLog.i(T.API, "Fetched " + event.rowsAffected + " " + event.taxonomyName + " terms");
AppLog.i(T.API, "Fetched " + event.rowsAffected + " terms");
mCountDownLatch.countDown();
}
break;
Expand All @@ -296,12 +297,21 @@ public void onTaxonomyChanged(OnTaxonomyChanged event) {
mCountDownLatch.countDown();
}
break;
case FETCH_TERM:
case PUSH_TERM:
case DELETE_TERM:
case FETCHED_TERMS:
case FETCHED_TERM:
case PUSHED_TERM:
case DELETED_TERM:
case REMOVE_ALL_TERMS:
break;
}
}

@SuppressWarnings("unused")
@Subscribe
public void onTermUploaded(OnTermUploaded event) {
public void onTermUploaded(@NonNull OnTermUploaded event) {
AppLog.i(T.API, "Received OnTermUploaded");
if (event.isError()) {
AppLog.i(T.API, "OnTermUploaded has error: " + event.error.type + " - " + event.error.message);
Expand Down Expand Up @@ -337,7 +347,7 @@ private void setupTermAttributes(@NonNull TermModel term) {

@NonNull
private TermModel createNewCategory() {
TermModel term = mTaxonomyStore.instantiateCategory(sSite);
TermModel term = instantiateTermModel(sSite, TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY);

if (term != null) {
assertEquals(0, term.getRemoteTermId());
Expand All @@ -352,7 +362,7 @@ private TermModel createNewCategory() {

@NonNull
private TermModel createNewTag() {
TermModel term = mTaxonomyStore.instantiateTag(sSite);
TermModel term = instantiateTermModel(sSite, TaxonomyStore.DEFAULT_TAXONOMY_TAG);

if (term != null) {
assertEquals(0, term.getRemoteTermId());
Expand All @@ -367,7 +377,7 @@ private TermModel createNewTag() {

@NonNull
private TermModel createNewTerm(@NonNull TaxonomyModel taxonomy) {
TermModel term = mTaxonomyStore.instantiateTerm(sSite, taxonomy);
TermModel term = instantiateTermModel(sSite, taxonomy.getName());

if (term != null) {
assertEquals(0, term.getRemoteTermId());
Expand Down Expand Up @@ -411,7 +421,7 @@ private void checkUpdateExistingTerm(TermModel term) throws InterruptedException
assertNotSame(0, uploadedTerm.getRemoteTermId());

String newDescription = "newDescription";
assertFalse(newDescription.equals(uploadedTerm.getDescription()));
assertNotEquals(newDescription, uploadedTerm.getDescription());
uploadedTerm.setDescription(newDescription);

uploadTerm(uploadedTerm);
Expand All @@ -420,4 +430,25 @@ private void checkUpdateExistingTerm(TermModel term) throws InterruptedException
assertEquals(updatedTerm.getRemoteTermId(), uploadedTerm.getRemoteTermId());
assertEquals(updatedTerm.getDescription(), newDescription);
}

@Nullable
private TermModel instantiateTermModel(@NonNull SiteModel site, @NonNull String taxonomyName) {
TermModel newTerm = new TermModel(taxonomyName);
newTerm.setLocalSiteId(site.getId());

// Insert the term into the db, updating the object to include the local ID
TermModel insertedTerm = insertTermForResult(newTerm);

// id is set to -1 if insertion fails
if (insertedTerm.getId() == -1) {
return null;
}
return insertedTerm;
}

@NonNull
public static TermModel insertTermForResult(@NonNull TermModel term) {
WellSql.insert(term).asSingleTransaction(true).execute();
return term;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package org.wordpress.android.fluxc.release;

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

import com.yarolegovich.wellsql.WellSql;

import org.greenrobot.eventbus.Subscribe;
import org.junit.Ignore;
import org.junit.Test;
import org.wordpress.android.fluxc.TestUtils;
import org.wordpress.android.fluxc.example.utils.RandomStringUtils;
import org.wordpress.android.fluxc.generated.TaxonomyActionBuilder;
import org.wordpress.android.fluxc.model.SiteModel;
import org.wordpress.android.fluxc.model.TaxonomyModel;
import org.wordpress.android.fluxc.model.TermModel;
import org.wordpress.android.fluxc.store.TaxonomyStore;
Expand All @@ -26,10 +32,12 @@
import javax.inject.Inject;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

@SuppressWarnings("NewClassNamingConvention")
public class ReleaseStack_TaxonomyTestXMLRPC extends ReleaseStack_XMLRPCBase {
@Inject TaxonomyStore mTaxonomyStore;

Expand Down Expand Up @@ -99,8 +107,7 @@ public void testFetchTermsForInvalidTaxonomy() throws InterruptedException {
mNextEvent = TestEvents.ERROR_GENERIC;
mCountDownLatch = new CountDownLatch(1);

TaxonomyModel taxonomyModel = new TaxonomyModel();
taxonomyModel.setName("roads");
TaxonomyModel taxonomyModel = new TaxonomyModel("roads");

FetchTermsPayload payload = new FetchTermsPayload(sSite, taxonomyModel);
mDispatcher.dispatch(TaxonomyActionBuilder.newFetchTermsAction(payload));
Expand All @@ -117,8 +124,7 @@ public void testFetchSingleCategory() throws InterruptedException {
mNextEvent = TestEvents.TERM_UPDATED;
mCountDownLatch = new CountDownLatch(1);

TermModel term = new TermModel();
term.setTaxonomy(TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY);
TermModel term = new TermModel(TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY);
term.setSlug("uncategorized");
term.setRemoteTermId(1);
mDispatcher.dispatch(TaxonomyActionBuilder.newFetchTermAction(new RemoteTermPayload(term, sSite)));
Expand Down Expand Up @@ -180,8 +186,7 @@ public void testUpdateExistingTag() throws InterruptedException {

@Test
public void testUploadNewCategoryAsTerm() throws InterruptedException {
TaxonomyModel taxonomyModel = new TaxonomyModel();
taxonomyModel.setName(TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY);
TaxonomyModel taxonomyModel = new TaxonomyModel(TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY);

// Instantiate new term
TermModel termModel = createNewTerm(taxonomyModel);
Expand All @@ -200,8 +205,7 @@ public void testUploadNewCategoryAsTerm() throws InterruptedException {

@Test
public void testUploadTermForInvalidTaxonomy() throws InterruptedException {
TaxonomyModel taxonomyModel = new TaxonomyModel();
taxonomyModel.setName("roads");
TaxonomyModel taxonomyModel = new TaxonomyModel("roads");

// Instantiate new term
TermModel term = createNewTerm(taxonomyModel);
Expand Down Expand Up @@ -262,7 +266,7 @@ public void testDeleteTag() throws InterruptedException {

@SuppressWarnings("unused")
@Subscribe
public void onTaxonomyChanged(OnTaxonomyChanged event) {
public void onTaxonomyChanged(@NonNull OnTaxonomyChanged event) {
AppLog.i(T.API, "Received OnTaxonomyChanged, causeOfChange: " + event.causeOfChange);
if (event.isError()) {
AppLog.i(T.API, "OnTaxonomyChanged has error: " + event.error.type + " - " + event.error.message);
Expand Down Expand Up @@ -297,7 +301,7 @@ public void onTaxonomyChanged(OnTaxonomyChanged event) {
break;
case FETCH_TERMS:
if (mNextEvent.equals(TestEvents.TERMS_FETCHED)) {
AppLog.i(T.API, "Fetched " + event.rowsAffected + " " + event.taxonomyName + " terms");
AppLog.i(T.API, "Fetched " + event.rowsAffected + " terms");
mCountDownLatch.countDown();
}
break;
Expand All @@ -313,12 +317,21 @@ public void onTaxonomyChanged(OnTaxonomyChanged event) {
mCountDownLatch.countDown();
}
break;
case FETCH_TERM:
case PUSH_TERM:
case DELETE_TERM:
case FETCHED_TERMS:
case FETCHED_TERM:
case PUSHED_TERM:
case DELETED_TERM:
case REMOVE_ALL_TERMS:
break;
}
}

@SuppressWarnings("unused")
@Subscribe
public void onTermUploaded(OnTermUploaded event) {
public void onTermUploaded(@NonNull OnTermUploaded event) {
AppLog.i(T.API, "Received OnTermUploaded");
if (event.isError()) {
AppLog.i(T.API, "OnTermUploaded has error: " + event.error.type + " - " + event.error.message);
Expand Down Expand Up @@ -353,32 +366,44 @@ private void setupTermAttributes(TermModel term) {
term.setDescription(TERM_DEFAULT_DESCRIPTION);
}

private TermModel createNewCategory() throws InterruptedException {
TermModel term = mTaxonomyStore.instantiateCategory(sSite);
private TermModel createNewCategory() {
TermModel term = instantiateTermModel(sSite, TaxonomyStore.DEFAULT_TAXONOMY_CATEGORY);

assertEquals(0, term.getRemoteTermId());
assertNotSame(0, term.getId());
assertNotSame(0, term.getLocalSiteId());
if (term != null) {
assertEquals(0, term.getRemoteTermId());
assertNotSame(0, term.getId());
assertNotSame(0, term.getLocalSiteId());
} else {
fail("Failed to instantiate new category!");
}

return term;
}

private TermModel createNewTag() throws InterruptedException {
TermModel term = mTaxonomyStore.instantiateTag(sSite);
private TermModel createNewTag() {
TermModel term = instantiateTermModel(sSite, TaxonomyStore.DEFAULT_TAXONOMY_TAG);

assertEquals(0, term.getRemoteTermId());
assertNotSame(0, term.getId());
assertNotSame(0, term.getLocalSiteId());
if (term != null) {
assertEquals(0, term.getRemoteTermId());
assertNotSame(0, term.getId());
assertNotSame(0, term.getLocalSiteId());
} else {
fail("Failed to instantiate new tag!");
}

return term;
}

private TermModel createNewTerm(TaxonomyModel taxonomy) throws InterruptedException {
TermModel term = mTaxonomyStore.instantiateTerm(sSite, taxonomy);
private TermModel createNewTerm(TaxonomyModel taxonomy) {
TermModel term = instantiateTermModel(sSite, taxonomy.getName());

assertEquals(0, term.getRemoteTermId());
assertNotSame(0, term.getId());
assertNotSame(0, term.getLocalSiteId());
if (term != null) {
assertEquals(0, term.getRemoteTermId());
assertNotSame(0, term.getId());
assertNotSame(0, term.getLocalSiteId());
} else {
fail("Failed to instantiate new term!");
}

return term;
}
Expand All @@ -404,7 +429,7 @@ private void testUpdateExistingTerm(TermModel term) throws InterruptedException
assertNotSame(0, uploadedTerm.getRemoteTermId());

String newDescription = "newDescription";
assertFalse(newDescription.equals(uploadedTerm.getDescription()));
assertNotEquals(newDescription, uploadedTerm.getDescription());
uploadedTerm.setDescription(newDescription);

uploadTerm(uploadedTerm);
Expand All @@ -423,4 +448,25 @@ private void deleteTerm(TermModel term) throws InterruptedException {

assertTrue(mCountDownLatch.await(TestUtils.DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
}

@Nullable
private TermModel instantiateTermModel(@NonNull SiteModel site, @NonNull String taxonomyName) {
TermModel newTerm = new TermModel(taxonomyName);
newTerm.setLocalSiteId(site.getId());

// Insert the term into the db, updating the object to include the local ID
TermModel insertedTerm = insertTermForResult(newTerm);

// id is set to -1 if insertion fails
if (insertedTerm.getId() == -1) {
return null;
}
return insertedTerm;
}

@NonNull
public static TermModel insertTermForResult(@NonNull TermModel term) {
WellSql.insert(term).asSingleTransaction(true).execute();
return term;
}
}
Loading