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

JUnit 4 -> JUnit 5 migration - assertArrayEquals #383

Closed
puskarpeter opened this issue Jul 18, 2023 · 1 comment · Fixed by #384
Closed

JUnit 4 -> JUnit 5 migration - assertArrayEquals #383

puskarpeter opened this issue Jul 18, 2023 · 1 comment · Fixed by #384
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@puskarpeter
Copy link
Contributor

What problem are you trying to solve?

When migrating assertEquals, detect properly when to use assertArrayEquals.
I believe that between JUnit4 and JUnit5 assertEquals behaviour changed. It compares direct object references now.
The following test case below passes in JUnit4 but fails with JUnit5 assertEquals.
We are comparing two Object[]. Therefore we should use assertArrayEquals instead.

What precondition(s) should be checked before applying this recipe?

Describe the situation before applying the recipe

assertEquals(Lists.newArrayList("Loopback0", "GigabitEthernet0/0/0/2")
                        .toArray(),
                AreaInterfaceReader.parseInterfaceIds(OUTPUT)
                        .stream()
                        .map(InterfaceKey::getId)
                        .toArray());

Describe the situation after applying the recipe

assertArrayEquals(Lists.newArrayList("Loopback0", "GigabitEthernet0/0/0/2")
                        .toArray(),
                AreaInterfaceReader.parseInterfaceIds(OUTPUT)
                        .stream()
                        .map(InterfaceKey::getId)
                        .toArray());

Have you considered any alternatives or workarounds?

Any additional context

I think currently it is not differentiated whether the compared types are just objects or arrays of objects.

Are you interested in contributing this recipe to OpenRewrite?

@timtebeek timtebeek added the bug Something isn't working label Jul 18, 2023
@timtebeek timtebeek moved this to Backlog in OpenRewrite Jul 18, 2023
@timtebeek timtebeek added the good first issue Good for newcomers label Jul 18, 2023
@timtebeek
Copy link
Contributor

Thanks for reporting this issue here and in Slack! Indeed looks like a case we had not consciously covered before, so great to have a sample and see if we can implement a quick fix; Would you be willing to help kick start development with a Draft pull request that adds Assert.assertEquals(new Object[1], new Object[1]); to the unit test fro AssertToAssertionsTest? From there it should then be easy to step through with the debugger and potentially even contribute the fix.

@timtebeek timtebeek linked a pull request Jul 19, 2023 that will close this issue
4 tasks
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenRewrite Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Archived in project
2 participants