@@ -24,74 +24,82 @@ class ProxyConfigFactoryTest {
2424 private final ProxyConfigFactory sut = new ProxyConfigFactory ();
2525
2626 @ Test
27- void create_throesExceptionIfUserNotSet () {
28- System .clearProperty (ProxyConfigNames .HTTP_PROXY_USER .getLiterat ());
29- System .setProperty (ProxyConfigNames .HTTP_PROXY_PASSWORD .getLiterat (), "password" );
30- System .setProperty (ProxyConfigNames .HTTP_PROXY_HOST .getLiterat (), "host" );
31- System .setProperty (ProxyConfigNames .HTTP_PROXY_PORT .getLiterat (), "4242" );
27+ void create_returnsDefaultIfUserAndPasswordNotPresent () {
28+ assertThat (sut .create (), is (ProxyConfigFactory .DEFAULT_CONFIG ));
29+ }
3230
33- final var thrown = assertThrows (
34- MissingProxyConfigValue . class ,
35- sut :: create );
31+ @ Test
32+ void create_returnsDefaultIfUserNotPresent () {
33+ System . setProperty ( ProxyConfigNames . HTTP_PROXY_USER . getLiterat (), "user" );
3634
37- assertThat (thrown . getMessage (), containsString ( "'http.proxyUser'" ));
35+ assertThat (sut . create (), is ( ProxyConfigFactory . DEFAULT_CONFIG ));
3836 }
3937
4038 @ Test
41- void create_throesExceptionIfPasswordNotSet () {
39+ void create_returnsDefaultIfPasswordNotPresent () {
40+ System .setProperty (ProxyConfigNames .HTTP_PROXY_PASSWORD .getLiterat (), "password" );
41+
42+ assertThat (sut .create (), is (ProxyConfigFactory .DEFAULT_CONFIG ));
43+ }
44+
45+ @ Test
46+ void create_returnsCompleteConfigIfAllPropertiesArePresent () {
4247 System .setProperty (ProxyConfigNames .HTTP_PROXY_USER .getLiterat (), "user" );
43- System .clearProperty (ProxyConfigNames .HTTP_PROXY_PASSWORD .getLiterat ());
48+ System .setProperty (ProxyConfigNames .HTTP_PROXY_PASSWORD .getLiterat (), "password" );
4449 System .setProperty (ProxyConfigNames .HTTP_PROXY_HOST .getLiterat (), "host" );
4550 System .setProperty (ProxyConfigNames .HTTP_PROXY_PORT .getLiterat (), "4242" );
4651
47- final var thrown = assertThrows (
48- MissingProxyConfigValue .class ,
49- sut ::create );
52+ final var expected = ProxyConfig .builder ()
53+ .user ("user" )
54+ .password ("password" )
55+ .host ("host" )
56+ .port (4242 )
57+ .build ();
5058
51- assertThat (thrown . getMessage (), containsString ( "'http.proxyPassword'" ));
59+ assertThat (sut . create (), is ( expected ));
5260 }
5361
5462 @ Test
55- void create_throesExceptionIfHostNotSet () {
63+ void create_throwsExceptionIfHostNotSet () {
5664 System .setProperty (ProxyConfigNames .HTTP_PROXY_USER .getLiterat (), "user" );
5765 System .setProperty (ProxyConfigNames .HTTP_PROXY_PASSWORD .getLiterat (), "password" );
5866 System .clearProperty (ProxyConfigNames .HTTP_PROXY_HOST .getLiterat ());
5967 System .setProperty (ProxyConfigNames .HTTP_PROXY_PORT .getLiterat (), "4242" );
6068
6169 final var thrown = assertThrows (
62- MissingProxyConfigValue .class ,
63- sut ::create );
70+ MissingProxyConfigValue .class ,
71+ sut ::create );
6472
6573 assertThat (thrown .getMessage (), containsString ("'http.proxyHost'" ));
6674 }
6775
6876 @ Test
69- void create_throesExceptionIfPortNotSet () {
77+ void create_throwsExceptionIfPortNotSet () {
7078 System .setProperty (ProxyConfigNames .HTTP_PROXY_USER .getLiterat (), "user" );
7179 System .setProperty (ProxyConfigNames .HTTP_PROXY_PASSWORD .getLiterat (), "password" );
7280 System .setProperty (ProxyConfigNames .HTTP_PROXY_HOST .getLiterat (), "host" );
7381 System .clearProperty (ProxyConfigNames .HTTP_PROXY_PORT .getLiterat ());
7482
7583 final var thrown = assertThrows (
76- MissingProxyConfigValue .class ,
77- sut ::create );
84+ MissingProxyConfigValue .class ,
85+ sut ::create );
7886
7987 assertThat (thrown .getMessage (), containsString ("'http.proxyPort'" ));
8088 }
8189
8290 @ Test
83- void create_throesExceptionIfPortIsNotInteger () {
91+ void create_throwsExceptionIfPortIsNotInteger () {
8492 System .setProperty (ProxyConfigNames .HTTP_PROXY_USER .getLiterat (), "user" );
8593 System .setProperty (ProxyConfigNames .HTTP_PROXY_PASSWORD .getLiterat (), "password" );
8694 System .setProperty (ProxyConfigNames .HTTP_PROXY_HOST .getLiterat (), "host" );
8795 System .setProperty (ProxyConfigNames .HTTP_PROXY_PORT .getLiterat (), "FUBAR" );
8896
8997 final var thrown = assertThrows (
90- IllegalArgumentException .class ,
91- sut ::create );
98+ IllegalArgumentException .class ,
99+ sut ::create );
92100
93101 assertThat (
94- thrown .getMessage (),
95- is ("Given port for proxy authentication configuration (property 'http.proxyPort') is not a valid number! Given value wa 'FUBAR'." ));
102+ thrown .getMessage (),
103+ is ("Given port for proxy authentication configuration (property 'http.proxyPort') is not a valid number! Given value wa 'FUBAR'." ));
96104 }
97105}
0 commit comments