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

JUnitAssertThrowsToAssertExceptionType does not convert cases where executable is a variable #511

Open
timtebeek opened this issue Apr 23, 2024 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@timtebeek
Copy link
Contributor

timtebeek commented Apr 23, 2024

What version of OpenRewrite are you using?

What is the smallest, simplest way to reproduce the problem?

import org.junit.jupiter.api.function.Executable;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class SimpleExpectedExceptionTest {
    public void throwsExceptionWithSpecificType() {
        Executable executable = () -> {
            throw new NullPointerException();
        };
        assertThrows(NullPointerException.class, executable);
    }
}

What did you expect to see?

import org.assertj.core.api.ThrowableAssert.ThrowingCallable;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class SimpleExpectedExceptionTest {
    public void throwsExceptionWithSpecificType() {
        ThrowingCallable executable = () -> {
            throw new NullPointerException();
        };
        assertThatExceptionOfType(NullPointerException.class).isThrownBy(executable);
    }
}

What did you see instead?

No change, as the recipe fails to match the case where the argument is a variable.

J executable = mi.getArguments().get(1);
if (executable instanceof J.Lambda) {
executable = ((J.Lambda) executable).withType(THROWING_CALLABLE_TYPE);
} else if (executable instanceof J.MemberReference) {
executable = ((J.MemberReference) executable).withType(THROWING_CALLABLE_TYPE);
} else {
executable = null;

Additional context

As reported on

@timtebeek timtebeek added bug Something isn't working good first issue Good for newcomers labels Apr 23, 2024
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
Status: Recipes Wanted
Development

No branches or pull requests

1 participant