2525import java .util .Map ;
2626import javax .servlet .http .HttpServletRequest ;
2727
28+ import org .apache .hadoop .yarn .util .TestBoundedAppender ;
2829import org .junit .jupiter .api .AfterAll ;
2930import org .junit .jupiter .api .BeforeAll ;
3031import org .junit .jupiter .api .Test ;
4344import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
4445import static org .junit .jupiter .api .Assertions .assertEquals ;
4546import static org .junit .jupiter .api .Assertions .assertNull ;
47+ import static org .mockito .Mockito .when ;
4648
4749public class TestWebAppUtils {
4850 private static final String RM1_NODE_ID = "rm1" ;
@@ -109,6 +111,15 @@ void testGetPassword() throws Exception {
109111 assertNull (WebAppUtils .getPassword (conf , "invalid-alias" ));
110112 }
111113
114+ @ Test
115+ void testGetPasswordIOException () throws Exception {
116+ Configuration mockConf = Mockito .mock (Configuration .class );
117+
118+ when (mockConf .getPassword ("error-alias" )).thenThrow (new IOException ("Simulated IO error" ));
119+
120+ assertNull (WebAppUtils .getPassword (mockConf , "error-alias" ));
121+ }
122+
112123 @ Test
113124 void testLoadSslConfiguration () throws Exception {
114125 Configuration conf = provisionCredentialsForSSL ();
@@ -186,7 +197,7 @@ protected Configuration provisionCredentialsForSSL() throws IOException,
186197 void testAppendQueryParams () throws Exception {
187198 HttpServletRequest request = Mockito .mock (HttpServletRequest .class );
188199 String targetUri = "/test/path" ;
189- Mockito . when (request .getCharacterEncoding ()).thenReturn (null );
200+ when (request .getCharacterEncoding ()).thenReturn (null );
190201 Map <String , String > paramResultMap = new HashMap <>();
191202 paramResultMap .put ("param1=x" , targetUri + "?" + "param1=x" );
192203 paramResultMap
@@ -195,7 +206,7 @@ void testAppendQueryParams() throws Exception {
195206 targetUri + "?" + "param1=x¶m2=y¶m3=x+y" );
196207
197208 for (Map .Entry <String , String > entry : paramResultMap .entrySet ()) {
198- Mockito . when (request .getQueryString ()).thenReturn (entry .getKey ());
209+ when (request .getQueryString ()).thenReturn (entry .getKey ());
199210 String uri = WebAppUtils .appendQueryParams (request , targetUri );
200211 assertEquals (entry .getValue (), uri );
201212 }
@@ -205,8 +216,8 @@ void testAppendQueryParams() throws Exception {
205216 void testGetHtmlEscapedURIWithQueryString () throws Exception {
206217 HttpServletRequest request = Mockito .mock (HttpServletRequest .class );
207218 String targetUri = "/test/path" ;
208- Mockito . when (request .getCharacterEncoding ()).thenReturn (null );
209- Mockito . when (request .getRequestURI ()).thenReturn (targetUri );
219+ when (request .getCharacterEncoding ()).thenReturn (null );
220+ when (request .getRequestURI ()).thenReturn (targetUri );
210221 Map <String , String > paramResultMap = new HashMap <>();
211222 paramResultMap .put ("param1=x" , targetUri + "?" + "param1=x" );
212223 paramResultMap
@@ -215,7 +226,7 @@ void testGetHtmlEscapedURIWithQueryString() throws Exception {
215226 targetUri + "?" + "param1=x&param2=y&param3=x+y" );
216227
217228 for (Map .Entry <String , String > entry : paramResultMap .entrySet ()) {
218- Mockito . when (request .getQueryString ()).thenReturn (entry .getKey ());
229+ when (request .getQueryString ()).thenReturn (entry .getKey ());
219230 String uri = WebAppUtils .getHtmlEscapedURIWithQueryString (request );
220231 assertEquals (entry .getValue (), uri );
221232 }
0 commit comments