Skip to content

Commit

Permalink
don't exclude junit4 for testcontainers jupiter (#641)
Browse files Browse the repository at this point in the history
* don't exclude junit4 for testcontainers jupiter

* Use glob to remove junit exclusion from `org.testcontainers:*`

---------

Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
sullis and timtebeek authored Nov 17, 2024
1 parent 89968a5 commit 5091a38
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/rewrite/junit5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ recipeList:
# Workaround for https://github.com/testcontainers/testcontainers-java/issues/970:
- org.openrewrite.maven.RemoveExclusion:
groupId: org.testcontainers
artifactId: testcontainers
artifactId: '*'
exclusionGroupId: junit
exclusionArtifactId: junit
# Similar for https://github.com/openrewrite/rewrite-testing-frameworks/issues/477
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 5091a38

Please sign in to comment.