6060
6161public class RequestBuilderTest extends MockCoreConfig {
6262
63+ private static final int ELECTRONS_DEFAULT = 12 ;
64+ private static final int ELECTRONS_UPDATED = 14 ;
65+ private static final long QUERY_DEFAULT = 234L ;
66+ private static final long QUERY_UPDATED = 254L ;
67+ private static final double HEADER_DEFAULT = 2.14 ;
68+ private static final double HEADER_UPDATED = 19.95 ;
69+ private static final int ATOM_NUMBER = 23 ;
70+ private static final int ATOM_MASS = 24 ;
71+ private static final int BODY_A_ELECTRONS = 2 ;
72+ private static final int BODY_A_MASS = 4 ;
73+ private static final int BODY_B_ELECTRONS = 4 ;
74+ private static final int BODY_B_MASS = 2 ;
75+ private static final int BODY_B_UPDATED = 8 ;
76+
77+
6378 /**
6479 * Initializes mocks annotated with Mock.
6580 */
@@ -142,7 +157,7 @@ public void testUpdatePathParam() throws IOException {
142157 public void testUpdatePathParamArray () throws IOException {
143158 HttpRequest .Builder localRequestBuilder = new HttpRequest .Builder ().httpMethod (Method .GET )
144159 .templateParam (param -> param .key ("temp" )
145- .value (new String [] { "apple" , "banana" , "cherry" }));
160+ .value (new String [] {"apple" , "banana" , "cherry" }));
146161
147162 updateAndVerify (localRequestBuilder , "$request.path#/temp/1" , "banana" , "mango" );
148163 }
@@ -158,41 +173,41 @@ public void testUpdateSimpleFormParam() throws IOException {
158173 @ Test
159174 public void testUpdateComplexFormParam () throws IOException {
160175 HttpRequest .Builder localRequestBuilder = new HttpRequest .Builder ().httpMethod (Method .GET )
161- .formParam (param -> param .key ("form" ).value (new Atom (12 , 12 )));
176+ .formParam (param -> param .key ("form" ).value (new Atom (ELECTRONS_DEFAULT , ELECTRONS_DEFAULT )));
162177
163- updateAndVerify (localRequestBuilder , "$request.body#/form/NumberOfElectrons" , 12 , 14 );
178+ updateAndVerify (localRequestBuilder , "$request.body#/form/NumberOfElectrons" , ELECTRONS_DEFAULT , ELECTRONS_UPDATED );
164179 }
165180
166181 @ Test
167182 public void testUpdateSimpleQueryParam () throws IOException {
168183 HttpRequest .Builder localRequestBuilder = new HttpRequest .Builder ().httpMethod (Method .GET )
169- .queryParam (param -> param .key ("que" ).value (234L ));
184+ .queryParam (param -> param .key ("que" ).value (QUERY_DEFAULT ));
170185
171- updateAndVerify (localRequestBuilder , "$request.query#/que" , 234L , 254L );
186+ updateAndVerify (localRequestBuilder , "$request.query#/que" , QUERY_DEFAULT , QUERY_UPDATED );
172187 }
173188
174189 @ Test
175190 public void testUpdateComplexQueryParam () throws IOException {
176191 HttpRequest .Builder localRequestBuilder = new HttpRequest .Builder ().httpMethod (Method .GET )
177- .queryParam (param -> param .key ("que" ).value (new Atom (12 , 12 )));
192+ .queryParam (param -> param .key ("que" ).value (new Atom (ELECTRONS_DEFAULT , ELECTRONS_DEFAULT )));
178193
179- updateAndVerify (localRequestBuilder , "$request.query#/que/NumberOfElectrons" , 12 , 14 );
194+ updateAndVerify (localRequestBuilder , "$request.query#/que/NumberOfElectrons" , ELECTRONS_DEFAULT , ELECTRONS_UPDATED );
180195 }
181196
182197 @ Test
183198 public void testUpdateSimpleHeaderParam () throws IOException {
184199 HttpRequest .Builder localRequestBuilder = new HttpRequest .Builder ().httpMethod (Method .GET )
185- .headerParam (param -> param .key ("head" ).value (2.14 ));
200+ .headerParam (param -> param .key ("head" ).value (HEADER_DEFAULT ));
186201
187- updateAndVerify (localRequestBuilder , "$request.headers#/head" , 2.14 , 19.95 );
202+ updateAndVerify (localRequestBuilder , "$request.headers#/head" , HEADER_DEFAULT , HEADER_UPDATED );
188203 }
189204
190205 @ Test
191206 public void testUpdateComplexHeaderParam () throws IOException {
192207 HttpRequest .Builder localRequestBuilder = new HttpRequest .Builder ().httpMethod (Method .GET )
193- .headerParam (param -> param .key ("head" ).value (new Atom (12 , 12 )));
208+ .headerParam (param -> param .key ("head" ).value (new Atom (ELECTRONS_DEFAULT , ELECTRONS_DEFAULT )));
194209
195- updateAndVerify (localRequestBuilder , "$request.headers#/head/NumberOfElectrons" , 12 , 14 );
210+ updateAndVerify (localRequestBuilder , "$request.headers#/head/NumberOfElectrons" , ELECTRONS_DEFAULT , ELECTRONS_UPDATED );
196211 }
197212
198213 @ Test
@@ -207,18 +222,18 @@ public void testUpdateMultipleBodyParams() throws IOException {
207222 @ Test
208223 public void testUpdateComplexBodyParam () throws IOException {
209224 HttpRequest .Builder localRequestBuilder = new HttpRequest .Builder ().httpMethod (Method .POST )
210- .bodyParam (param -> param .value (new Atom (23 , 24 )));
225+ .bodyParam (param -> param .value (new Atom (ATOM_NUMBER , ATOM_MASS )));
211226
212- updateAndVerify (localRequestBuilder , "$request.body#/NumberOfElectrons" , 23 , 24 );
227+ updateAndVerify (localRequestBuilder , "$request.body#/NumberOfElectrons" , ATOM_NUMBER , ATOM_MASS );
213228 }
214229
215230 @ Test
216231 public void testUpdateMultipleComplexBodyParams () throws IOException {
217232 HttpRequest .Builder localRequestBuilder = new HttpRequest .Builder ().httpMethod (Method .POST )
218- .bodyParam (param -> param .key ("bodyA" ).value (new Atom (2 , 4 )))
219- .bodyParam (param -> param .key ("bodyB" ).value (new Atom (4 , 2 )));
233+ .bodyParam (param -> param .key ("bodyA" ).value (new Atom (BODY_A_ELECTRONS , BODY_A_MASS )))
234+ .bodyParam (param -> param .key ("bodyB" ).value (new Atom (BODY_B_ELECTRONS , BODY_B_MASS )));
220235
221- updateAndVerify (localRequestBuilder , "$request.body#/bodyB/NumberOfElectrons" , 4 , 8 );
236+ updateAndVerify (localRequestBuilder , "$request.body#/bodyB/NumberOfElectrons" , BODY_B_ELECTRONS , BODY_B_UPDATED );
222237 }
223238
224239 @ Test
@@ -230,14 +245,12 @@ public void testUpdateSimpleBodyParam() throws IOException {
230245 }
231246
232247 private void updateAndVerify (HttpRequest .Builder requestBuilder , String pointer , Object oldValue , Object newValue ) {
233- requestBuilder .updateParameterByJsonPointer (pointer , old ->
234- {
248+ requestBuilder .updateParameterByJsonPointer (pointer , old -> {
235249 assertEquals (oldValue .toString (), old .toString ());
236250 return newValue ;
237251 });
238252 AtomicBoolean asserted = new AtomicBoolean (false );
239- requestBuilder .updateParameterByJsonPointer (pointer , newV ->
240- {
253+ requestBuilder .updateParameterByJsonPointer (pointer , newV -> {
241254 assertEquals (newValue .toString (), newV .toString ());
242255 asserted .set (true );
243256 return newV ;
@@ -248,25 +261,28 @@ private void updateAndVerify(HttpRequest.Builder requestBuilder, String pointer,
248261 @ Test (expected = NullPointerException .class )
249262 public void testBodyParamValidation () throws IOException {
250263 // when
251- new HttpRequest .Builder ().httpMethod (Method .POST ).bodyParam (param -> param .value (null ))
264+ new HttpRequest .Builder ()
265+ .httpMethod (Method .POST )
266+ .bodyParam (param -> param .value (null ))
252267 .build (getMockGlobalConfig ());
253-
254268 }
255269
256270 @ Test (expected = NullPointerException .class )
257271 public void testBodyParamValidation1 () throws IOException {
258272 // when
259- new HttpRequest .Builder ().httpMethod (Method .POST ).bodyParam (param -> param .value (null ))
273+ new HttpRequest .Builder ()
274+ .httpMethod (Method .POST )
275+ .bodyParam (param -> param .value (null ))
260276 .build (getMockGlobalConfig ());
261-
262277 }
263278
264279 @ Test
265280 public void testBodyParam () throws IOException {
266281 // when
267282 Request coreHttpRequest =
268283 new HttpRequest .Builder ().httpMethod (Method .PATCH )
269- .bodyParam (param -> param .value ("bodyValue" )).build (getMockGlobalConfig ());
284+ .bodyParam (param -> param .value ("bodyValue" ))
285+ .build (getMockGlobalConfig ());
270286
271287 when (coreHttpRequest .getBody ()).thenReturn ("bodyValue" );
272288
0 commit comments