Skip to content

[Compile Warnings As Errors] WordPress Module - Resolve Test Warnings#17300

Merged
ParaskP7 merged 20 commits intotrunkfrom
analysis/wordpress-test-all-warnings
Oct 12, 2022
Merged

[Compile Warnings As Errors] WordPress Module - Resolve Test Warnings#17300
ParaskP7 merged 20 commits intotrunkfrom
analysis/wordpress-test-all-warnings

Conversation

@ParaskP7
Copy link
Copy Markdown
Contributor

Parent: #17173
Partially Closes: #17181

This PR resolves one part of all Test related warnings for the WordPress module:

Deprecated Related (80)

  • 58 x 'XYX' is deprecated. Deprecated in Java
  • 2 x 'xyz' is deprecated. Use xyz instead.
  • 20 x 'Xyz' is deprecated. This class is being refactored, if you implement any change, please also update xyz

Type Related (8)

  • 3 x Type mismatch: inferred type is Xyz? but Xyz was expected
  • 4 x Unnecessary non-null assertion (!!) on a non-null receiver of type Xyz
  • 1 x Unnecessary safe call on a non-null receiver of type Xyz. This expression will have nullable type in future releases

Cast Related (6)

  • 4 x Unchecked cast: Xyz to Xyz
  • 2 x This cast can never succeed

When Related (1)

  • 1 x Non exhaustive 'when' statements on xyz will be prohibited in 1.7, add 'Xyz', 'Xyz' branch(es) or 'else' branch instead

Other Related (23)

  • 5 x Parameter 'xyz' is never used
  • 2 x Check for instance is always 'xyz'
  • 15 x Name contains characters which can cause problems on Windows: "
  • 1 x Name shadowed: fileName

Warnings Resolution List:

Warnings Suppression List:

Refactor List:


PS: @AjeshRPai I added you as the main reviewer, that is, in addition to @wordpress-mobile/apps-infrastructure team itself, but randomly, since I want someone from the WordPress Android team to primarily sign-off on that change. 🥇

FYI: I am going to randomly add more of you in those PRs that will follow, just so you become more aware of this change and how close we are on enabling allWarningsAsErrors by default everywhere. 🎉


To test:

  • There is nothing much to test here.
  • Verifying that all the CI checks are successful should be enough.

Regression Notes

  1. Potential unintended areas of impact

N/A

  1. What I did to test those areas of impact (or what existing automated tests I relied on)

See To test section above.

  1. What automated tests I added (or what prevented me from doing so)

N/A


PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Warning Messages:
- "'assertThat(T!, Matcher<in T!>!): Unit' is deprecated.
Deprecated in Java"
- "'assertThat(String!, T!, Matcher<in T!>!): Unit' is deprecated.
Deprecated in Java"

Using 'Assertions.assertThat' from the 'org.assertj.core.api' package,
instead of 'Assert.assertThat' from the 'org.junit' package is the
recommended action to resolve this kind of deprecated warnings.
In addition to that, this commit also replaces the 'runBlockingTest'
block, from the 'kotlinx.coroutines.test' package, with the 'test'
block, from [CoroutinesUtils], that is using 'runBlocking' underneath
anyway. This was done to make tests simpler to reason about and  easier
to be migrated to Coroutines version 1.6, which completely changes how
testing with Coroutines works. The only tests that are still using
'runBlockingTest', and doing that purposefully are the below:
- [BatchModerateCommentsUseCaseTest]
- [ModerateCommentsWithUndoUseCaseTest]
- [PaginateCommentsUseCaseTest]
- [QRCodeAuthViewModelTest]
- [SnackbarSequencerConcurrentTest]
- [UnifiedCommentListViewModelTest]

Also, the 'coroutineScope' rule annotations, that were pointing to
[MainCoroutineScopeRule] were removed as well, that is, where they were
indeed unnecessary.
Warning Messages: "'Assert' is deprecated. Deprecated in Java"

Using 'Assertions.assertThat' from the 'org.assertj.core.api' package,
instead of 'Assert.assertEquals/False/True' from the 'junit.framework'
package is the recommended action to resolve this kind of deprecated
warnings.
Warning Message: "'allowScanningByMediaScanner(): Unit' is deprecated.
Deprecated in Java"

These deprecated warnings are suppressed, that is, instead of being
resolved, since a resolution would require a proper migration.

For more info see:
- android.app.DownloadManager.Request.allowScanningByMediaScanner (Doc):
https://developer.android.com/reference/android/app/
DownloadManager.Request#allowScanningByMediaScanner()
Warning Messages: "'none(): ExpectedException!' is deprecated.
Deprecated in Java"

Also, as part of this commit, a few other minor warnings, including
typos, got resolved too.
This is done for consistency purposes only, as most of the other usages
of [InstantTaskExecutorRule] is on multiline instead on a single line.
Warning Messages:
- "'NetworkInfo' is deprecated. Deprecated in Java"
- "'getter for activeNetworkInfo: NetworkInfo?' is deprecated.
Deprecated in Java"
- "'getter for isConnected: Boolean' is deprecated.
Deprecated in Java"

