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.
18
18
19
19
import java .util .LinkedHashMap ;
20
20
import java .util .Map ;
21
- import java .util .Properties ;
22
21
23
22
import org .junit .Rule ;
24
23
import org .junit .Test ;
29
28
import org .springframework .core .io .ByteArrayResource ;
30
29
31
30
import static org .junit .Assert .*;
32
- import static org .springframework .beans .factory .config .YamlProcessor .*;
33
31
34
32
/**
35
33
* Tests for {@link YamlProcessor}.
@@ -48,110 +46,81 @@ public class YamlProcessorTests {
48
46
@ Test
49
47
public void arrayConvertedToIndexedBeanReference () {
50
48
this .processor .setResources (new ByteArrayResource ("foo: bar\n bar: [1,2,3]" .getBytes ()));
51
- this .processor .process (new MatchCallback () {
52
- @ Override
53
- public void process (Properties properties , Map <String , Object > map ) {
54
- assertEquals (4 , properties .size ());
55
- assertEquals ("bar" , properties .get ("foo" ));
56
- assertEquals ("bar" , properties .getProperty ("foo" ));
57
- assertEquals (1 , properties .get ("bar[0]" ));
58
- assertEquals ("1" , properties .getProperty ("bar[0]" ));
59
- assertEquals (2 , properties .get ("bar[1]" ));
60
- assertEquals ("2" , properties .getProperty ("bar[1]" ));
61
- assertEquals (3 , properties .get ("bar[2]" ));
62
- assertEquals ("3" , properties .getProperty ("bar[2]" ));
63
- }
49
+ this .processor .process ((properties , map ) -> {
50
+ assertEquals (4 , properties .size ());
51
+ assertEquals ("bar" , properties .get ("foo" ));
52
+ assertEquals ("bar" , properties .getProperty ("foo" ));
53
+ assertEquals (1 , properties .get ("bar[0]" ));
54
+ assertEquals ("1" , properties .getProperty ("bar[0]" ));
55
+ assertEquals (2 , properties .get ("bar[1]" ));
56
+ assertEquals ("2" , properties .getProperty ("bar[1]" ));
57
+ assertEquals (3 , properties .get ("bar[2]" ));
58
+ assertEquals ("3" , properties .getProperty ("bar[2]" ));
64
59
});
65
60
}
66
61
67
62
@ Test
68
- public void testStringResource () throws Exception {
63
+ public void testStringResource () {
69
64
this .processor .setResources (new ByteArrayResource ("foo # a document that is a literal" .getBytes ()));
70
- this .processor .process (new MatchCallback () {
71
- @ Override
72
- public void process (Properties properties , Map <String , Object > map ) {
73
- assertEquals ("foo" , map .get ("document" ));
74
- }
75
- });
65
+ this .processor .process ((properties , map ) -> assertEquals ("foo" , map .get ("document" )));
76
66
}
77
67
78
68
@ Test
79
- public void testBadDocumentStart () throws Exception {
69
+ public void testBadDocumentStart () {
80
70
this .processor .setResources (new ByteArrayResource ("foo # a document\n bar: baz" .getBytes ()));
81
71
this .exception .expect (ParserException .class );
82
72
this .exception .expectMessage ("line 2, column 1" );
83
- this .processor .process (new MatchCallback () {
84
- @ Override
85
- public void process (Properties properties , Map <String , Object > map ) {
86
- }
87
- });
73
+ this .processor .process ((properties , map ) -> {});
88
74
}
89
75
90
76
@ Test
91
- public void testBadResource () throws Exception {
77
+ public void testBadResource () {
92
78
this .processor .setResources (new ByteArrayResource ("foo: bar\n cd\n spam:\n foo: baz" .getBytes ()));
93
79
this .exception .expect (ScannerException .class );
94
80
this .exception .expectMessage ("line 3, column 1" );
95
- this .processor .process (new MatchCallback () {
96
- @ Override
97
- public void process (Properties properties , Map <String , Object > map ) {
98
- }
99
- });
81
+ this .processor .process ((properties , map ) -> {});
100
82
}
101
83
102
84
@ Test
103
85
public void mapConvertedToIndexedBeanReference () {
104
86
this .processor .setResources (new ByteArrayResource ("foo: bar\n bar:\n spam: bucket" .getBytes ()));
105
- this .processor .process (new MatchCallback () {
106
- @ Override
107
- public void process (Properties properties , Map <String , Object > map ) {
108
- // System.err.println(properties);
109
- assertEquals ("bucket" , properties .get ("bar.spam" ));
110
- assertEquals (2 , properties .size ());
111
- }
87
+ this .processor .process ((properties , map ) -> {
88
+ assertEquals ("bucket" , properties .get ("bar.spam" ));
89
+ assertEquals (2 , properties .size ());
112
90
});
113
91
}
114
92
115
93
@ Test
116
94
public void integerKeyBehaves () {
117
95
this .processor .setResources (new ByteArrayResource ("foo: bar\n 1: bar" .getBytes ()));
118
- this .processor .process (new MatchCallback () {
119
- @ Override
120
- public void process (Properties properties , Map <String , Object > map ) {
121
- assertEquals ("bar" , properties .get ("[1]" ));
122
- assertEquals (2 , properties .size ());
123
- }
96
+ this .processor .process ((properties , map ) -> {
97
+ assertEquals ("bar" , properties .get ("[1]" ));
98
+ assertEquals (2 , properties .size ());
124
99
});
125
100
}
126
101
127
102
@ Test
128
103
public void integerDeepKeyBehaves () {
129
104
this .processor .setResources (new ByteArrayResource ("foo:\n 1: bar" .getBytes ()));
130
- this .processor .process (new MatchCallback () {
131
- @ Override
132
- public void process (Properties properties , Map <String , Object > map ) {
133
- assertEquals ("bar" , properties .get ("foo[1]" ));
134
- assertEquals (1 , properties .size ());
135
- }
105
+ this .processor .process ((properties , map ) -> {
106
+ assertEquals ("bar" , properties .get ("foo[1]" ));
107
+ assertEquals (1 , properties .size ());
136
108
});
137
109
}
138
110
139
111
@ Test
140
112
@ SuppressWarnings ("unchecked" )
141
113
public void flattenedMapIsSameAsPropertiesButOrdered () {
142
114
this .processor .setResources (new ByteArrayResource ("foo: bar\n bar:\n spam: bucket" .getBytes ()));
143
- this .processor .process (new MatchCallback () {
144
- @ Override
145
- public void process (Properties properties , Map <String , Object > map ) {
146
- assertEquals ("bucket" , properties .get ("bar.spam" ));
147
- assertEquals (2 , properties .size ());
148
- Map <String , Object > flattenedMap = processor .getFlattenedMap (map );
149
- assertEquals ("bucket" , flattenedMap .get ("bar.spam" ));
150
- assertEquals (2 , flattenedMap .size ());
151
- assertTrue (flattenedMap instanceof LinkedHashMap );
152
- Map <String , Object > bar = (Map <String , Object >) map .get ("bar" );
153
- assertEquals ("bucket" , bar .get ("spam" ));
154
- }
115
+ this .processor .process ((properties , map ) -> {
116
+ assertEquals ("bucket" , properties .get ("bar.spam" ));
117
+ assertEquals (2 , properties .size ());
118
+ Map <String , Object > flattenedMap = processor .getFlattenedMap (map );
119
+ assertEquals ("bucket" , flattenedMap .get ("bar.spam" ));
120
+ assertEquals (2 , flattenedMap .size ());
121
+ assertTrue (flattenedMap instanceof LinkedHashMap );
122
+ Map <String , Object > bar = (Map <String , Object >) map .get ("bar" );
123
+ assertEquals ("bucket" , bar .get ("spam" ));
155
124
});
156
125
}
157
126
0 commit comments