Skip to content

Commit

Permalink
Implement fail() migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Philzen committed Jun 12, 2024
1 parent d760e6f commit 25a7d94
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ public static class MigrateAssertNullWithMsg {
Assertions.assertNull(expr, msg);
}
}
<<<<<<< HEAD
=======

@RecipeDescriptor(
name = "Replace `Assert#assertNotNull(Object)`",
Expand Down Expand Up @@ -322,5 +320,4 @@ public static class MigrateFailWithMessageAndCause {
Assertions.fail(message, cause);
}
}
>>>>>>> 3c937e8 (fixup! Implement assertNull() migration)
}
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ void testMethod() {

@Test void withErrorMessage() {
//language=java
rewriteRun(java("""
rewriteRun(java(
"""
import org.testng.Assert;
class MyTest {
Expand All @@ -572,7 +573,8 @@ void testMethod() {

@Test void withoutErrorMessage() {
//language=java
rewriteRun(java("""
rewriteRun(java(
"""
import org.testng.Assert;
class MyTest {
Expand All @@ -599,7 +601,8 @@ void testMethod() {

@Test void withErrorMessage() {
// language=java
rewriteRun(java("""
rewriteRun(java(
"""
import org.testng.Assert;
class MyTest {
Expand All @@ -622,7 +625,8 @@ void testMethod() {

@Test void withoutErrorMessage() {
// language=java
rewriteRun(java("""
rewriteRun(java(
"""
import org.testng.Assert;
class MyTest {
Expand All @@ -643,4 +647,80 @@ void testMethod() {
));
}
}

@Nested class MigrateFail {

@Test void withNoArguments() {
//language=java
rewriteRun(java(
"""
import org.testng.Assert;
class MyTest {
void testMethod() {
Assert.fail();
}
}
""",
"""
import org.junit.jupiter.api.Assertions;
class MyTest {
void testMethod() {
Assertions.fail();
}
}
"""
));
}

@Test void withMessage() {
// language=java
rewriteRun(java(
"""
import org.testng.Assert;
class MyTest {
void testMethod() {
Assert.fail("Boom!");
}
}
""",
"""
import org.junit.jupiter.api.Assertions;
class MyTest {
void testMethod() {
Assertions.fail("Boom!");
}
}
"""
));
}

@Test void withMessageAndException() {
rewriteRun(
// language=java
java(
"""
import org.testng.Assert;
class MyTest {
void testMethod() {
Assert.fail("Boom!", new Exception("Halted and caught fire."));
}
}
""",
"""
import org.junit.jupiter.api.Assertions;
class MyTest {
void testMethod() {
Assertions.fail("Boom!", new Exception("Halted and caught fire."));
}
}
"""
));
}
}
}

0 comments on commit 25a7d94

Please sign in to comment.