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

fix usage of asserts where order or condition is missleading #1700

Merged
merged 4 commits into from
Oct 18, 2024

Conversation

carstenartur
Copy link
Contributor

What it does

junit asserts generate an error message based on the parameters presented. So when the fixed part and the actual part of an equal assertion is wrong it creates a wrong message about what was expected. The assertion still "works" because in an equal comparison the order does not matter regarding the failure of the junit test but the error message is wrong.
Another case is when you do the comparison inside of an assertion to check for true. That way junit is inable to generate a useful error message.

This PR fixes some of these issues. It has been generated by using the "Autorefactor" cleanup at
https://github.com/carstenartur/AutoRefactor/tree/master
Afaik this cleanup will not make it into jdt.ui any longer.

I looked at it while checking what could help to migrate tests to junit5.
Since the change was applied to no longer support old java versions in a lot of code of jdt.ui test environments are a mess with wrong name for the testenvironment to be used.

How to test

Nothing should change but the messages should be better in case of an issue.

Author checklist

@carstenartur carstenartur force-pushed the cleanuptestasserts branch 2 times, most recently from bd2f3ff to 8815ef7 Compare October 6, 2024 08:39
@carstenartur carstenartur marked this pull request as ready for review October 6, 2024 09:59
@jukzi
Copy link
Contributor

jukzi commented Oct 8, 2024

the build failed multiple times (build 4, 5) with

java.lang.AssertionError: 
Wrong bundles loaded:
- org.eclipse.jdt.junit
 expected:<0> but was:<24>
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.failNotEquals(Assert.java:835)
	at org.junit.Assert.assertEquals(Assert.java:647)
	at org.eclipse.jdt.text.tests.PluginsNotLoadedTest.pluginsNotLoaded(PluginsNotLoadedTest.java:278)

@jjohnstn
Copy link
Contributor

jjohnstn commented Oct 8, 2024

the build failed multiple times (build 4, 5) with

java.lang.AssertionError: 
Wrong bundles loaded:
- org.eclipse.jdt.junit
 expected:<0> but was:<24>
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.failNotEquals(Assert.java:835)
	at org.junit.Assert.assertEquals(Assert.java:647)
	at org.eclipse.jdt.text.tests.PluginsNotLoadedTest.pluginsNotLoaded(PluginsNotLoadedTest.java:278)

This test has been failing randomly for me in PR runs lately before this patch.

@carstenartur carstenartur force-pushed the cleanuptestasserts branch 4 times, most recently from cac9a88 to a21fd55 Compare October 15, 2024 19:16
@jjohnstn jjohnstn force-pushed the cleanuptestasserts branch 2 times, most recently from 898a187 to 8959467 Compare October 17, 2024 17:41
@jjohnstn jjohnstn merged commit 4f8849c into eclipse-jdt:master Oct 18, 2024
10 checks passed
@jjohnstn jjohnstn added the enhancement New feature or request label Oct 18, 2024
@jjohnstn jjohnstn self-assigned this Oct 18, 2024
@jjohnstn jjohnstn added this to the 4.34 M2 milestone Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants