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

(fixes #3464) Replace assert() usages with assertThat() #5861

Merged
merged 6 commits into from
Oct 16, 2024

Conversation

u7683345
Copy link
Contributor

Uses of the assert() function in Kotlin are inherited from Java and are only enabled in the JVM with the -ea flag (enable assertions). Since the -ea flag has "not been enabled and won't be", these current assert() assertions don't do anything.

To fix this the assertThat() assertion is always active, regardless of JVM settings, so this would be more suitable.

Fixes #3463

What changes did you make and why?

  • Replaced all occurrences of the assert() function to equivalent assertThat() function calls, in 3 relevant files.
  • Imported 3 functions from the hamcrest.CoreMatchers library, assetThat() , equalTo(), and not(), in these files for translating the current assertions over to the hamcrest syntax.

Tests performed

Tested ProdDebug on Pixel 9 with API level 34.

New imports:
 - org.hamcrest.CoreMatchers.equalTo
 - org.hamcrest.CoreMatchers.assertThat
New imports:
 - org.hamcrest.CoreMatchers.equalTo
 - import org.hamcrest.CoreMatchers.not
 - org.hamcrest.CoreMatchers.assertThat
New imports:
 - org.hamcrest.CoreMatchers.equalTo
 - org.hamcrest.CoreMatchers.assertThat
@u7683345
Copy link
Contributor Author

@nicolas-raoul would you be able to review this? :-)

@nicolas-raoul
Copy link
Member

Thanks!

Now I guess we have to find out why this test is failing:

fr.free.nrw.commons.location.LatLngTest > testConstructorBigLongitude FAILED
    java.lang.AssertionError at LatLngTest.kt:26
    
1542 tests completed, 1 failed, 40 skipped

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

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

Tests pass, thanks! :-)

@nicolas-raoul nicolas-raoul merged commit 0a7fe66 into commons-app:main Oct 16, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove usages of assert
2 participants