Skip to content

Commit be0eaad

Browse files
WeltraumschafManuelNeuer
authored andcommitted
#36 Test config creation from env vars
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent a53e954 commit be0eaad

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies {
2424
testImplementation 'org.springframework:spring-test:5.3.23'
2525
testImplementation 'org.hamcrest:java-hamcrest:2.0.0.0'
2626
testImplementation 'org.mockito:mockito-core:3.+'
27+
testImplementation 'uk.org.webcompere:system-stubs-jupiter:2.0.1'
2728

2829
implementation group: 'org.springframework', name: 'spring-web', version: '5.3.9'
2930
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'

src/test/java/io/securecodebox/persistence/defectdojo/config/ConfigTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package io.securecodebox.persistence.defectdojo.config;
22

33
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.extension.ExtendWith;
45
import org.junit.jupiter.params.ParameterizedTest;
56
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;
610

711
import static org.junit.jupiter.api.Assertions.*;
812
import static org.hamcrest.MatcherAssert.assertThat;
@@ -11,8 +15,12 @@
1115
/**
1216
* Tests for {@link Config}
1317
*/
18+
@ExtendWith(SystemStubsExtension.class)
1419
class ConfigTest {
1520

21+
@SystemStub
22+
private EnvironmentVariables environmentVariables;
23+
1624
@Test
1725
void constructor_urlMustNotBeNull() {
1826
final var thrown = assertThrows(NullPointerException.class, () ->{
@@ -50,4 +58,22 @@ void constructor_maxPageCountForGetsMustNotBeLessThanOne(final int number) {
5058
assertThat(thrown.getMessage(), startsWith("maxPageCountForGets "));
5159
}
5260

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+
}
5379
}

0 commit comments

Comments
 (0)