23
23
import org .junit .jupiter .api .BeforeEach ;
24
24
import org .junit .jupiter .api .Test ;
25
25
26
+ import javax .net .ssl .KeyManager ;
27
+ import java .lang .reflect .Method ;
26
28
import java .security .KeyStore ;
27
29
import java .util .Arrays ;
28
30
import java .util .Collections ;
33
35
import static org .junit .jupiter .api .Assertions .assertEquals ;
34
36
import static org .junit .jupiter .api .Assertions .assertNotNull ;
35
37
import static org .junit .jupiter .api .Assertions .assertNull ;
38
+ import static org .mockito .Mockito .mock ;
36
39
37
40
@ SuppressWarnings ("this-escape" )
38
41
public class DefaultSslEngineFactoryTest {
@@ -324,6 +327,8 @@ private String pemFilePath(String pem) throws Exception {
324
327
return TestUtils .tempFile (pem ).getAbsolutePath ();
325
328
}
326
329
330
+
331
+
327
332
private Password pemAsConfigValue (String ... pemValues ) {
328
333
StringBuilder builder = new StringBuilder ();
329
334
for (String pem : pemValues ) {
@@ -332,4 +337,27 @@ private Password pemAsConfigValue(String... pemValues) {
332
337
}
333
338
return new Password (builder .toString ().trim ());
334
339
}
340
+
341
+ @ Test
342
+ void testApplyAliasToKM () throws Exception {
343
+ DefaultSslEngineFactory instance = new DefaultSslEngineFactory ();
344
+ // Mock KeyManager array
345
+ KeyManager mockKeyManager = mock (KeyManager .class );
346
+ KeyManager [] kms = new KeyManager []{mockKeyManager };
347
+
348
+ // Define the alias
349
+ String alias = "testAlias" ;
350
+
351
+ // Use reflection to access the private method
352
+ Method method = DefaultSslEngineFactory .class .getDeclaredMethod ("applyAliasToKM" , KeyManager [].class , String .class );
353
+ method .setAccessible (true );
354
+
355
+ // Invoke the method
356
+ KeyManager [] result = (KeyManager []) method .invoke (instance , (Object ) kms , alias );
357
+
358
+ // Validate results (Modify based on actual method behavior)
359
+ assertNotNull (result );
360
+ assertEquals (1 , result .length );
361
+ }
362
+
335
363
}
0 commit comments