Skip to content

Commit

Permalink
Drop now removed unnecessary import
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Jan 3, 2025
1 parent b9fa756 commit ff78e07
Showing 1 changed file with 69 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ String getField() {
java(
"""
import static org.junit.Assert.assertEquals;
class MyTest {
void foo() {
Entity entity = new Entity();
Expand All @@ -67,7 +67,7 @@ void foo() {
""",
"""
import static org.junit.jupiter.api.Assertions.assertEquals;
class MyTest {
void foo() {
Entity entity = new Entity();
Expand Down Expand Up @@ -108,7 +108,7 @@ String getName() {
""",
"""
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
public class MyTest {
Expand Down Expand Up @@ -148,7 +148,7 @@ public void test() {
""",
"""
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
public class MyTest {
Expand All @@ -170,9 +170,9 @@ void assertWithoutMessage() {
java(
"""
import org.junit.Assert;
class MyTest {
void foo() {
Assert.assertEquals(1, 2);
Assert.assertArrayEquals(new int[]{}, new int[]{});
Expand All @@ -194,9 +194,9 @@ void foo() {
""",
"""
import org.junit.jupiter.api.Assertions;
class MyTest {
void foo() {
Assertions.assertEquals(1, 2);
Assertions.assertArrayEquals(new int[]{}, new int[]{});
Expand Down Expand Up @@ -227,9 +227,9 @@ void staticAssertWithoutMessage() {
java(
"""
import static org.junit.Assert.*;
class MyTest {
void foo() {
assertEquals(1, 2);
assertArrayEquals(new int[]{}, new int[]{});
Expand All @@ -244,9 +244,9 @@ void foo() {
""",
"""
import static org.junit.jupiter.api.Assertions.*;
class MyTest {
void foo() {
assertEquals(1, 2);
assertArrayEquals(new int[]{}, new int[]{});
Expand All @@ -270,9 +270,9 @@ void assertWithMessage() {
java(
"""
import org.junit.Assert;
class MyTest {
void foo() {
Assert.assertEquals("One is one", 1, 1);
Assert.assertArrayEquals("Empty is empty", new int[]{}, new int[]{});
Expand All @@ -291,9 +291,9 @@ void foo() {
""",
"""
import org.junit.jupiter.api.Assertions;
class MyTest {
void foo() {
Assertions.assertEquals(1, 1, "One is one");
Assertions.assertArrayEquals(new int[]{}, new int[]{}, "Empty is empty");
Expand Down Expand Up @@ -327,7 +327,7 @@ void staticallyImportAssertions() {
java(
"""
import org.junit.Assert;
class Test {
void test() {
Assert.assertEquals("One is one", 1, 1);
Expand All @@ -336,7 +336,7 @@ void test() {
""",
"""
import static org.junit.jupiter.api.Assertions.assertEquals;
class Test {
void test() {
assertEquals(1, 1, "One is one");
Expand All @@ -355,7 +355,7 @@ void swapAssertTrueArgumentsWhenMessageIsBinaryExpression() {
java(
"""
import org.junit.Assert;
class Test {
void test() {
Assert.assertTrue("one" + "one", true);
Expand All @@ -364,7 +364,7 @@ void test() {
""",
"""
import org.junit.jupiter.api.Assertions;
class Test {
void test() {
Assertions.assertTrue(true, "one" + "one");
Expand Down Expand Up @@ -392,7 +392,7 @@ void testNestedPartitionStepStepReference() {
""",
"""
import static org.junit.jupiter.api.Assertions.assertNotNull;
class MyTest {
Long l = 1L;
void testNestedPartitionStepStepReference() {
Expand All @@ -412,7 +412,7 @@ void assertThrows() {
java(
"""
import static org.junit.Assert.assertThrows;
class Test {
void test(Runnable run) {
assertThrows(
Expand All @@ -430,7 +430,7 @@ void test(Runnable run) {
""",
"""
import static org.junit.jupiter.api.Assertions.assertThrows;
class Test {
void test(Runnable run) {
assertThrows(
Expand Down Expand Up @@ -458,7 +458,7 @@ void missingTypeInfo() {
java(
"""
import static org.junit.Assert.*;
class MyTest {
void test() {
assertNotNull(UnknownType.unknownMethod());
Expand All @@ -467,7 +467,7 @@ void test() {
""",
"""
import static org.junit.jupiter.api.Assertions.*;
class MyTest {
void test() {
assertNotNull(UnknownType.unknownMethod());
Expand All @@ -478,8 +478,6 @@ void test() {
);
}

// The retained org.junit.Assert import is not ideal,
// but if this recipe is invoked within JUnit4to5Migration, then it gets removed by CleanupJUnitImports
@Test
void migratesAssertStatementsWithMissingTypeInfo() {
//language=java
Expand All @@ -488,17 +486,16 @@ void migratesAssertStatementsWithMissingTypeInfo() {
java(
"""
import static org.junit.Assert.assertNotNull;
class MyTest {
void test() {
assertNotNull(UnknownType.unknownMethod());
}
}
""",
"""
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
class MyTest {
void test() {
assertNotNull(UnknownType.unknownMethod());
Expand All @@ -509,49 +506,49 @@ void test() {
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/515")
void verifyClassExtendsAssertMethodArgumentsOrderRetained() {
//language=java
rewriteRun(
java(
"""
package foo;
import org.junit.Assert;
public class Verify extends Assert {
public static void assertContains(String expected, String actual) {
@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/515")
void verifyClassExtendsAssertMethodArgumentsOrderRetained() {
//language=java
rewriteRun(
java(
"""
package foo;
import org.junit.Assert;
public class Verify extends Assert {
public static void assertContains(String expected, String actual) {
}
}
}
""",
SourceSpec::skip
),
java(
"""
import foo.Verify;
import org.junit.Assert;
import java.util.List;
class A {
void test(String message, String expected, String actual) {
Verify.assertContains(expected, actual);
Assert.assertEquals(message, expected, actual);
""",
SourceSpec::skip
),
java(
"""
import foo.Verify;
import org.junit.Assert;
import java.util.List;
class A {
void test(String message, String expected, String actual) {
Verify.assertContains(expected, actual);
Assert.assertEquals(message, expected, actual);
}
}
}
""",
"""
import foo.Verify;
import org.junit.jupiter.api.Assertions;
import java.util.List;
class A {
void test(String message, String expected, String actual) {
Verify.assertContains(expected, actual);
Assertions.assertEquals(expected, actual, message);
""",
"""
import foo.Verify;
import org.junit.jupiter.api.Assertions;
import java.util.List;
class A {
void test(String message, String expected, String actual) {
Verify.assertContains(expected, actual);
Assertions.assertEquals(expected, actual, message);
}
}
}
"""
)
);
}
"""
)
);
}
}

0 comments on commit ff78e07

Please sign in to comment.