Skip to content

Commit

Permalink
Add unit to @Timeout (#451)
Browse files Browse the repository at this point in the history
Fixes #450
  • Loading branch information
timtebeek authored Jan 4, 2024
1 parent 326c048 commit af84b02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,17 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
}
}
if (cta.timeout != null) {
m = JavaTemplate.builder("@Timeout(#{any(long)})")
m = JavaTemplate.builder("@Timeout(value = #{any(long)}, unit = TimeUnit.MILLISECONDS)")
.javaParser(javaParser(ctx))
.imports("org.junit.jupiter.api.Timeout")
.imports("org.junit.jupiter.api.Timeout", "java.util.concurrent.TimeUnit")
.build()
.apply(
updateCursor(m),
m.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName)),
cta.timeout
);
maybeAddImport("org.junit.jupiter.api.Timeout");
maybeAddImport("java.util.concurrent.TimeUnit");
}
maybeAddImport("org.junit.jupiter.api.Test");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ public void test2() {
}

@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/450")
void annotationWithTimeout() {
//language=java
rewriteRun(
Expand All @@ -290,10 +291,12 @@ public void test() {
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.util.concurrent.TimeUnit;
public class MyTest {
@Test
@Timeout(500)
@Timeout(value = 500, unit = TimeUnit.MILLISECONDS)
public void test() {
}
}
Expand Down Expand Up @@ -369,12 +372,14 @@ public void test() {
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class MyTest {
@Test
@Timeout(500)
@Timeout(value = 500, unit = TimeUnit.MILLISECONDS)
public void test() {
assertThrows(IllegalArgumentException.class, () -> {
throw new IllegalArgumentException("boom");
Expand Down Expand Up @@ -518,7 +523,7 @@ public void feature1() {
}
@Test
void feature2() {
public void feature2() {
}
}
""",
Expand All @@ -531,7 +536,7 @@ public void feature1() {
}
@Test
void feature2() {
public void feature2() {
}
}
"""
Expand Down

0 comments on commit af84b02

Please sign in to comment.