/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemExitJUnit4UnitTest.java
29 строк
868 B
Ashley Frieze
BAEL-4742 System Stubs example tests
25 ноя 2020, 02:38
25 ноя 2020, 02:38
3c01b8f
Код
Авторство
О чём код?
package com.baeldung.systemstubs; import org.junit.Rule; import org.junit.Test; import uk.org.webcompere.systemstubs.rules.SystemExitRule; import uk.org.webcompere.systemstubs.security.AbortExecutionException; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; public class SystemExitJUnit4UnitTest { @Rule public SystemExitRule systemExitRule = new SystemExitRule(); @Test public void whenAccidentalSystemExit_thenTestFailsRatherThanJVMKilled() { // uncomment this to try it //System.exit(1); } @Test public void whenExit_thenExitCodeIsAvailable() { assertThatThrownBy(() -> { System.exit(123); }).isInstanceOf(AbortExecutionException.class); assertThat(systemExitRule.getExitCode()).isEqualTo(123); } }