Skip to content

Commit d00c9dd

Browse files
committed
#36 Extract exception for missingproxy config in own file forbetter readability
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent 680ca56 commit d00c9dd

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.securecodebox.persistence.defectdojo.http;
2+
3+
import lombok.NonNull;
4+
5+
/**
6+
* This exception indicates a missing proxy config value
7+
*/
8+
public final class MissingProxyConfigValue extends RuntimeException {
9+
MissingProxyConfigValue(@NonNull final ProxyConfigNames name) {
10+
super(String.format("Expected system property '%s' not set!", name.getLiterat()));
11+
}
12+
}

src/main/java/io/securecodebox/persistence/defectdojo/http/ProxyConfigFactory.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,4 @@ private String getProperty(@NonNull final ProxyConfigNames name) {
6868
}
6969
}
7070

71-
/**
72-
* This exception indicates a missing proxy config value
73-
*/
74-
final static class MissingProxyConfigValue extends RuntimeException {
75-
MissingProxyConfigValue(ProxyConfigNames name) {
76-
super(String.format("Expected System property '%s' not set!", name.getLiterat()));
77-
}
78-
}
7971
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.securecodebox.persistence.defectdojo.http;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
import static org.hamcrest.MatcherAssert.assertThat;
7+
import static org.hamcrest.Matchers.*;
8+
9+
/**
10+
* Tests for {@link MissingProxyConfigValue}
11+
*/
12+
class MissingProxyConfigValueTest {
13+
@Test
14+
void rendersMessageFromProxyConfigName() {
15+
final var sut = new MissingProxyConfigValue(ProxyConfigNames.HTTP_PROXY_HOST);
16+
17+
assertThat(sut.getMessage(), is("Expected system property 'http.proxyHost' not set!"));
18+
}
19+
}

src/test/java/io/securecodebox/persistence/defectdojo/http/ProxyConfigFactoryTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import uk.org.webcompere.systemstubs.properties.SystemProperties;
88

99
import static org.hamcrest.MatcherAssert.assertThat;
10-
import static org.hamcrest.Matchers.is;
10+
import static org.hamcrest.Matchers.*;
1111
import static org.junit.jupiter.api.Assertions.assertThrows;
1212

1313
/**
@@ -27,10 +27,10 @@ void create_throesExceptionIfUserNotSet() {
2727
System.setProperty(ProxyConfigNames.HTTP_PROXY_PORT.getLiterat(), "4242");
2828

2929
final var thrown = assertThrows(
30-
ProxyConfigFactory.MissingProxyConfigValue.class,
30+
MissingProxyConfigValue.class,
3131
sut::create);
3232

33-
assertThat(thrown.getMessage(), is("Expected System property 'http.proxyUser' not set!"));
33+
assertThat(thrown.getMessage(), containsString("'http.proxyUser'"));
3434
}
3535

3636
@Test
@@ -41,10 +41,10 @@ void create_throesExceptionIfPasswordNotSet() {
4141
System.setProperty(ProxyConfigNames.HTTP_PROXY_PORT.getLiterat(), "4242");
4242

4343
final var thrown = assertThrows(
44-
ProxyConfigFactory.MissingProxyConfigValue.class,
44+
MissingProxyConfigValue.class,
4545
sut::create);
4646

47-
assertThat(thrown.getMessage(), is("Expected System property 'http.proxyPassword' not set!"));
47+
assertThat(thrown.getMessage(), containsString("'http.proxyPassword'"));
4848
}
4949

5050
@Test
@@ -55,10 +55,10 @@ void create_throesExceptionIfHostNotSet() {
5555
System.setProperty(ProxyConfigNames.HTTP_PROXY_PORT.getLiterat(), "4242");
5656

5757
final var thrown = assertThrows(
58-
ProxyConfigFactory.MissingProxyConfigValue.class,
58+
MissingProxyConfigValue.class,
5959
sut::create);
6060

61-
assertThat(thrown.getMessage(), is("Expected System property 'http.proxyHost' not set!"));
61+
assertThat(thrown.getMessage(), containsString("'http.proxyHost'"));
6262
}
6363

6464
@Test
@@ -69,10 +69,10 @@ void create_throesExceptionIfPortNotSet() {
6969
System.clearProperty(ProxyConfigNames.HTTP_PROXY_PORT.getLiterat());
7070

7171
final var thrown = assertThrows(
72-
ProxyConfigFactory.MissingProxyConfigValue.class,
72+
MissingProxyConfigValue.class,
7373
sut::create);
7474

75-
assertThat(thrown.getMessage(), is("Expected System property 'http.proxyPort' not set!"));
75+
assertThat(thrown.getMessage(), containsString("'http.proxyPort'"));
7676
}
7777

7878
@Test

0 commit comments

Comments
 (0)