Skip to content

Commit

Permalink
Format and suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurens-W committed Sep 12, 2024
1 parent b865ce4 commit a99e5d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
List<Statement> statementsAfterWhen = new ArrayList<>();
for (Statement stmt : m.getBody().getStatements()) {
if (stmt instanceof J.MethodInvocation &&
MOCKITO_WHEN.matches(((J.MethodInvocation)stmt).getSelect())) {
J.MethodInvocation when = (J.MethodInvocation)((J.MethodInvocation) stmt).getSelect();
if (when.getArguments().get(0) instanceof J.MethodInvocation && ((J.MethodInvocation)when.getArguments().get(0)).getMethodType().getFlags().contains(Flag.Static)){
MOCKITO_WHEN.matches(((J.MethodInvocation) stmt).getSelect())) {
J.MethodInvocation when = (J.MethodInvocation) ((J.MethodInvocation) stmt).getSelect();
if (when.getArguments().get(0) instanceof J.MethodInvocation && ((J.MethodInvocation) when.getArguments().get(0)).getMethodType().getFlags().contains(Flag.Static)) {
JavaType.FullyQualified arg_fq = TypeUtils.asFullyQualified(when.getArguments().get(0).getType());
String template = String.format("try(MockedStatic<%s> mock%s = mockStatic(%s.class)){\n" +
"mock%s.when(%s::%s).thenReturn(%s);\n" +
"}", arg_fq.getClassName(), arg_fq.getClassName(), arg_fq.getClassName(), arg_fq.getClassName(), arg_fq.getClassName(), ((J.MethodInvocation)when.getArguments().get(0)).getSimpleName(), ((J.MethodInvocation) stmt).getArguments().get(0));
"}", arg_fq.getClassName(), arg_fq.getClassName(), arg_fq.getClassName(), arg_fq.getClassName(), arg_fq.getClassName(), ((J.MethodInvocation) when.getArguments().get(0)).getSimpleName(), ((J.MethodInvocation) stmt).getArguments().get(0));
m = JavaTemplate.builder(template)
.contextSensitive()
.javaParser(JavaParser.fromJavaVersion())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import static org.openrewrite.java.Assertions.java;

public class MockitoWhenOnStaticToMockStaticTest implements RewriteTest {
class MockitoWhenOnStaticToMockStaticTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
Expand Down

0 comments on commit a99e5d6

Please sign in to comment.