These deprecated warnings are suppressed, that is, instead of being
resolved, since a resolution would require a proper migration.

For more info see:
- Compiler Warnings as Errors - WordPress Module -
Connectivity Manager & Network Info #17230 (Issue):
#17230
Warning Messages:
- "'PhotoPickerViewModel' is deprecated. This class is being refactored,
if you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.MediaPickerViewModel}"
- "'DeviceMediaListBuilder' is deprecated. This class is being
refactored, if you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.loader.DeviceListBuilder}"
- "'PhotoPickerItem' is deprecated. This class is being refactored, if
you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.MediaItem}"
- "'PhotoPickerUiItem' is deprecated. This class is being refactored, if
you implement any change, please also update
{@link org.wordpress.android.ui.mediapicker.MedaPickerUiItem}"

These deprecated warnings are suppressed, that is, instead of being
resolved, since a resolution would require a proper migration.

Also, as part of this commit, a few other minor warnings, including
imports, got resolved too.

Example Explanation: See KDoc on 'PhotoPickerViewModel' class.

"This class is being refactored, if you implement any change, please
also update {@link org.wordpress.android.ui.mediapicker
.MediaPickerViewModel}"
Warning Message: "Type mismatch: inferred type is Xyz?
but Xyz was expected"
Warning Message: "Unnecessary non-null assertion (!!) on a non-null
receiver of type Xyz"
Warning Message: "Unnecessary safe call on a non-null receiver of type
Xyz. This expression will have nullable type in future releases"
Warning Message: "Unchecked cast: Xyz to Xyz"

These type warnings are suppressed, that is, instead of being resolved,
since a resolution would require a proper investigation. As such, it
might be best to ignore those as out of scope, for now, and so as to not
introduce any breaking changes to these tests overall.
Warning Message: "This cast can never succeed"

These type warnings are suppressed, that is, instead of being resolved,
since a resolution would require a proper investigation. As such, it
might be best to ignore those as out of scope, for now, and so as to not
introduce any breaking changes to these tests overall.
Warning Message: "Non exhaustive 'when' statements on enum will be
prohibited in 1.7, add 'Xyz', 'Xyz' branch(es) or 'else' branch instead"

Also, as part of this commit, one other minor warning got resolved too.
Warning Message: "Check for instance is always 'false'"

Also, as part of this commit, one other minor warning got resolved too.
Warning Message: "Name contains characters which can cause problems on
Windows: "

Renaming '"xyz"' to ''xyz'' resolves this kind of 'name character'
warnings.

Also, as part of this commit, a few other minor warnings, including
imports, got resolved too.
Warning Message: "Name shadowed: xyz"

Also, as part of this commit, a couple of other minor warnings got
resolved too.
@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Oct 11, 2022

WordPress📲 You can test these changes on WordPress by downloading wordpress-installable-build-pr17300-42b38e8.apk
💡 Scan this QR code with your Android phone to download and install the APK directly on it.
AppWordPress
Build FlavorJalapeno
Build TypeDebug
Commit42b38e8
Note: This installable build uses the JalapenoDebug build flavor, and does not support Google Login.

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Oct 11, 2022

Jetpack📲 You can test these changes on Jetpack by downloading jetpack-installable-build-pr17300-42b38e8.apk
💡 Scan this QR code with your Android phone to download and install the APK directly on it.
AppJetpack
Build FlavorJalapeno
Build TypeDebug
Commit42b38e8
Note: This installable build uses the JalapenoDebug build flavor, and does not support Google Login.

Copy link
Copy Markdown
Contributor

@AjeshRPai AjeshRPai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing me with all the details for the review in the commit messages. 🙌🏼

I have tested the PR by going through the changes in every commit and reading the reference links mentioned in the commit messages and everything LGTM. And as the CI passes 🟢 , its a 👍🏼 from me.

I have left a ❓ for you to address. Since that's non-blocking. Am going to approve but not merge the PR so that anyone from @apps-infrastructure can have a look. Please feel free to merge the PR at your convenience.

import org.junit.Test
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ParaskP7 👋🏼
❓ Is the wild cart import necessary?.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 @AjeshRPai and thanks for noticing and hence the comment! 🙇

Actually no, I can replace that with import org.mockito.Mockito.'when', maybe that's better, although, to be honest I don't like the 'when' import syntax and in general us needing this 'when' syntax in tests. PS: This * import was done automatically for me by AS, when I clicked on optimizing the import.

Since, I am not seeing any such import org.mockito.Mockito.* imports for Mockito in our project, I'll go ahead and make this change, especially since we generally don't like * imports. 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This is now done: 42b38e8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @ParaskP7 👍🏼 .

Also, as part of this commit, a few other minor warnings got resolved
too.
@ParaskP7
Copy link
Copy Markdown
Contributor Author

Once more, thank you so much for reviewing this PR @AjeshRPai, you are being most helpful! 🙇 ❤️ 🚀

@ParaskP7 ParaskP7 merged commit a53f95a into trunk Oct 12, 2022
@ParaskP7 ParaskP7 deleted the analysis/wordpress-test-all-warnings branch October 12, 2022 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler Warnings as Errors - WordPress Module

3 participants