Skip to content

Commit 10d68c7

Browse files
committed
Use assertThrows() in MiscTest
* There is no exception for the caller of Context#close(true)
1 parent e348f68 commit 10d68c7

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/test/java/org/truffleruby/MiscTest.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
import static org.junit.Assert.assertTrue;
1616

1717
import org.graalvm.polyglot.Context;
18-
import org.graalvm.polyglot.PolyglotException;
1918
import org.graalvm.polyglot.Value;
20-
import org.junit.Assert;
2119
import org.junit.Test;
2220

2321
public class MiscTest {
@@ -49,26 +47,18 @@ public void timeoutExecution() throws Throwable {
4947
TestingThread thread = new TestingThread(() -> {
5048
try {
5149
Thread.sleep(1000);
52-
context.close(true);
5350
} catch (InterruptedException e) {
5451
throw new Error(e);
55-
} catch (PolyglotException e) {
56-
if (e.isCancelled()) {
57-
assertTrue(e.isCancelled());
58-
} else {
59-
throw e;
60-
}
6152
}
53+
context.close(true);
6254
});
6355

6456
context.eval("ruby", "init = 1");
6557
thread.start();
6658
try {
6759
String maliciousCode = "while true; end";
68-
context.eval("ruby", maliciousCode);
69-
Assert.fail();
70-
} catch (PolyglotException e) {
71-
assertTrue(e.isCancelled());
60+
RubyTest.assertThrows(() -> context.eval("ruby", maliciousCode),
61+
e -> assertTrue(e.isCancelled()));
7262
} finally {
7363
thread.join();
7464
}

0 commit comments

Comments
 (0)