Skip to content

Commit

Permalink
don't exclude junit4 for testcontainers jupiter
Browse files Browse the repository at this point in the history
  • Loading branch information
sullis committed Nov 17, 2024
1 parent 89968a5 commit 8852189
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/rewrite/junit5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ recipeList:
artifactId: testcontainers
exclusionGroupId: junit
exclusionArtifactId: junit
# Workaround for https://github.com/testcontainers/testcontainers-java/issues/970:
- org.openrewrite.maven.RemoveExclusion:
groupId: org.testcontainers
artifactId: junit-jupiter
exclusionGroupId: junit
exclusionArtifactId: junit
# Similar for https://github.com/openrewrite/rewrite-testing-frameworks/issues/477
- org.openrewrite.maven.RemoveExclusion:
groupId: org.springframework.boot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void classReference() {
java(
"""
import org.junit.Test;
public class Sample {
void method() {
Class<Test> c = Test.class;
Expand All @@ -64,7 +64,7 @@ void method() {
""",
"""
import org.junit.jupiter.api.Test;
public class Sample {
void method() {
Class<Test> c = Test.class;
Expand All @@ -85,10 +85,10 @@ void assertThatReceiver() {
"""
import org.junit.Assert;
import org.junit.Test;
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.containsInAnyOrder;
public class SampleTest {
@SuppressWarnings("ALL")
@Test
Expand All @@ -100,11 +100,11 @@ public void filterShouldRemoveUnusedConfig() {
""",
"""
import org.junit.jupiter.api.Test;
import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
public class SampleTest {
@SuppressWarnings("ALL")
@Test
Expand Down Expand Up @@ -178,6 +178,30 @@ void dontExcludeJunit4DependencyfromTestcontainers() {
rewriteRun(pomXml(before, before));
}

@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/429")
void dontExcludeJunit4DependencyfromTestcontainersJupiter() {
//language=xml
String before = """
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.jackson</groupId>
<artifactId>test-plugins</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.18.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""";
// Output identical, but we want to make sure we don't exclude junit4 from testcontainers
rewriteRun(pomXml(before, before));
}

@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/477")
void dontExcludeJunit4DependencyfromSpringBootTestcontainers() {
Expand Down Expand Up @@ -231,7 +255,7 @@ void assertEqualsWithArrayArgumentToAssertArrayEquals() {
java(
"""
import org.junit.Assert;
class MyTest {
void test() {
Assert.assertEquals(new Object[1], new Object[1]);
Expand All @@ -240,7 +264,7 @@ void test() {
""",
"""
import org.junit.jupiter.api.Assertions;
class MyTest {
void test() {
Assertions.assertArrayEquals(new Object[1], new Object[1]);
Expand All @@ -261,16 +285,16 @@ void migrateInheritedTestBeforeAfterAnnotations() {
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class AbstractTest {
@Before
public void before() {
}
@After
public void after() {
}
@Test
public void test() {
}
Expand All @@ -280,16 +304,16 @@ public void test() {
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class AbstractTest {
@BeforeEach
public void before() {
}
@AfterEach
public void after() {
}
@Test
public void test() {
}
Expand All @@ -301,10 +325,10 @@ public void test() {
public class A extends AbstractTest {
public void before() {
}
public void after() {
}
public void test() {
}
}
Expand All @@ -313,16 +337,16 @@ public void test() {
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class A extends AbstractTest {
@BeforeEach
public void before() {
}
@AfterEach
public void after() {
}
@Test
public void test() {
}
Expand Down

0 comments on commit 8852189

Please sign in to comment.