@@ -24,74 +24,82 @@ class ProxyConfigFactoryTest {
24
24
private final ProxyConfigFactory sut = new ProxyConfigFactory ();
25
25
26
26
@ 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
+ }
32
30
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" );
36
34
37
- assertThat (thrown . getMessage (), containsString ( "'http.proxyUser'" ));
35
+ assertThat (sut . create (), is ( ProxyConfigFactory . DEFAULT_CONFIG ));
38
36
}
39
37
40
38
@ 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 () {
42
47
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" );
44
49
System .setProperty (ProxyConfigNames .HTTP_PROXY_HOST .getLiterat (), "host" );
45
50
System .setProperty (ProxyConfigNames .HTTP_PROXY_PORT .getLiterat (), "4242" );
46
51
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 ();
50
58
51
- assertThat (thrown . getMessage (), containsString ( "'http.proxyPassword'" ));
59
+ assertThat (sut . create (), is ( expected ));
52
60
}
53
61
54
62
@ Test
55
- void create_throesExceptionIfHostNotSet () {
63
+ void create_throwsExceptionIfHostNotSet () {
56
64
System .setProperty (ProxyConfigNames .HTTP_PROXY_USER .getLiterat (), "user" );
57
65
System .setProperty (ProxyConfigNames .HTTP_PROXY_PASSWORD .getLiterat (), "password" );
58
66
System .clearProperty (ProxyConfigNames .HTTP_PROXY_HOST .getLiterat ());
59
67
System .setProperty (ProxyConfigNames .HTTP_PROXY_PORT .getLiterat (), "4242" );
60
68
61
69
final var thrown = assertThrows (
62
- MissingProxyConfigValue .class ,
63
- sut ::create );
70
+ MissingProxyConfigValue .class ,
71
+ sut ::create );
64
72
65
73
assertThat (thrown .getMessage (), containsString ("'http.proxyHost'" ));
66
74
}
67
75
68
76
@ Test
69
- void create_throesExceptionIfPortNotSet () {
77
+ void create_throwsExceptionIfPortNotSet () {
70
78
System .setProperty (ProxyConfigNames .HTTP_PROXY_USER .getLiterat (), "user" );
71
79
System .setProperty (ProxyConfigNames .HTTP_PROXY_PASSWORD .getLiterat (), "password" );
72
80
System .setProperty (ProxyConfigNames .HTTP_PROXY_HOST .getLiterat (), "host" );
73
81
System .clearProperty (ProxyConfigNames .HTTP_PROXY_PORT .getLiterat ());
74
82
75
83
final var thrown = assertThrows (
76
- MissingProxyConfigValue .class ,
77
- sut ::create );
84
+ MissingProxyConfigValue .class ,
85
+ sut ::create );
78
86
79
87
assertThat (thrown .getMessage (), containsString ("'http.proxyPort'" ));
80
88
}
81
89
82
90
@ Test
83
- void create_throesExceptionIfPortIsNotInteger () {
91
+ void create_throwsExceptionIfPortIsNotInteger () {
84
92
System .setProperty (ProxyConfigNames .HTTP_PROXY_USER .getLiterat (), "user" );
85
93
System .setProperty (ProxyConfigNames .HTTP_PROXY_PASSWORD .getLiterat (), "password" );
86
94
System .setProperty (ProxyConfigNames .HTTP_PROXY_HOST .getLiterat (), "host" );
87
95
System .setProperty (ProxyConfigNames .HTTP_PROXY_PORT .getLiterat (), "FUBAR" );
88
96
89
97
final var thrown = assertThrows (
90
- IllegalArgumentException .class ,
91
- sut ::create );
98
+ IllegalArgumentException .class ,
99
+ sut ::create );
92
100
93
101
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'." ));
96
104
}
97
105
}
0 commit comments