openrewrite / rewrite-testing-frameworks

OpenRewrite recipes that perform common Java testing migration tasks.
Apache License 2.0
77 stars 73 forks source link

Refactor `Mockito.when` on static (non mock) to try with resource #601

Closed Laurens-W closed 2 months ago

Laurens-W commented 2 months ago

What's your motivation?

Mockito.when on static (non mock) is no longer allowed with Mockito 4

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

@timtebeek

Checklist

timtebeek commented 2 months ago

I'm seeing failures with

java.lang.IllegalStateException: LST contains missing or invalid type information   
Identifier->ParameterizedType->VariableDeclarations->Resource->Try->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit  
/*~~(Identifier type is missing or malformed)~~>*/A 
Identifier->FieldAccess->MethodInvocation->NamedVariable->VariableDeclarations->Resource->Try->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit   
/*~~(Identifier type is missing or malformed)~~>*/A 
Identifier->MethodInvocation->MethodInvocation->Block->Try->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit  
/*~~(Identifier type is missing or malformed)~~>*/mockA 
MemberReference->MethodInvocation->MethodInvocation->Block->Try->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit 
/*~~(MemberReference type is missing or malformed)~~>*//*~~(Identifier type is missing or malformed)~~>*/A::getA    
Identifier->MemberReference->MethodInvocation->MethodInvocation->Block->Try->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit 
/*~~(Identifier type is missing or malformed)~~>*/A 
Identifier->MethodInvocation->Block->Try->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit    
/*~~(Identifier type is missing or malformed)~~>*/aMock 

Would you already want me to have a look? Or are you still exploring those?

timtebeek commented 2 months ago

Also: could you hook this recipe into the Mockito migration already? That way we can't forget that step.

Laurens-W commented 2 months ago

I'm seeing failures with

java.lang.IllegalStateException: LST contains missing or invalid type information 
Identifier->ParameterizedType->VariableDeclarations->Resource->Try->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit    
/*~~(Identifier type is missing or malformed)~~>*/A   
Identifier->FieldAccess->MethodInvocation->NamedVariable->VariableDeclarations->Resource->Try->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit 
/*~~(Identifier type is missing or malformed)~~>*/A   
Identifier->MethodInvocation->MethodInvocation->Block->Try->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit    
/*~~(Identifier type is missing or malformed)~~>*/mockA   
MemberReference->MethodInvocation->MethodInvocation->Block->Try->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit   
/*~~(MemberReference type is missing or malformed)~~>*//*~~(Identifier type is missing or malformed)~~>*/A::getA  
Identifier->MemberReference->MethodInvocation->MethodInvocation->Block->Try->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit   
/*~~(Identifier type is missing or malformed)~~>*/A   
Identifier->MethodInvocation->Block->Try->Block->MethodDeclaration->Block->ClassDeclaration->CompilationUnit  
/*~~(Identifier type is missing or malformed)~~>*/aMock   

Would you already want me to have a look? Or are you still exploring those?

I'll have a look tomorrow, am aware of them :)