5
5
*/
6
6
package com .offbytwo .jenkins .client ;
7
7
8
+ import static org .junit .Assert .assertEquals ;
9
+ import static org .mockito .ArgumentMatchers .any ;
10
+ import static org .mockito .ArgumentMatchers .eq ;
11
+ import static org .mockito .BDDMockito .given ;
12
+ import static org .mockito .Mockito .mock ;
13
+
8
14
import java .io .ByteArrayInputStream ;
9
15
import java .net .URI ;
10
16
import org .apache .http .Header ;
15
21
import org .apache .http .client .methods .HttpUriRequest ;
16
22
import org .apache .http .impl .client .CloseableHttpClient ;
17
23
import org .apache .http .protocol .HttpContext ;
18
- import static org .junit .Assert .assertEquals ;
19
24
import org .junit .Test ;
20
- import static org .mockito .BDDMockito .given ;
21
- import static org .mockito .Matchers .any ;
22
- import static org .mockito .Matchers .anyString ;
23
- import static org .mockito .Mockito .mock ;
24
25
25
26
26
27
30
31
*/
31
32
public class JenkinsHttpClientTest {
32
33
private static final String URI = "http://localhost/jenkins" ;
33
-
34
+
34
35
35
36
36
37
@ Test
@@ -40,8 +41,8 @@ public void testGet_String() throws Exception {
40
41
final Header versionHeader = mock (Header .class );
41
42
final StatusLine statusLine = mock (StatusLine .class );
42
43
final HttpEntity entity = mock (HttpEntity .class );
43
- given (client .execute (any (HttpUriRequest .class ), any ( HttpContext . class ))).willReturn (response );
44
- given (response .getHeaders (anyString () )).willReturn (new Header []{versionHeader });
44
+ given (client .execute (any (HttpUriRequest .class ), eq (( HttpContext ) null ))).willReturn (response );
45
+ given (response .getHeaders ("X-Jenkins" )).willReturn (new Header []{versionHeader });
45
46
given (response .getStatusLine ()).willReturn (statusLine );
46
47
given (versionHeader .getValue ()).willReturn ("1.234" );
47
48
given (statusLine .getStatusCode ()).willReturn (HttpStatus .SC_OK );
@@ -51,15 +52,15 @@ public void testGet_String() throws Exception {
51
52
final String s = jclient .get ("job/someJob" );
52
53
assertEquals ("someJson" , s );
53
54
}
54
-
55
-
56
-
55
+
56
+
57
+
57
58
@ Test (expected =IllegalStateException .class )
58
59
public void testClose () throws Exception {
59
60
final JenkinsHttpConnection jclient = new JenkinsHttpClient (new URI (URI ));
60
61
jclient .close ();
61
62
jclient .close (); //check multiple calls yield no errors
62
- jclient .get ("job/someJob" );
63
+ jclient .get ("job/someJob" );
63
64
}
64
65
65
66
0 commit comments