/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemPropertiesExecuteAroundUnitTest.java
31 строка
1009 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.jupiter.api.Test; import uk.org.webcompere.systemstubs.properties.SystemProperties; import static org.assertj.core.api.Assertions.assertThat; import static uk.org.webcompere.systemstubs.SystemStubs.restoreSystemProperties; class SystemPropertiesExecuteAroundUnitTest { @Test void givenRestoreSystemProperties_thenPropertyRestored() throws Exception { restoreSystemProperties(() -> { // test code System.setProperty("unrestored", "true"); }); assertThat(System.getProperty("unrestored")).isNull(); } @Test void givenSystemPropertiesObject_thenPropertyRestored() throws Exception { String result = new SystemProperties() .execute(() -> { System.setProperty("unrestored", "true"); return "it works"; }); assertThat(result).isEqualTo("it works"); assertThat(System.getProperty("unrestored")).isNull(); } }