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

Add a default constructor for test only to pass testing in Java recipe guide. #326

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

addozhang
Copy link
Contributor

What's changed?

java.lang.AssertionError: [Recipe must be able to instantiate via RecipeIntrospectionUtils] 
Expecting code not to raise a throwable but caught
  "org.openrewrite.config.RecipeIntrospectionException: Unable to call primary constructor for Recipe class ...
...

I found this is issue with this commit. In this commit, The RewriteTest will invoke RecipeIntrospectionUtils.constructRecipe(recipe.getClass()) to do some validation. This requires our recipe should contain a default constructor.

Add a default constructor will fix it.

    @TestOnly
    public SayHelloRecipe() {
        fullyQualifiedClassName = "";
    }    

Have you considered any alternatives or workarounds?

Not sure.

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

To minimize what folks need on the classpath.
@timtebeek
Copy link
Contributor

Thanks a lot for the fix here @addozhang , also for pulling in that context of where it now fails. I've removed the @TestOnly annotation as we want to minimize what folks need to have available, as we similarly stripped Lombok from the test examples as well. With that we're good to merge. ❤️

@timtebeek timtebeek merged commit 7a0a16b into openrewrite:master Nov 26, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants