1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -47,17 +47,16 @@ public class YamlPropertiesFactoryBeanTests {
47
47
48
48
49
49
@ Test
50
- public void testLoadResource () throws Exception {
50
+ public void testLoadResource () {
51
51
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
52
- factory .setResources (new ByteArrayResource (
53
- "foo: bar\n spam:\n foo: baz" .getBytes ()));
52
+ factory .setResources (new ByteArrayResource ("foo: bar\n spam:\n foo: baz" .getBytes ()));
54
53
Properties properties = factory .getObject ();
55
54
assertThat (properties .getProperty ("foo" ), equalTo ("bar" ));
56
55
assertThat (properties .getProperty ("spam.foo" ), equalTo ("baz" ));
57
56
}
58
57
59
58
@ Test
60
- public void testBadResource () throws Exception {
59
+ public void testBadResource () {
61
60
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
62
61
factory .setResources (new ByteArrayResource (
63
62
"foo: bar\n cd\n spam:\n foo: baz" .getBytes ()));
@@ -67,7 +66,7 @@ public void testBadResource() throws Exception {
67
66
}
68
67
69
68
@ Test
70
- public void testLoadResourcesWithOverride () throws Exception {
69
+ public void testLoadResourcesWithOverride () {
71
70
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
72
71
factory .setResources (
73
72
new ByteArrayResource ("foo: bar\n spam:\n foo: baz" .getBytes ()),
@@ -79,7 +78,7 @@ public void testLoadResourcesWithOverride() throws Exception {
79
78
}
80
79
81
80
@ Test
82
- public void testLoadResourcesWithInternalOverride () throws Exception {
81
+ public void testLoadResourcesWithInternalOverride () {
83
82
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
84
83
factory .setResources (new ByteArrayResource (
85
84
"foo: bar\n spam:\n foo: baz\n foo: bucket" .getBytes ()));
@@ -89,7 +88,7 @@ public void testLoadResourcesWithInternalOverride() throws Exception {
89
88
90
89
@ Test
91
90
@ Ignore ("We can't fail on duplicate keys because the Map is created by the YAML library" )
92
- public void testLoadResourcesWithNestedInternalOverride () throws Exception {
91
+ public void testLoadResourcesWithNestedInternalOverride () {
93
92
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
94
93
factory .setResources (new ByteArrayResource (
95
94
"foo:\n bar: spam\n foo: baz\n break: it\n foo: bucket" .getBytes ()));
@@ -98,7 +97,7 @@ public void testLoadResourcesWithNestedInternalOverride() throws Exception {
98
97
}
99
98
100
99
@ Test
101
- public void testLoadResourceWithMultipleDocuments () throws Exception {
100
+ public void testLoadResourceWithMultipleDocuments () {
102
101
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
103
102
factory .setResources (new ByteArrayResource (
104
103
"foo: bar\n spam: baz\n ---\n foo: bag" .getBytes ()));
@@ -108,37 +107,29 @@ public void testLoadResourceWithMultipleDocuments() throws Exception {
108
107
}
109
108
110
109
@ Test
111
- public void testLoadResourceWithSelectedDocuments () throws Exception {
110
+ public void testLoadResourceWithSelectedDocuments () {
112
111
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
113
112
factory .setResources (new ByteArrayResource (
114
113
"foo: bar\n spam: baz\n ---\n foo: bag\n spam: bad" .getBytes ()));
115
- factory .setDocumentMatchers (new DocumentMatcher () {
116
- @ Override
117
- public MatchStatus matches (Properties properties ) {
118
- return ("bag" .equals (properties .getProperty ("foo" )) ?
119
- MatchStatus .FOUND : MatchStatus .NOT_FOUND );
120
- }
121
- });
114
+ factory .setDocumentMatchers (properties -> ("bag" .equals (properties .getProperty ("foo" )) ?
115
+ MatchStatus .FOUND : MatchStatus .NOT_FOUND ));
122
116
Properties properties = factory .getObject ();
123
117
assertThat (properties .getProperty ("foo" ), equalTo ("bag" ));
124
118
assertThat (properties .getProperty ("spam" ), equalTo ("bad" ));
125
119
}
126
120
127
121
@ Test
128
- public void testLoadResourceWithDefaultMatch () throws Exception {
122
+ public void testLoadResourceWithDefaultMatch () {
129
123
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
130
124
factory .setMatchDefault (true );
131
125
factory .setResources (new ByteArrayResource (
132
126
"one: two\n ---\n foo: bar\n spam: baz\n ---\n foo: bag\n spam: bad" .getBytes ()));
133
- factory .setDocumentMatchers (new DocumentMatcher () {
134
- @ Override
135
- public MatchStatus matches (Properties properties ) {
136
- if (!properties .containsKey ("foo" )) {
137
- return MatchStatus .ABSTAIN ;
138
- }
139
- return ("bag" .equals (properties .getProperty ("foo" )) ?
140
- MatchStatus .FOUND : MatchStatus .NOT_FOUND );
127
+ factory .setDocumentMatchers (properties -> {
128
+ if (!properties .containsKey ("foo" )) {
129
+ return MatchStatus .ABSTAIN ;
141
130
}
131
+ return ("bag" .equals (properties .getProperty ("foo" )) ?
132
+ MatchStatus .FOUND : MatchStatus .NOT_FOUND );
142
133
});
143
134
Properties properties = factory .getObject ();
144
135
assertThat (properties .getProperty ("foo" ), equalTo ("bag" ));
@@ -147,7 +138,7 @@ public MatchStatus matches(Properties properties) {
147
138
}
148
139
149
140
@ Test
150
- public void testLoadResourceWithoutDefaultMatch () throws Exception {
141
+ public void testLoadResourceWithoutDefaultMatch () {
151
142
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
152
143
factory .setMatchDefault (false );
153
144
factory .setResources (new ByteArrayResource (
@@ -169,20 +160,17 @@ public MatchStatus matches(Properties properties) {
169
160
}
170
161
171
162
@ Test
172
- public void testLoadResourceWithDefaultMatchSkippingMissedMatch () throws Exception {
163
+ public void testLoadResourceWithDefaultMatchSkippingMissedMatch () {
173
164
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
174
165
factory .setMatchDefault (true );
175
166
factory .setResources (new ByteArrayResource (
176
167
"one: two\n ---\n foo: bag\n spam: bad\n ---\n foo: bar\n spam: baz" .getBytes ()));
177
- factory .setDocumentMatchers (new DocumentMatcher () {
178
- @ Override
179
- public MatchStatus matches (Properties properties ) {
180
- if (!properties .containsKey ("foo" )) {
181
- return MatchStatus .ABSTAIN ;
182
- }
183
- return ("bag" .equals (properties .getProperty ("foo" )) ?
184
- MatchStatus .FOUND : MatchStatus .NOT_FOUND );
168
+ factory .setDocumentMatchers (properties -> {
169
+ if (!properties .containsKey ("foo" )) {
170
+ return MatchStatus .ABSTAIN ;
185
171
}
172
+ return ("bag" .equals (properties .getProperty ("foo" )) ?
173
+ MatchStatus .FOUND : MatchStatus .NOT_FOUND );
186
174
});
187
175
Properties properties = factory .getObject ();
188
176
assertThat (properties .getProperty ("foo" ), equalTo ("bag" ));
@@ -191,7 +179,7 @@ public MatchStatus matches(Properties properties) {
191
179
}
192
180
193
181
@ Test
194
- public void testLoadNonExistentResource () throws Exception {
182
+ public void testLoadNonExistentResource () {
195
183
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
196
184
factory .setResolutionMethod (ResolutionMethod .OVERRIDE_AND_IGNORE );
197
185
factory .setResources (new ClassPathResource ("no-such-file.yml" ));
@@ -200,7 +188,7 @@ public void testLoadNonExistentResource() throws Exception {
200
188
}
201
189
202
190
@ Test
203
- public void testLoadNull () throws Exception {
191
+ public void testLoadNull () {
204
192
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
205
193
factory .setResources (new ByteArrayResource ("foo: bar\n spam:" .getBytes ()));
206
194
Properties properties = factory .getObject ();
@@ -209,7 +197,7 @@ public void testLoadNull() throws Exception {
209
197
}
210
198
211
199
@ Test
212
- public void testLoadArrayOfString () throws Exception {
200
+ public void testLoadArrayOfString () {
213
201
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
214
202
factory .setResources (new ByteArrayResource ("foo:\n - bar\n - baz" .getBytes ()));
215
203
Properties properties = factory .getObject ();
@@ -219,7 +207,7 @@ public void testLoadArrayOfString() throws Exception {
219
207
}
220
208
221
209
@ Test
222
- public void testLoadArrayOfInteger () throws Exception {
210
+ public void testLoadArrayOfInteger () {
223
211
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
224
212
factory .setResources (new ByteArrayResource ("foo:\n - 1\n - 2" .getBytes ()));
225
213
Properties properties = factory .getObject ();
@@ -229,7 +217,7 @@ public void testLoadArrayOfInteger() throws Exception {
229
217
}
230
218
231
219
@ Test
232
- public void testLoadArrayOfObject () throws Exception {
220
+ public void testLoadArrayOfObject () {
233
221
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean ();
234
222
factory .setResources (new ByteArrayResource (
235
223
"foo:\n - bar:\n spam: crap\n - baz\n - one: two\n three: four" .getBytes ()
@@ -247,8 +235,8 @@ public void testLoadArrayOfObject() throws Exception {
247
235
public void testYaml () {
248
236
Yaml yaml = new Yaml ();
249
237
Map <String , ?> map = yaml .loadAs ("foo: bar\n spam:\n foo: baz" , Map .class );
250
- assertThat (map .get ("foo" ), equalTo (( Object ) "bar" ));
251
- assertThat (((Map <String , Object >) map .get ("spam" )).get ("foo" ), equalTo (( Object ) "baz" ));
238
+ assertThat (map .get ("foo" ), equalTo ("bar" ));
239
+ assertThat (((Map <String , Object >) map .get ("spam" )).get ("foo" ), equalTo ("baz" ));
252
240
}
253
241
254
242
}
0 commit comments