/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
testing-modules/testing-libraries-2/src/test/java/com/baeldung/systemstubs/GettingStartedWithSystemStubsJUnit4UnitTest.java
58 строк
2 KB
Ashley Frieze
BAEL-4742 System Stubs example tests
25 ноя 2020, 02:38
25 ноя 2020, 02:38
3c01b8f
Код
Авторство
О чём код?
package com.baeldung.systemstubs; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import uk.org.webcompere.systemstubs.rules.EnvironmentVariablesRule; import static org.assertj.core.api.Assertions.assertThat; @RunWith(Enclosed.class) public class GettingStartedWithSystemStubsJUnit4UnitTest { public static class SetEnvironmentInsideTest { @Rule public EnvironmentVariablesRule environmentVariablesRule = new EnvironmentVariablesRule(); @Test public void givenEnvironmentCanBeModified_whenSetEnvironment_thenItIsSet() { environmentVariablesRule.set("ENV", "value1"); assertThat(System.getenv("ENV")).isEqualTo("value1"); } } public static class SetEnvironmentAtConstruction { @Rule public EnvironmentVariablesRule environmentVariablesRule = new EnvironmentVariablesRule("ENV", "value1", "ENV2", "value2"); @Test public void givenEnvironmentCanBeModified_whenSetEnvironment_thenItIsSet() { assertThat(System.getenv("ENV")).isEqualTo("value1"); assertThat(System.getenv("ENV2")).isEqualTo("value2"); } } public static class SetEnvironmentInBefore { @Rule public EnvironmentVariablesRule environmentVariablesRule = new EnvironmentVariablesRule(); @Before public void before() { environmentVariablesRule.set("ENV", "value1") .set("ENV2", "value2"); } @Test public void givenEnvironmentCanBeModified_whenSetEnvironment_thenItIsSet() { assertThat(System.getenv("ENV")).isEqualTo("value1"); assertThat(System.getenv("ENV2")).isEqualTo("value2"); } } }