@@ -136,28 +136,28 @@ public void ensureJsCannotCreateANewSession() throws URISyntaxException {
136
136
.build ();
137
137
distributor .add (node );
138
138
139
- HttpClient client = HttpClient .Factory .createDefault ().createClient (server .getUrl ());
140
-
141
- // Attempt to create a session with an origin header but content type set
142
- HttpResponse res = client . execute (
143
- new HttpRequest ( POST , "/session" )
144
- .addHeader ("Content-Type " , JSON_UTF_8 )
145
- . addHeader ( "Origin" , "localhost" )
146
- . setContent ( Contents . asJson ( ImmutableMap .of (
147
- "capabilities " , ImmutableMap . of (
148
- "alwaysMatch" , Browser . detect (). getCapabilities ())))));
149
-
150
- assertThat ( res . getStatus ()). isEqualTo ( HTTP_INTERNAL_ERROR );
151
-
152
- // And now make sure the session is just fine
153
- res = client . execute (
154
- new HttpRequest ( POST , "/session" )
155
- . addHeader ( "Content-Type" , JSON_UTF_8 )
156
- . setContent ( Contents . asJson ( ImmutableMap .of (
157
- "capabilities " , ImmutableMap . of (
158
- "alwaysMatch" , Browser . detect (). getCapabilities ())))));
159
-
160
- assertThat ( res . isSuccessful ()). isTrue ();
139
+ try ( HttpClient client = HttpClient .Factory .createDefault ().createClient (server .getUrl ())) {
140
+ // Attempt to create a session with an origin header but content type set
141
+ HttpResponse res = client . execute (
142
+ new HttpRequest ( POST , "/session" )
143
+ . addHeader ( "Content-Type" , JSON_UTF_8 )
144
+ .addHeader ("Origin " , "localhost" )
145
+ . setContent ( Contents . asJson ( ImmutableMap . of (
146
+ "capabilities" , ImmutableMap .of (
147
+ "alwaysMatch " , Browser . detect (). getCapabilities ())))));
148
+
149
+ assertThat ( res . getStatus ()). isEqualTo ( HTTP_INTERNAL_ERROR );
150
+
151
+ // And now make sure the session is just fine
152
+ res = client . execute (
153
+ new HttpRequest ( POST , "/session" )
154
+ . addHeader ( "Content-Type" , JSON_UTF_8 )
155
+ . setContent ( Contents . asJson ( ImmutableMap . of (
156
+ "capabilities" , ImmutableMap .of (
157
+ "alwaysMatch " , Browser . detect (). getCapabilities ())))));
158
+
159
+ assertThat ( res . isSuccessful ()). isTrue ();
160
+ }
161
161
}
162
162
163
163
@ Test
@@ -228,9 +228,10 @@ public void shouldRetryNewSessionRequestOnUnexpectedError() throws URISyntaxExce
228
228
"capabilities" , ImmutableMap .of (
229
229
"alwaysMatch" , capabilities ))));
230
230
231
- HttpClient client = clientFactory .createClient (server .getUrl ());
232
- HttpResponse httpResponse = client .execute (request );
233
- assertThat (httpResponse .getStatus ()).isEqualTo (HTTP_OK );
231
+ try (HttpClient client = clientFactory .createClient (server .getUrl ())) {
232
+ HttpResponse httpResponse = client .execute (request );
233
+ assertThat (httpResponse .getStatus ()).isEqualTo (HTTP_OK );
234
+ }
234
235
}
235
236
236
237
}
0 commit comments