3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-03 01:50:07 +01:00

Replace try-fail-catch-assert with assertThrows

Dieser Commit ist enthalten in:
Kenzie Togami 2019-07-15 16:19:28 -07:00
Ursprung 3b157b67c3
Commit 5c5c822f4b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 5D200B325E157A81

Datei anzeigen

@ -32,9 +32,10 @@ import org.mockito.Mockito;
import static java.lang.Math.atan2; import static java.lang.Math.atan2;
import static java.lang.Math.sin; import static java.lang.Math.sin;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class ExpressionTest { public class ExpressionTest {
@BeforeEach @BeforeEach
@ -67,56 +68,46 @@ public class ExpressionTest {
} }
@Test @Test
public void testErrors() throws ExpressionException { public void testErrors() {
// test lexer errors assertAll(
try { // test lexer errors
compile("#"); () -> {
fail("Error expected"); LexerException e = assertThrows(LexerException.class,
} catch (LexerException e) { () -> compile("#"));
assertEquals(0, e.getPosition(), "Error position"); assertEquals(0, e.getPosition(), "Error position");
} },
// test parser errors
// test parser errors () -> {
try { ParserException e = assertThrows(ParserException.class,
compile("x"); () -> compile("x"));
fail("Error expected"); assertEquals(0, e.getPosition(), "Error position");
} catch (ParserException e) { },
assertEquals(0, e.getPosition(), "Error position"); () -> {
} ParserException e = assertThrows(ParserException.class,
try { () -> compile("x()"));
compile("x()"); assertEquals(0, e.getPosition(), "Error position");
fail("Error expected"); },
} catch (ParserException e) { () -> assertThrows(ParserException.class,
assertEquals(0, e.getPosition(), "Error position"); () -> compile("(")),
} () -> assertThrows(ParserException.class,
try { () -> compile("x(")),
compile("("); // test overloader errors
fail("Error expected"); () -> {
} catch (ParserException ignored) {} ParserException e = assertThrows(ParserException.class,
try { () -> compile("atan2(1)"));
compile("x("); assertEquals(0, e.getPosition(), "Error position");
fail("Error expected"); },
} catch (ParserException ignored) {} () -> {
ParserException e = assertThrows(ParserException.class,
// test overloader errors () -> compile("atan2(1, 2, 3)"));
try { assertEquals(0, e.getPosition(), "Error position");
compile("atan2(1)"); },
fail("Error expected"); () -> {
} catch (ParserException e) { ParserException e = assertThrows(ParserException.class,
assertEquals(0, e.getPosition(), "Error position"); () -> compile("rotate(1, 2, 3)"));
} assertEquals(0, e.getPosition(), "Error position");
try { }
compile("atan2(1, 2, 3)"); );
fail("Error expected");
} catch (ParserException e) {
assertEquals(0, e.getPosition(), "Error position");
}
try {
compile("rotate(1, 2, 3)");
fail("Error expected");
} catch (ParserException e) {
assertEquals(0, e.getPosition(), "Error position");
}
} }
@Test @Test
@ -180,13 +171,11 @@ public class ExpressionTest {
} }
@Test @Test
public void testTimeout() throws Exception { public void testTimeout() {
try { EvaluationException e = assertThrows(EvaluationException.class,
simpleEval("for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}"); () -> simpleEval("for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}"),
fail("Loop was not stopped."); "Loop was not stopped.");
} catch (EvaluationException e) { assertTrue(e.getMessage().contains("Calculations exceeded time limit"));
assertTrue(e.getMessage().contains("Calculations exceeded time limit"));
}
} }
private double simpleEval(String expressionString) throws ExpressionException { private double simpleEval(String expressionString) throws ExpressionException {