@@ -31,15 +31,15 @@ public class TestTokenList {
31
31
public void testAll () throws IOException {
32
32
Set <String > expected = new HashSet <String >();
33
33
expected .add ("*" );
34
- doTestVary ("*" , expected );
34
+ doTestVary ("*" , expected , true );
35
35
}
36
36
37
37
38
38
@ Test
39
39
public void testSingle () throws IOException {
40
40
Set <String > expected = new HashSet <String >();
41
41
expected .add ("host" );
42
- doTestVary ("Host" , expected );
42
+ doTestVary ("Host" , expected , true );
43
43
}
44
44
45
45
@@ -49,21 +49,21 @@ public void testMultiple() throws IOException {
49
49
expected .add ("bar" );
50
50
expected .add ("foo" );
51
51
expected .add ("host" );
52
- doTestVary ("Host, Foo, Bar" , expected );
52
+ doTestVary ("Host, Foo, Bar" , expected , true );
53
53
}
54
54
55
55
56
56
@ Test
57
57
public void testEmptyString () throws IOException {
58
58
Set <String > s = Collections .emptySet ();
59
- doTestVary ("" , s );
59
+ doTestVary ("" , s , false );
60
60
}
61
61
62
62
63
63
@ Test
64
64
public void testSingleInvalid () throws IOException {
65
65
Set <String > s = Collections .emptySet ();
66
- doTestVary ("{{{" , s );
66
+ doTestVary ("{{{" , s , false );
67
67
}
68
68
69
69
@@ -73,7 +73,7 @@ public void testMultipleWithInvalidStart() throws IOException {
73
73
expected .add ("bar" );
74
74
expected .add ("foo" );
75
75
expected .add ("host" );
76
- doTestVary ("{{{, Host, Foo, Bar" , expected );
76
+ doTestVary ("{{{, Host, Foo, Bar" , expected , false );
77
77
}
78
78
79
79
@@ -83,7 +83,7 @@ public void testMultipleWithInvalidMiddle() throws IOException {
83
83
expected .add ("bar" );
84
84
expected .add ("foo" );
85
85
expected .add ("host" );
86
- doTestVary ("Host, {{{, Foo, Bar" , expected );
86
+ doTestVary ("Host, {{{, Foo, Bar" , expected , false );
87
87
}
88
88
89
89
@@ -93,7 +93,7 @@ public void testMultipleWithInvalidEnd() throws IOException {
93
93
expected .add ("bar" );
94
94
expected .add ("foo" );
95
95
expected .add ("host" );
96
- doTestVary ("Host, Foo, Bar, {{{" , expected );
96
+ doTestVary ("Host, Foo, Bar, {{{" , expected , false );
97
97
}
98
98
99
99
@@ -103,7 +103,7 @@ public void testMultipleWithInvalidStart2() throws IOException {
103
103
expected .add ("bar" );
104
104
expected .add ("foo" );
105
105
expected .add ("host" );
106
- doTestVary ("OK {{{, Host, Foo, Bar" , expected );
106
+ doTestVary ("OK {{{, Host, Foo, Bar" , expected , false );
107
107
}
108
108
109
109
@@ -113,7 +113,7 @@ public void testMultipleWithInvalidMiddle2() throws IOException {
113
113
expected .add ("bar" );
114
114
expected .add ("foo" );
115
115
expected .add ("host" );
116
- doTestVary ("Host, OK {{{, Foo, Bar" , expected );
116
+ doTestVary ("Host, OK {{{, Foo, Bar" , expected , false );
117
117
}
118
118
119
119
@@ -123,21 +123,80 @@ public void testMultipleWithInvalidEnd2() throws IOException {
123
123
expected .add ("bar" );
124
124
expected .add ("foo" );
125
125
expected .add ("host" );
126
- doTestVary ("Host, Foo, Bar, OK {{{" , expected );
126
+ doTestVary ("Host, Foo, Bar, OK {{{" , expected , false );
127
127
}
128
128
129
129
130
130
@ SuppressWarnings ("deprecation" )
131
- private void doTestVary (String input , Set <String > expected ) throws IOException {
131
+ private void doTestVary (String input , Set <String > expectedTokens , boolean expectedResult ) throws IOException {
132
132
StringReader reader = new StringReader (input );
133
- Set <String > result = new HashSet <String >();
134
- Vary .parseVary (reader , result );
135
- Assert .assertEquals (expected , result );
133
+ Set <String > tokens = new HashSet <String >();
134
+ Vary .parseVary (reader , tokens );
135
+ Assert .assertEquals (expectedTokens , tokens );
136
136
137
137
// Can't use reset(). Parser uses marks.
138
138
reader = new StringReader (input );
139
- result .clear ();
140
- TokenList .parseTokenList (reader , result );
141
- Assert .assertEquals (expected , result );
139
+ tokens .clear ();
140
+ boolean result = TokenList .parseTokenList (reader , tokens );
141
+ Assert .assertEquals (expectedTokens , tokens );
142
+ Assert .assertEquals (Boolean .valueOf (expectedResult ), Boolean .valueOf (result ));
142
143
}
144
+
145
+
146
+ @ Test
147
+ public void testMultipleHeadersValidWithoutNull () throws IOException {
148
+ doTestMultipleHeadersValid (false );
149
+ }
150
+
151
+
152
+ @ Test
153
+ public void testMultipleHeadersValidWithNull () throws IOException {
154
+ doTestMultipleHeadersValid (true );
155
+ }
156
+
157
+
158
+ private void doTestMultipleHeadersValid (boolean withNull ) throws IOException {
159
+ Set <String > expectedTokens = new HashSet <String >();
160
+ expectedTokens .add ("bar" );
161
+ expectedTokens .add ("foo" );
162
+ expectedTokens .add ("foo2" );
163
+
164
+ Set <String > inputs = new HashSet <String >();
165
+ inputs .add ("foo" );
166
+ if (withNull ) {
167
+ inputs .add (null );
168
+ }
169
+ inputs .add ("bar, foo2" );
170
+
171
+ Set <String > tokens = new HashSet <String >();
172
+
173
+
174
+ boolean result = TokenList .parseTokenList (Collections .enumeration (inputs ), tokens );
175
+ Assert .assertEquals (expectedTokens , tokens );
176
+ Assert .assertTrue (result );
177
+ }
178
+
179
+
180
+ @ Test
181
+ public void doTestMultipleHeadersInvalid () throws IOException {
182
+ Set <String > expectedTokens = new HashSet <String >();
183
+ expectedTokens .add ("bar" );
184
+ expectedTokens .add ("bar2" );
185
+ expectedTokens .add ("foo" );
186
+ expectedTokens .add ("foo2" );
187
+ expectedTokens .add ("foo3" );
188
+
189
+ Set <String > inputs = new HashSet <String >();
190
+ inputs .add ("foo" );
191
+ inputs .add ("bar2, }}}, foo3" );
192
+ inputs .add ("bar, foo2" );
193
+
194
+ Set <String > tokens = new HashSet <String >();
195
+
196
+
197
+ boolean result = TokenList .parseTokenList (Collections .enumeration (inputs ), tokens );
198
+ Assert .assertEquals (expectedTokens , tokens );
199
+ Assert .assertFalse (result );
200
+ }
201
+
143
202
}
0 commit comments