Skip to content

Commit

Permalink
When mockito mockStatic is used as variable initializer we shouldn'…
Browse files Browse the repository at this point in the history
…t return null
  • Loading branch information
Laurens-W committed Sep 30, 2024
1 parent 823e3c3 commit 659ba4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx)

if (MOCKED_STATIC_MATCHER.matches(mi)) {
determineTestGroups();
if (!getCursor().getPath(o -> o instanceof J.Assignment || o instanceof J.Try.Resource).hasNext()) {
if (!getCursor().getPath(o -> o instanceof J.VariableDeclarations ||
o instanceof J.Assignment ||
o instanceof J.Try.Resource).hasNext()) {
//noinspection DataFlowIssue
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,23 @@ public void testStaticMethod() {
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/611")
void existingMockitoMockStaticShouldNotBeTouched() {
//language=java
rewriteRun(
java(
"""
import static org.mockito.Mockito.mockStatic;
import org.mockito.MockedStatic;
class TestClass {
MockedStatic<String> mocked = mockStatic(String.class);
}
"""));
}

@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/358")
void doesNotExplodeOnTopLevelMethodDeclaration() {
Expand Down

0 comments on commit 659ba4e

Please sign in to comment.