|
1 | 1 | package io.securecodebox.persistence.defectdojo.config; |
2 | 2 |
|
3 | 3 | import org.junit.jupiter.api.Test; |
| 4 | +import org.junit.jupiter.api.extension.ExtendWith; |
4 | 5 | import org.junit.jupiter.params.ParameterizedTest; |
5 | 6 | import org.junit.jupiter.params.provider.ValueSource; |
| 7 | +import uk.org.webcompere.systemstubs.environment.EnvironmentVariables; |
| 8 | +import uk.org.webcompere.systemstubs.jupiter.SystemStub; |
| 9 | +import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension; |
6 | 10 |
|
7 | 11 | import static org.junit.jupiter.api.Assertions.*; |
8 | 12 | import static org.hamcrest.MatcherAssert.assertThat; |
|
11 | 15 | /** |
12 | 16 | * Tests for {@link Config} |
13 | 17 | */ |
| 18 | +@ExtendWith(SystemStubsExtension.class) |
14 | 19 | class ConfigTest { |
15 | 20 |
|
| 21 | + @SystemStub |
| 22 | + private EnvironmentVariables environmentVariables; |
| 23 | + |
16 | 24 | @Test |
17 | 25 | void constructor_urlMustNotBeNull() { |
18 | 26 | final var thrown = assertThrows(NullPointerException.class, () ->{ |
@@ -50,4 +58,22 @@ void constructor_maxPageCountForGetsMustNotBeLessThanOne(final int number) { |
50 | 58 | assertThat(thrown.getMessage(), startsWith("maxPageCountForGets ")); |
51 | 59 | } |
52 | 60 |
|
| 61 | + @Test |
| 62 | + void fromEnv() { |
| 63 | + environmentVariables.set("DEFECTDOJO_URL", "url") |
| 64 | + .set("DEFECTDOJO_USERNAME", "username") |
| 65 | + .set("DEFECTDOJO_APIKEY", "apikey") |
| 66 | + .set("DEFECTDOJO_USER_ID", "42") |
| 67 | + .set("DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS", "23"); |
| 68 | + |
| 69 | + final var sut = Config.fromEnv(); |
| 70 | + |
| 71 | + assertAll( |
| 72 | + () -> assertThat(sut.getUrl(), is("url")), |
| 73 | + () -> assertThat(sut.getUsername(), is("username")), |
| 74 | + () -> assertThat(sut.getApiKey(), is("apikey")), |
| 75 | + () -> assertThat(sut.getUserId(), is(42L)), |
| 76 | + () -> assertThat(sut.getMaxPageCountForGets(), is(23)) |
| 77 | + ); |
| 78 | + } |
53 | 79 | } |
0 commit comments