Skip to content

Commit

Permalink
Add testcase as provided in #511
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurens-W committed Aug 8, 2024
1 parent ebd24fe commit a5f65ce
Showing 1 changed file with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ void memberReference() {
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class MemberReferenceTest {
public void throwsWithMemberReference() {
CompletableFuture<Boolean> future = new CompletableFuture<>();
assertThrows(ExecutionException.class, future::get);
Expand All @@ -89,9 +89,9 @@ public void throwsWithMemberReference() {
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class MemberReferenceTest {
public void throwsWithMemberReference() {
CompletableFuture<Boolean> future = new CompletableFuture<>();
assertThatExceptionOfType(ExecutionException.class).isThrownBy(future::get);
Expand All @@ -110,7 +110,7 @@ void assertThrowsAssignment() {
java(
"""
import static org.junit.jupiter.api.Assertions.assertThrows;
public class SimpleExpectedExceptionTest {
public void throwsExceptionWithSpecificType() {
NullPointerException npe = assertThrows(NullPointerException.class, () -> {
Expand All @@ -135,7 +135,7 @@ void assertThrowsTernaryAssignment() {
java(
"""
import static org.junit.jupiter.api.Assertions.assertThrows;
public class SimpleExpectedExceptionTest {
public void throwsExceptionWithSpecificType() {
NullPointerException npe = hashCode() == 42
Expand All @@ -149,4 +149,42 @@ public void throwsExceptionWithSpecificType() {
)
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/511")
void assertThrowsExecutableVariable() {
//language=java
rewriteRun(
java(
"""
import org.junit.jupiter.api.function.Executable;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class SimpleExpectedExceptionTest {
public void throwsExceptionWithSpecificType() {
Executable executable = () -> {
throw new NullPointerException();
};
assertThrows(NullPointerException.class, executable);
}
}
""",
"""
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class SimpleExpectedExceptionTest {
public void throwsExceptionWithSpecificType() {
ThrowingCallable executable = () -> {
throw new NullPointerException();
};
assertThatExceptionOfType(NullPointerException.class).isThrownBy(executable);
}
}
"""
)
);
}
}

0 comments on commit a5f65ce

Please sign in to comment.