/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/SystemLambdaComparisonUnitTest.java
49 строк
2 KB
Ashley Frieze
BAEL-4742-Guide-To-System-Stubs
20 ноя 2020, 20:44
20 ноя 2020, 20:44
390b864
Код
Авторство
О чём код?
package com.baeldung.systemstubs; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; import uk.org.webcompere.systemstubs.jupiter.SystemStub; import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; import uk.org.webcompere.systemstubs.properties.SystemProperties; import static com.github.stefanbirkner.systemlambda.SystemLambda.restoreSystemProperties; import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable; import static org.junit.Assert.assertEquals; @ExtendWith(SystemStubsExtension.class) class SystemLambdaComparisonUnitTest { @SystemStub private EnvironmentVariables environmentVariables = new EnvironmentVariables("ADDRESS", "https://www.baeldung.com"); @SystemStub private SystemProperties systemProperties = new SystemProperties(); @Test void aSingleSystemLambda() throws Exception { restoreSystemProperties(() -> { System.setProperty("log_dir", "test/resources"); assertEquals("test/resources", System.getProperty("log_dir")); }); } @Test void multipleSystemLambdas() throws Exception { restoreSystemProperties(() -> { withEnvironmentVariable("URL", "https://www.baeldung.com") .execute(() -> { System.setProperty("log_dir", "test/resources"); assertEquals("test/resources", System.getProperty("log_dir")); assertEquals("https://www.baeldung.com", System.getenv("URL")); }); }); } @Test void multipleSystemStubs() { System.setProperty("log_dir", "test/resources"); assertEquals("test/resources", System.getProperty("log_dir")); assertEquals("https://www.baeldung.com", System.getenv("ADDRESS")); } }