[Compile Warnings As Errors] WordPress Module - Resolve Test Warnings#17300
[Compile Warnings As Errors] WordPress Module - Resolve Test Warnings#17300
Conversation
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.
|
|||||||||||
| 💡 Scan this QR code with your Android phone to download and install the APK directly on it. | ||
| App | WordPress | |
| Build Flavor | Jalapeno | |
| Build Type | Debug | |
| Commit | 42b38e8 | |
|
|||||||||||
| 💡 Scan this QR code with your Android phone to download and install the APK directly on it. | ||
| App | Jetpack | |
| Build Flavor | Jalapeno | |
| Build Type | Debug | |
| Commit | 42b38e8 | |
AjeshRPai
left a comment
There was a problem hiding this comment.
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.* |
There was a problem hiding this comment.
Hey @ParaskP7 👋🏼
❓ Is the wild cart import necessary?.
There was a problem hiding this comment.
👋 @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. 👍
Also, as part of this commit, a few other minor warnings got resolved too.
|
Once more, thank you so much for reviewing this PR @AjeshRPai, you are being most helpful! 🙇 ❤️ 🚀 |


Parent: #17173
Partially Closes: #17181
This PR resolves one part of all
Testrelated warnings for theWordPressmodule:Deprecated Related (
80)58x'XYX' is deprecated. Deprecated in Java2x'xyz' is deprecated. Use xyz instead.20x'Xyz' is deprecated. This class is being refactored, if you implement any change, please also update xyzType Related (
8)3xType mismatch: inferred type is Xyz? but Xyz was expected4xUnnecessary non-null assertion (!!) on a non-null receiver of type Xyz1xUnnecessary safe call on a non-null receiver of type Xyz. This expression will have nullable type in future releasesCast Related (
6)4xUnchecked cast: Xyz to Xyz2xThis cast can never succeedWhen Related (
1)1xNon exhaustive 'when' statements on xyz will be prohibited in 1.7, add 'Xyz', 'Xyz' branch(es) or 'else' branch insteadOther Related (
23)5xParameter 'xyz' is never used2xCheck for instance is always 'xyz'15xName contains characters which can cause problems on Windows: "1xName shadowed: fileNameWarnings Resolution List:
deprecatedtypewhenotherWarnings Suppression List:
deprecatedcastRefactor List:
deprecatedotherPS: @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:
Regression Notes
N/A
See
To testsection above.N/A
PR submission checklist:
RELEASE-NOTES.txtif necessary.