1313 */
1414package org .apache .hadoop .security .authentication .client ;
1515
16- import org .junit .Assert ;
17- import org .junit .Test ;
16+ import static org .junit .jupiter .api .Assertions .assertEquals ;
17+ import static org .junit .jupiter .api .Assertions .assertFalse ;
18+ import static org .junit .jupiter .api .Assertions .assertTrue ;
19+ import static org .junit .jupiter .api .Assertions .fail ;
20+ import static org .mockito .Mockito .anyString ;
21+ import static org .mockito .Mockito .eq ;
22+ import static org .mockito .Mockito .mock ;
23+ import static org .mockito .Mockito .verify ;
24+ import static org .mockito .Mockito .when ;
25+
26+ import org .junit .jupiter .api .Test ;
1827import org .mockito .Mockito ;
1928
2029import java .net .HttpURLConnection ;
@@ -29,128 +38,128 @@ public class TestAuthenticatedURL {
2938 @ Test
3039 public void testToken () throws Exception {
3140 AuthenticatedURL .Token token = new AuthenticatedURL .Token ();
32- Assert . assertFalse (token .isSet ());
41+ assertFalse (token .isSet ());
3342 token = new AuthenticatedURL .Token ("foo" );
34- Assert . assertTrue (token .isSet ());
35- Assert . assertEquals ("foo" , token .toString ());
43+ assertTrue (token .isSet ());
44+ assertEquals ("foo" , token .toString ());
3645 }
3746
3847 @ Test
3948 public void testInjectToken () throws Exception {
40- HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
49+ HttpURLConnection conn = mock (HttpURLConnection .class );
4150 AuthenticatedURL .Token token = new AuthenticatedURL .Token ();
4251 token .set ("foo" );
4352 AuthenticatedURL .injectToken (conn , token );
44- Mockito . verify (conn ).addRequestProperty (Mockito . eq ("Cookie" ), Mockito . anyString ());
53+ verify (conn ).addRequestProperty (eq ("Cookie" ), anyString ());
4554 }
4655
4756 @ Test
4857 public void testExtractTokenOK () throws Exception {
49- HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
58+ HttpURLConnection conn = mock (HttpURLConnection .class );
5059
51- Mockito . when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_OK );
60+ when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_OK );
5261
5362 String tokenStr = "foo" ;
5463 Map <String , List <String >> headers = new HashMap <String , List <String >>();
5564 List <String > cookies = new ArrayList <String >();
5665 cookies .add (AuthenticatedURL .AUTH_COOKIE + "=" + tokenStr );
5766 headers .put ("Set-Cookie" , cookies );
58- Mockito . when (conn .getHeaderFields ()).thenReturn (headers );
67+ when (conn .getHeaderFields ()).thenReturn (headers );
5968
6069 AuthenticatedURL .Token token = new AuthenticatedURL .Token ();
6170 AuthenticatedURL .extractToken (conn , token );
6271
63- Assert . assertEquals (tokenStr , token .toString ());
72+ assertEquals (tokenStr , token .toString ());
6473 }
6574
6675 @ Test
6776 public void testExtractTokenFail () throws Exception {
68- HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
77+ HttpURLConnection conn = mock (HttpURLConnection .class );
6978
70- Mockito . when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
79+ when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
7180
7281 String tokenStr = "foo" ;
7382 Map <String , List <String >> headers = new HashMap <String , List <String >>();
7483 List <String > cookies = new ArrayList <String >();
7584 cookies .add (AuthenticatedURL .AUTH_COOKIE + "=" + tokenStr );
7685 headers .put ("Set-Cookie" , cookies );
77- Mockito . when (conn .getHeaderFields ()).thenReturn (headers );
86+ when (conn .getHeaderFields ()).thenReturn (headers );
7887
7988 AuthenticatedURL .Token token = new AuthenticatedURL .Token ();
8089 token .set ("bar" );
8190 try {
8291 AuthenticatedURL .extractToken (conn , token );
83- Assert . fail ();
92+ fail ();
8493 } catch (AuthenticationException ex ) {
8594 // Expected
86- Assert . assertFalse (token .isSet ());
95+ assertFalse (token .isSet ());
8796 } catch (Exception ex ) {
88- Assert . fail ();
97+ fail ();
8998 }
9099 }
91100
92101 @ Test
93102 public void testExtractTokenCookieHeader () throws Exception {
94- HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
103+ HttpURLConnection conn = mock (HttpURLConnection .class );
95104
96- Mockito . when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_OK );
105+ when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_OK );
97106
98107 String tokenStr = "foo" ;
99108 Map <String , List <String >> headers = new HashMap <>();
100109 List <String > cookies = new ArrayList <>();
101110 cookies .add (AuthenticatedURL .AUTH_COOKIE + "=" + tokenStr );
102111 headers .put ("Set-Cookie" , cookies );
103- Mockito . when (conn .getHeaderFields ()).thenReturn (headers );
112+ when (conn .getHeaderFields ()).thenReturn (headers );
104113
105114 AuthenticatedURL .Token token = new AuthenticatedURL .Token ();
106115 AuthenticatedURL .extractToken (conn , token );
107116
108- Assert . assertTrue (token .isSet ());
117+ assertTrue (token .isSet ());
109118 }
110119
111120 @ Test
112121 public void testExtractTokenLowerCaseCookieHeader () throws Exception {
113- HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
122+ HttpURLConnection conn = mock (HttpURLConnection .class );
114123
115- Mockito . when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_OK );
124+ when (conn .getResponseCode ()).thenReturn (HttpURLConnection .HTTP_OK );
116125
117126 String tokenStr = "foo" ;
118127 Map <String , List <String >> headers = new HashMap <>();
119128 List <String > cookies = new ArrayList <>();
120129 cookies .add (AuthenticatedURL .AUTH_COOKIE + "=" + tokenStr );
121130 headers .put ("set-cookie" , cookies );
122- Mockito . when (conn .getHeaderFields ()).thenReturn (headers );
131+ when (conn .getHeaderFields ()).thenReturn (headers );
123132
124133 AuthenticatedURL .Token token = new AuthenticatedURL .Token ();
125134 AuthenticatedURL .extractToken (conn , token );
126135
127- Assert . assertTrue (token .isSet ());
136+ assertTrue (token .isSet ());
128137 }
129138
130139 @ Test
131140 public void testConnectionConfigurator () throws Exception {
132- HttpURLConnection conn = Mockito . mock (HttpURLConnection .class );
133- Mockito . when (conn .getResponseCode ()).
141+ HttpURLConnection conn = mock (HttpURLConnection .class );
142+ when (conn .getResponseCode ()).
134143 thenReturn (HttpURLConnection .HTTP_UNAUTHORIZED );
135144
136145 ConnectionConfigurator connConf =
137- Mockito . mock (ConnectionConfigurator .class );
146+ mock (ConnectionConfigurator .class );
138147 Mockito .when (connConf .configure (Mockito .<HttpURLConnection >any ())).
139148 thenReturn (conn );
140149
141150 Authenticator authenticator = Mockito .mock (Authenticator .class );
142151
143152 AuthenticatedURL aURL = new AuthenticatedURL (authenticator , connConf );
144153 aURL .openConnection (new URL ("http://foo" ), new AuthenticatedURL .Token ());
145- Mockito . verify (connConf ).configure (Mockito .<HttpURLConnection >any ());
154+ verify (connConf ).configure (Mockito .<HttpURLConnection >any ());
146155 }
147156
148157 @ Test
149158 public void testGetAuthenticator () throws Exception {
150- Authenticator authenticator = Mockito . mock (Authenticator .class );
159+ Authenticator authenticator = mock (Authenticator .class );
151160
152161 AuthenticatedURL aURL = new AuthenticatedURL (authenticator );
153- Assert . assertEquals (authenticator , aURL .getAuthenticator ());
162+ assertEquals (authenticator , aURL .getAuthenticator ());
154163 }
155164
156165}
0 commit comments