diff --git a/src/test/java/org/openrewrite/java/testing/mockito/MockUtilsToStaticTest.java b/src/test/java/org/openrewrite/java/testing/mockito/MockUtilsToStaticTest.java index dbe746cc3..1b166f84d 100644 --- a/src/test/java/org/openrewrite/java/testing/mockito/MockUtilsToStaticTest.java +++ b/src/test/java/org/openrewrite/java/testing/mockito/MockUtilsToStaticTest.java @@ -15,6 +15,7 @@ */ package org.openrewrite.java.testing.mockito; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; import org.openrewrite.InMemoryExecutionContext; @@ -98,6 +99,79 @@ public void isMockExample() { ); } + @Disabled("The single-file use analysis removes a MockUtil field still referenced from another source file, so that file no longer compiles") + @Test + void doNotRemoveFieldUsedInAnotherClass() { + //language=java + rewriteRun( + java( + """ + package mockito.example; + + import org.mockito.internal.util.MockUtil; + + public class MockitoMockUtils { + public MockUtil util = new MockUtil(); + } + """ + ), + java( + """ + package mockito.example; + + public class MockitoMockUtilsUser { + public boolean isMockUtilSet(MockitoMockUtils utils) { + return utils.util != null; + } + } + """ + ) + ); + } + + @Disabled("A fully migrated MockUtil declaration directly under a case label is not removed because its parent is the case, not a block") + @Test + void mockUtilsVariableInSwitchCaseToStatic() { + //language=java + rewriteRun( + java( + """ + package mockito.example; + + import org.mockito.internal.util.MockUtil; + + public class MockitoMockUtils { + public boolean isMockExample(int mode, Object value) { + switch (mode) { + case 1: + MockUtil util = new MockUtil(); + return util.isMock(value); + default: + return false; + } + } + } + """, + """ + package mockito.example; + + import org.mockito.internal.util.MockUtil; + + public class MockitoMockUtils { + public boolean isMockExample(int mode, Object value) { + switch (mode) { + case 1: + return MockUtil.isMock(value); + default: + return false; + } + } + } + """ + ) + ); + } + @Test void mockUtilsFieldToStatic() { //language=java