Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert lambda block to expression after adopting assertThrows #582

Merged
merged 6 commits into from
Aug 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,62 @@ public void test() {
);
}

@Test
void assertThrowsSingleLineInlined() {
//language=java
rewriteRun(
java(
"""
import org.junit.Test;

public class MyTest {

@Test(expected = IllegalArgumentException.class)
public void test() {
foo();
}
private void foo() {
throw new IllegalArgumentException("boom");
}
}
""",
"""
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class MyTest {

@Test
public void test() {
assertThrows(IllegalArgumentException.class, () -> foo());
}
private void foo() {
throw new IllegalArgumentException("boom");
}
}
"""
)
);
}

@SuppressWarnings("ConstantConditions")
@Test
void assertThrowsSingleStatement() {
//language=java
rewriteRun(
java(
"""
import org.junit.Test;

public class MyTest {

@Test(expected = IndexOutOfBoundsException.class)
public void test() {
int arr = new int[]{}[0];
}
import org.junit.Test;

public class MyTest {

@Test(expected = IndexOutOfBoundsException.class)
public void test() {
int arr = new int[]{}[0];
}
""",
}
""",
"""
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -562,7 +601,7 @@ public void testWithThrows() throws IOException {
// Second call shows why we wrap the entire method body in the lambda
foo();
}

void foo() throws IOException {
throw new IOException();
}
Expand All @@ -585,7 +624,7 @@ public void testWithThrows() {
foo();
});
}

void foo() throws IOException {
throw new IOException();
}
Expand Down
Loading