@@ -81,103 +81,175 @@ public void testNonFiltering() throws Exception
81
81
public void testSingleMatchFilteringWithoutPath () throws Exception
82
82
{
83
83
JsonParser p0 = JSON_F .createParser (SIMPLE );
84
- JsonParser p = new FilteringParserDelegate (p0 ,
84
+ FilteringParserDelegate p = new FilteringParserDelegate (p0 ,
85
85
new NameMatchFilter ("value" ),
86
86
false , // includePath
87
87
false // multipleMatches
88
88
);
89
89
String result = readAndWrite (JSON_F , p );
90
90
assertEquals (aposToQuotes ("3" ), result );
91
+ assertEquals (1 , p .getMatchCount ());
92
+ }
93
+
94
+ public void testSingleMatchFilteringWithPath () throws Exception
95
+ {
96
+ String jsonString = aposToQuotes ("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4},'b':true}" );
97
+ JsonParser p0 = JSON_F .createParser (jsonString );
98
+ FilteringParserDelegate p = new FilteringParserDelegate (p0 ,
99
+ new NameMatchFilter ("a" ),
100
+ true , // includePath
101
+ false // multipleMatches
102
+ );
103
+ String result = readAndWrite (JSON_F , p );
104
+ assertEquals (aposToQuotes ("{'a':123}" ), result );
105
+ assertEquals (1 , p .getMatchCount ());
91
106
}
92
107
93
108
@ SuppressWarnings ("resource" )
94
- public void testNotAllowMultipleMatches () throws Exception
109
+ public void testNotAllowMultipleMatchesWithoutPath1 () throws Exception
95
110
{
96
- String jsonString = aposToQuotes ("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4} ,'value':4 ,'b':true}" );
111
+ String jsonString = aposToQuotes ("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4,'value':{'value0':2}} ,'b':true}" );
97
112
JsonParser p0 = JSON_F .createParser (jsonString );
98
- JsonParser p = new FilteringParserDelegate (p0 ,
113
+ FilteringParserDelegate p = new FilteringParserDelegate (p0 ,
99
114
new NameMatchFilter ("value" ),
100
115
false , // includePath
101
116
false // multipleMatches -false
102
117
);
103
118
String result = readAndWrite (JSON_F , p );
104
119
assertEquals (aposToQuotes ("3" ), result );
120
+ assertEquals (1 , p .getMatchCount ());
105
121
}
106
-
122
+
107
123
@ SuppressWarnings ("resource" )
108
- public void testAllowMultipleMatches () throws Exception
124
+ public void testNotAllowMultipleMatchesWithoutPath2 () throws Exception
109
125
{
110
- String jsonString = aposToQuotes ("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4} ,'value':4 ,'b':true}" );
126
+ String jsonString = aposToQuotes ("{'a':123,'array':[1,2],'array':[3,4],' ob':{'value0':2,'value':3,'value2':4,'value':{'value0':2}} ,'value':\" val \" ,'b':true}" );
111
127
JsonParser p0 = JSON_F .createParser (jsonString );
112
- JsonParser p = new FilteringParserDelegate (p0 ,
128
+ FilteringParserDelegate p = new FilteringParserDelegate (p0 ,
129
+ new IndexMatchFilter (1 ),
130
+ false , // includePath
131
+ false // multipleMatches -false
132
+ );
133
+ String result = readAndWrite (JSON_F , p );
134
+ assertEquals (aposToQuotes ("2" ), result );
135
+ assertEquals (1 , p .getMatchCount ());
136
+ }
137
+
138
+ @ SuppressWarnings ("resource" )
139
+ public void testAllowMultipleMatchesWithoutPath () throws Exception
140
+ {
141
+ String jsonString = aposToQuotes ("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4,'value':{'value0':2}},'value':\" val\" ,'b':true}" );
142
+ JsonParser p0 = JSON_F .createParser (jsonString );
143
+ FilteringParserDelegate p = new FilteringParserDelegate (p0 ,
113
144
new NameMatchFilter ("value" ),
114
145
false , // includePath
115
146
true // multipleMatches - true
116
147
);
117
148
String result = readAndWrite (JSON_F , p );
118
- assertEquals (aposToQuotes ("3 4" ), result );
149
+ assertEquals (aposToQuotes ("3 {\" value0\" :2} \" val\" " ), result );
150
+ assertEquals (3 , p .getMatchCount ());
151
+ }
152
+
153
+
154
+ @ SuppressWarnings ("resource" )
155
+ public void testAllowMultipleMatchesWithPath1 () throws Exception
156
+ {
157
+ String jsonString = aposToQuotes ("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'value2':4,'value':{'value0':2}},'value':\" val\" ,'b':true}" );
158
+ JsonParser p0 = JSON_F .createParser (jsonString );
159
+ FilteringParserDelegate p = new FilteringParserDelegate (p0 ,
160
+ new NameMatchFilter ("value" ),
161
+ true , // includePath
162
+ true // multipleMatches - true
163
+ );
164
+ String result = readAndWrite (JSON_F , p );
165
+ assertEquals (aposToQuotes ("{\" ob\" :{\" value\" :3,\" value\" :{\" value0\" :2}},\" value\" :\" val\" }" ), result );
166
+ assertEquals (3 , p .getMatchCount ());
167
+ }
168
+
169
+
170
+ @ SuppressWarnings ("resource" )
171
+ public void testAllowMultipleMatchesWithPath2 () throws Exception
172
+ {
173
+ String jsonString = aposToQuotes ("{'a':123,'array':[1,2],'ob':{'value0':2,'value':3,'array':[3,4],'value':{'value0':2}},'value':\" val\" ,'b':true}" );
174
+ JsonParser p0 = JSON_F .createParser (jsonString );
175
+ FilteringParserDelegate p = new FilteringParserDelegate (p0 ,
176
+ new IndexMatchFilter (1 ),
177
+ true , // includePath
178
+ true // multipleMatches - true
179
+ );
180
+ String result = readAndWrite (JSON_F , p );
181
+ assertEquals (aposToQuotes ("{\" array\" :[2],\" ob\" :{\" array\" :[4]}}" ), result );
182
+ assertEquals (2 , p .getMatchCount ());
119
183
}
120
184
121
185
@ SuppressWarnings ("resource" )
122
186
public void testMultipleMatchFilteringWithPath1 () throws Exception
123
187
{
124
188
JsonParser p0 = JSON_F .createParser (SIMPLE );
125
- JsonParser p = new FilteringParserDelegate (p0 ,
189
+ FilteringParserDelegate p = new FilteringParserDelegate (p0 ,
126
190
new NameMatchFilter ("value0" , "value2" ),
127
191
true , /* includePath */ true /* multipleMatches */ );
128
192
String result = readAndWrite (JSON_F , p );
129
193
assertEquals (aposToQuotes ("{'ob':{'value0':2,'value2':4}}" ), result );
194
+ assertEquals (2 , p .getMatchCount ());
195
+
130
196
}
131
197
132
198
@ SuppressWarnings ("resource" )
133
199
public void testMultipleMatchFilteringWithPath2 () throws Exception
134
200
{
135
201
String INPUT = aposToQuotes ("{'a':123,'ob':{'value0':2,'value':3,'value2':4},'b':true}" );
136
202
JsonParser p0 = JSON_F .createParser (INPUT );
137
- JsonParser p = new FilteringParserDelegate (p0 ,
203
+ FilteringParserDelegate p = new FilteringParserDelegate (p0 ,
138
204
new NameMatchFilter ("b" , "value" ),
139
205
true , true );
140
206
141
207
String result = readAndWrite (JSON_F , p );
142
208
assertEquals (aposToQuotes ("{'ob':{'value':3},'b':true}" ), result );
209
+ assertEquals (2 , p .getMatchCount ());
143
210
}
144
211
145
212
@ SuppressWarnings ("resource" )
146
213
public void testMultipleMatchFilteringWithPath3 () throws Exception
147
214
{
148
- final String JSON = aposToQuotes ("{'root':{'a0':true,'a':{'value':3},'b':{'value':4 }},'b0':false}" );
215
+ final String JSON = aposToQuotes ("{'root':{'a0':true,'a':{'value':3},'b':{'value':\" foo \" }},'b0':false}" );
149
216
JsonParser p0 = JSON_F .createParser (JSON );
150
- JsonParser p = new FilteringParserDelegate (p0 ,
217
+ FilteringParserDelegate p = new FilteringParserDelegate (p0 ,
151
218
new NameMatchFilter ("value" ),
152
219
true , true );
153
220
String result = readAndWrite (JSON_F , p );
154
- assertEquals (aposToQuotes ("{'root':{'a':{'value':3},'b':{'value':4}}}" ), result );
221
+ assertEquals (aposToQuotes ("{'root':{'a':{'value':3},'b':{'value':\" foo\" }}}" ), result );
222
+ assertEquals (2 , p .getMatchCount ());
155
223
}
156
224
157
225
@ SuppressWarnings ("resource" )
158
226
public void testIndexMatchWithPath1 () throws Exception
159
227
{
160
- JsonParser p = new FilteringParserDelegate (JSON_F .createParser (SIMPLE ),
228
+ FilteringParserDelegate p = new FilteringParserDelegate (JSON_F .createParser (SIMPLE ),
161
229
new IndexMatchFilter (1 ), true , true );
162
230
String result = readAndWrite (JSON_F , p );
163
231
assertEquals (aposToQuotes ("{'array':[2]}" ), result );
232
+ assertEquals (1 , p .getMatchCount ());
164
233
165
234
p = new FilteringParserDelegate (JSON_F .createParser (SIMPLE ),
166
235
new IndexMatchFilter (0 ), true , true );
167
236
result = readAndWrite (JSON_F , p );
168
237
assertEquals (aposToQuotes ("{'array':[1]}" ), result );
238
+ assertEquals (1 , p .getMatchCount ());
169
239
}
170
240
171
241
@ SuppressWarnings ("resource" )
172
242
public void testIndexMatchWithPath2 () throws Exception
173
243
{
174
- JsonParser p = new FilteringParserDelegate (JSON_F .createParser (SIMPLE ),
244
+ FilteringParserDelegate p = new FilteringParserDelegate (JSON_F .createParser (SIMPLE ),
175
245
new IndexMatchFilter (0 , 1 ), true , true );
176
246
assertEquals (aposToQuotes ("{'array':[1,2]}" ), readAndWrite (JSON_F , p ));
247
+ assertEquals (2 , p .getMatchCount ());
177
248
178
249
String JSON = aposToQuotes ("{'a':123,'array':[1,2,3,4,5],'b':[1,2,3]}" );
179
250
p = new FilteringParserDelegate (JSON_F .createParser (JSON ),
180
251
new IndexMatchFilter (1 , 3 ), true , true );
181
252
assertEquals (aposToQuotes ("{'array':[2,4],'b':[2]}" ), readAndWrite (JSON_F , p ));
253
+ assertEquals (3 , p .getMatchCount ());
182
254
}
183
255
}
0 commit comments