1
1
package com .spring .loader .util ;
2
2
3
3
import static org .junit .Assert .assertEquals ;
4
+ import static org .mockito .Matchers .eq ;
4
5
5
6
import org .junit .Before ;
6
7
import org .junit .Test ;
7
8
import org .junit .runner .RunWith ;
8
- import org .mockito .Mockito ;
9
9
import org .powermock .api .mockito .PowerMockito ;
10
10
import org .powermock .core .classloader .annotations .PrepareForTest ;
11
11
import org .powermock .modules .junit4 .PowerMockRunner ;
12
12
13
13
import com .spring .loader .exception .EnviromentPropertyNotFoundException ;
14
14
import com .spring .loader .exception .InvalidS3LocationException ;
15
- import com .spring .loader .util .SystemPropertyResolver ;
16
15
17
16
@ PrepareForTest (SystemPropertyResolver .class )
18
17
@ RunWith (PowerMockRunner .class )
19
18
public class SystemPropertyResolverTest {
20
-
19
+
21
20
private SystemPropertyResolver subject ;
22
21
23
22
@ Before
@@ -29,13 +28,26 @@ public void setup() {
29
28
@ Test
30
29
public void shouldGetFormattedValueWhenValueIsValid () {
31
30
String expected = "someValue" ;
32
-
33
- PowerMockito .when (System .getenv (Mockito . eq ("AWS_S3" ))).thenReturn (expected );
34
-
31
+
32
+ PowerMockito .when (System .getenv (eq ("AWS_S3" ))).thenReturn (expected );
33
+
35
34
String env = "${AWS_S3}" ;
36
-
35
+
37
36
String formattedValue = subject .getFormattedValue (env );
38
-
37
+
38
+ assertEquals (expected , formattedValue );
39
+ }
40
+
41
+ @ Test
42
+ public void shouldGetFormattedValueFromPropertiesWhenValueIsValid () {
43
+ String expected = "someValue" ;
44
+
45
+ PowerMockito .when (System .getProperty (eq ("AWS_S3" ))).thenReturn (expected );
46
+
47
+ String env = "${AWS_S3}" ;
48
+
49
+ String formattedValue = subject .getFormattedValue (env );
50
+
39
51
assertEquals (expected , formattedValue );
40
52
}
41
53
@@ -44,8 +56,8 @@ public void shouldGetCombinedFormattedValueWhenValueIsValid() {
44
56
String region = "someRegion" ;
45
57
String environment = "someEnvironment" ;
46
58
47
- PowerMockito .when (System .getenv (Mockito . eq ("S3_BUCKET_REGION" ))).thenReturn (region );
48
- PowerMockito .when (System .getenv (Mockito . eq ("S3_BUCKET_ENVIRONMENT" ))).thenReturn (environment );
59
+ PowerMockito .when (System .getenv (eq ("S3_BUCKET_REGION" ))).thenReturn (region );
60
+ PowerMockito .when (System .getenv (eq ("S3_BUCKET_ENVIRONMENT" ))).thenReturn (environment );
49
61
50
62
String configValue = "${S3_BUCKET_REGION}/${S3_BUCKET_ENVIRONMENT}/myApplication/application.properties" ;
51
63
String expected = String .format ("%s/%s/myApplication/application.properties" , region , environment );
@@ -59,7 +71,7 @@ public void shouldGetCombinedFormattedValueWhenValueIsValid() {
59
71
public void shouldReplaceMultiple () {
60
72
String environment = "dev" ;
61
73
62
- PowerMockito .when (System .getenv (Mockito . eq ("EC2_ENVIRONMENT" ))).thenReturn (environment );
74
+ PowerMockito .when (System .getenv (eq ("EC2_ENVIRONMENT" ))).thenReturn (environment );
63
75
64
76
String configValue = "region-${EC2_ENVIRONMENT}/deploy-${EC2_ENVIRONMENT}/application.properties" ;
65
77
String expected = String .format ("region-%s/deploy-%s/application.properties" , environment , environment );
@@ -72,32 +84,32 @@ public void shouldReplaceMultiple() {
72
84
@ Test
73
85
public void shouldGetFormattedValueWhenValueIsValidAndNotASystemEnv () {
74
86
String expected = "someValue" ;
75
-
87
+
76
88
String formattedValue = subject .getFormattedValue (expected );
77
-
89
+
78
90
assertEquals (expected , formattedValue );
79
91
}
80
-
92
+
81
93
@ Test (expected = InvalidS3LocationException .class )
82
94
public void shouldNotGetFormattedValueWhenValueIsEmpty () {
83
95
String expected = "" ;
84
-
96
+
85
97
subject .getFormattedValue (expected );
86
98
}
87
-
99
+
88
100
@ Test (expected = InvalidS3LocationException .class )
89
101
public void shouldNotGetFormattedValueWhenValueHasAInvalidSyntax () {
90
102
String expected = "${AWS_S3" ;
91
-
103
+
92
104
subject .getFormattedValue (expected );
93
105
}
94
-
106
+
95
107
@ Test (expected = EnviromentPropertyNotFoundException .class )
96
108
public void shouldNotGetFormattedValueWhenSystemDoesNotHasTheEnvironmentVariable () {
97
- PowerMockito .when (System .getenv (Mockito . eq ("AWS_S3" ))).thenReturn (null );
98
-
109
+ PowerMockito .when (System .getenv (eq ("AWS_S3" ))).thenReturn (null );
110
+
99
111
String env = "${AWS_S3}" ;
100
-
112
+
101
113
subject .getFormattedValue (env );
102
114
}
103
115
0 commit comments