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 flaky test PolarPlotTest.testGetLegendItems2 #387

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Sujishark
Copy link

This PR aims to fix a test:

org.jfree.chart.plot.PolarPlotTest.testGetLegendItems2

This was found by using the NonDex tool.

Encountered the following error after running NonDex:

in org.jfree.chart.plot.PolarPlotTest
[ERROR] org.jfree.chart.plot.PolarPlotTest.testGetLegendItems2  Time elapsed: 0.053 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <A> but was: <C>
at org.jfree.chart@2.0.0-SNAPSHOT/org.jfree.chart.plot.PolarPlotTest.testGetLegendItems2(PolarPlotTest.java:108)

REASON AND FIX

The tests fail when the function values of 'items' are compared using assert statements intestGetLegendItems2. This is because the 'renderers' in Plot are set using HashMap which maintains a non-deterministic order.

this.renderers = new HashMap<>();

According to HashMap documentation,
"This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time."

This can be solved by changing from HashMap to LinkedHashMap to maintain a permanent deterministic order.

Reproduce:

The following command can be used to replicate the failures and validate the fix:

mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.jfree.chart.plot.PolarPlotTest#testGetLegendItems2

Environment:

Java: openjdk version "11.0.20.1"
Maven: Apache Maven 3.6.3

No user-facing change.
No dependency upgrade.

Author:    rajan11 <rajan11@illinois.edu>
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.

None yet

1 participant