Skip to content

Commit

Permalink
Apply formatter to PowerMockitoMockStaticToMockito
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Aug 26, 2024
1 parent fb81b3e commit 8145e8b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private static class PowerMockitoToMockitoVisitor extends JavaVisitor<ExecutionC
private static final MethodMatcher DYNAMIC_WHEN_METHOD_MATCHER = new MethodMatcher("org.mockito.Mockito when(java.lang.Class, String, ..)");
private static final String MOCK_PREFIX = "mocked";
private static final String TEST_GROUP = "testGroup";

private String setUpMethodAnnotationSignature;
private String setUpMethodAnnotation;
private String tearDownMethodAnnotationSignature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void testStaticMethod() {
import org.mockito.MockedStatic;
public class MyTest {
private MockedStatic<Calendar> mockedCalendar;
@BeforeEach
Expand Down Expand Up @@ -219,38 +219,38 @@ void tearDownMethodOfTestNGHasAnnotationWithArgument() {
java(
"""
import java.util.Calendar;
import org.testng.annotations.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;
@PrepareForTest({Calendar.class})
public class MyTest {
@Test
void testSomething() { }
}
""",
"""
import java.util.Calendar;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class MyTest {
@BeforeMethod
void setUpStaticMocks() {
}
@AfterMethod(alwaysRun = true)
void tearDownStaticMocks() {
}
@Test
void testSomething() { }
}
"""
)
Expand All @@ -264,41 +264,41 @@ void tearDownMethodOfTestNGWithAnnotationRemainsUntouched() {
java(
"""
import java.util.Calendar;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;
@PrepareForTest({Calendar.class})
public class MyTest {
@AfterMethod(groups = "irrelevant")
void tearDown() {}
@Test
void testSomething() { }
}
""",
"""
import java.util.Calendar;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class MyTest {
@AfterMethod(groups = "irrelevant")
void tearDown() {}
@BeforeMethod
void setUpStaticMocks() {
}
@Test
void testSomething() { }
}
"""
)
Expand All @@ -312,22 +312,22 @@ void tearDownMethodOfTestNGHasAnnotationWithSameArgumentsAsTheTestThatCallsMockS
java(
"""
import java.util.Calendar;
import static org.mockito.Mockito.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;
@PrepareForTest({Calendar.class})
public class MyTest {
private Calendar calendarMock;
@Test(groups = "irrelevant")
void testSomethingIrrelevantForCheckin() { }
@Test(groups = "checkin")
void testStaticMethod() {
calendarMock = mock(Calendar.class);
Expand All @@ -338,33 +338,33 @@ void testStaticMethod() {
""",
"""
import java.util.Calendar;
import static org.mockito.Mockito.*;
import org.mockito.MockedStatic;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class MyTest {
private MockedStatic<Calendar> mockedCalendar;
private Calendar calendarMock;
@BeforeMethod(groups = "checkin")
void setUpStaticMocks() {
mockedCalendar = mockStatic(Calendar.class);
}
@AfterMethod(groups = "checkin")
void tearDownStaticMocks() {
mockedCalendar.closeOnDemand();
}
@Test(groups = "irrelevant")
void testSomethingIrrelevantForCheckin() { }
@Test(groups = "checkin")
void testStaticMethod() {
calendarMock = mock(Calendar.class);
Expand All @@ -383,19 +383,19 @@ void argumentOfWhenOnStaticMethodWithParametersIsReplacedByLambda() {
java(
"""
import static org.mockito.Mockito.*;
import java.util.Calendar;
import java.util.Locale;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
public class MyTest {
private MockedStatic<Calendar> mockedCalendar;
private Calendar calendarMock = mock(Calendar.class);
@Test
void testStaticMethod() {
when(Calendar.getInstance(Locale.ENGLISH)).thenReturn(calendarMock);
Expand All @@ -404,19 +404,19 @@ void testStaticMethod() {
""",
"""
import static org.mockito.Mockito.*;
import java.util.Calendar;
import java.util.Locale;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
public class MyTest {
private MockedStatic<Calendar> mockedCalendar;
private Calendar calendarMock = mock(Calendar.class);
@Test
void testStaticMethod() {
mockedCalendar.when(() -> Calendar.getInstance(Locale.ENGLISH)).thenReturn(calendarMock);
Expand All @@ -434,16 +434,16 @@ void argumentOfWhenOnInstanceMethodsAreNotReplaced() {
java(
"""
import static org.mockito.Mockito.*;
import java.util.Calendar;
import java.util.Locale;
import org.junit.jupiter.api.Test;
public class MyTest {
private Calendar calendarMock = mock(Calendar.class);
@Test
void testStaticMethod() {
when(calendarMock.toString()).thenReturn(null);
Expand All @@ -461,19 +461,19 @@ void argumentOfVerifyOnParameterlessStaticMethodIsReplacedBySimpleLambda() {
java(
"""
import static org.mockito.Mockito.*;
import java.util.Currency;
import java.util.Locale;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
public class MyTest {
private MockedStatic<Currency> mockedCurrency;
private Currency currencyMock = mock(Currency.class);
@Test
void testStaticMethod() {
verify(Currency.getInstance(Locale.ENGLISH), never());
Expand All @@ -483,19 +483,19 @@ void testStaticMethod() {
""",
"""
import static org.mockito.Mockito.*;
import java.util.Currency;
import java.util.Locale;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
public class MyTest {
private MockedStatic<Currency> mockedCurrency;
private Currency currencyMock = mock(Currency.class);
@Test
void testStaticMethod() {
mockedCurrency.verify(() -> Currency.getInstance(Locale.ENGLISH), never());
Expand All @@ -519,13 +519,13 @@ public interface MyInterface {
}
""")
, java(
"""
"""
public abstract class MyAbstractClass {
public boolean isItTrue() { return true; }
public abstract boolean isItImplemented();
}
"""
));
Expand All @@ -537,14 +537,14 @@ void extensionOfPowerMockTestCaseGetsRemoved() {
rewriteRun(java(
"""
package org.powermock.modules.testng;
public class PowerMockTestCase {}
"""
),
java(
"""
import org.powermock.modules.testng.PowerMockTestCase;
public class MyPowerMockTestCase extends PowerMockTestCase {}
""",
"""
Expand All @@ -560,14 +560,14 @@ void extensionOfPowerMockConfigurationGetsRemoved() {
java(
"""
package org.powermock.configuration;
public class PowerMockConfiguration {}
"""
),
java(
"""
import org.powermock.configuration.PowerMockConfiguration;
public class MyPowerMockConfiguration extends PowerMockConfiguration {}
""",
"""
Expand Down Expand Up @@ -608,6 +608,7 @@ void doesNotExplodeOnTopLevelMethodDeclaration() {
rewriteRun(
groovy(
"def myFun() { }"
));
)
);
}
}

0 comments on commit 8145e8b

Please sign in to comment.