Closed josemariavillar closed 2 years ago
Thanks @josemariavillar, I will have a look
@josemariavillar, I could reproduce the issue; thanks so much for the test project.
FindMissingTypes is one of the first tools I use when investigating invalid recipe results. The results show several missing types. Looking at your project, I found that it's using Lombok, which is not supported at this time.
user = /*~~(type is 'null')~~>*/User.builder().coUser(CTE_CO_USER)
.coUserModification("codification")
.tsModification(timestamp)
.build();
role = /*~~(type is 'null')~~>*/Role.builder().coRole(CTE_CO_ROLE)
.coUserModification("codification")
.tsModification(timestamp)
.build();
userRoleKey = /*~~(type is 'null')~~>*/UserRoleKey.builder().coUser(CTE_CO_USER).coRole(CTE_CO_ROLE)
.build();
userRole = /*~~(type is 'null')~~>*/UserRole.builder()
.id(userRoleKey)
.user(user)
.role(role)
.tsDelete(timestamp)
.coUserModification("codification")
.tsModification(timestamp)
.build();
}
@Test
void assertionsTest() {
/*~~(type is 'null')~~>*/assertNotNull(userRole.getId());
/*~~(type is 'null')~~>*/assertEquals(role, userRole.getRole());
/*~~(type is 'null')~~>*/assertEquals(user, userRole.getUser());
requires lombok support https://github.com/openrewrite/rewrite/issues/1297
Thanks for the information @pway99. I have a doubt about what you comment, in this specific case what is affecting the lombok library? I don't understand it.
Regardless, a possible solution while supporting Loombok is to add generically the "import static org.junit.jupiter.api.Assertions.*", thus avoiding any problems.
Hi @josemariavillar,
I have a doubt about what you comment, in this specific case what is affecting the lombok library? I don't understand it.
Thanks for asking, and please accept my apology for closing this issue with such a brief explanation.
In this specific case, the UserRole object uses Lombok annotations, so the UserRole.getId()
method is not a member of the source file parsed by the rewrite-java-parser when the plugin is executed.
As a result the assertNotNull(userRole.getId())
statement has a null method type.
Consequently, the Assertions.assertNotNull
import is not added by the AddImportVisitor
because its type does not exist on the source tree.
Regardless, a possible solution while supporting Lombok is to add generically the "import static org.junit.jupiter.api.Assertions.*", thus avoiding any problems.
Unfortunately, other recipes such as OrderImports
might unfold the stared import, and the original problem remains.
Thanks again for identifying these issues :)
Good afternoon, I am having problems when applying the SpringBoot2JUnit4to5Migration recipe in the following Test:
When I run the mvn rewrite:dryRun or mvn rewrite:run command I would expect the "import static " to update correctly, instead the import of "assertEquals" and "assertNotNull" are removed and not replaced by their corresponding ones in Junit5 causing it to not compile the code, as can be seen in the following result:
Attached is a test case where the problem can be reproduced and observed: https://github.com/josemariavillar/test_project/tree/assert_to_assertions