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

Reordering of assert parameters partially broken #30

Open
nkiesel opened this issue Jun 10, 2021 · 0 comments
Open

Reordering of assert parameters partially broken #30

nkiesel opened this issue Jun 10, 2021 · 0 comments

Comments

@nkiesel
Copy link

nkiesel commented Jun 10, 2021

The reordering of assert parameters should only happen if the assertion has a description parameter:

org.junit.Assert.assertEquals("Greeting broken", "Hello, world!", suspect.generateGreeting()); is correctly converted to
org.junit.jupiter.api.Assertions.assertEquals("Hello, world!", suspect.generateGreeting(), "Greeting broken");

However, parameters to asserts w/o the description parameter should be kept unchanged. Right now, org.junit.Assert.assertEquals("Hello, world!", suspect.generateGreeting()); is incorrectly converted to
org.junit.jupiter.api.Assertions.assertEquals(suspect.generateGreeting(), "Hello, world!"); (ie. expected and actual are swapped).

Looks to me the fix would be to add a "check number of parameters" test to

    if ("assertTrue".equals(methodName) || "assertFalse".equals(methodName) || "assertNotNull".equals(methodName) ||
                    "assertArrayEquals".equals(methodName) || "assertEquals".equals(methodName) ||
                    "assertNotEquals".equals(methodName)) {
              pushFirstAsLastArgument(methodCallExpr, "Assertions");
     }
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

No branches or pull requests

1 participant