@@ -369,4 +369,55 @@ public void testGetSslHandshakeTimeout() {
369369 agentPropertiesFileHandlerMocked .when (() -> AgentPropertiesFileHandler .getPropertyValue (Mockito .eq (AgentProperties .SSL_HANDSHAKE_TIMEOUT ))).thenReturn (expected );
370370 Assert .assertEquals (expected , agentShellSpy .getSslHandshakeTimeout ());
371371 }
372+
373+ private void mockLastSetupCompletedHost (String value ) {
374+ PowerMockito .mockStatic (AgentPropertiesFileHandler .class );
375+ PowerMockito .when (AgentPropertiesFileHandler .getPropertyValue (Mockito .eq (AgentProperties .LAST_SETUP_COMPLETED_HOST ))).thenReturn (value );
376+ }
377+
378+ @ Test
379+ @ PrepareForTest (AgentPropertiesFileHandler .class )
380+ public void getHostsTestAppendsLastSetupCompletedHostAsFallback () {
381+ mockLastSetupCompletedHost ("30.3.3.3" );
382+ agentShellSpy .setHosts ("10.1.1.1,20.2.2.2" );
383+
384+ Assert .assertArrayEquals (new String [] {"10.1.1.1" , "20.2.2.2" , "30.3.3.3" }, agentShellSpy .getHosts ());
385+ }
386+
387+ @ Test
388+ @ PrepareForTest (AgentPropertiesFileHandler .class )
389+ public void getHostsTestSubstringHostDoesNotSuppressFallback () {
390+ // 10.0.0.1 is a substring of 10.0.0.10 but not the same host, so it must still be appended.
391+ mockLastSetupCompletedHost ("10.0.0.1" );
392+ agentShellSpy .setHosts ("10.0.0.10" );
393+
394+ Assert .assertArrayEquals (new String [] {"10.0.0.10" , "10.0.0.1" }, agentShellSpy .getHosts ());
395+ }
396+
397+ @ Test
398+ @ PrepareForTest (AgentPropertiesFileHandler .class )
399+ public void getHostsTestExactMatchIsNotDuplicated () {
400+ mockLastSetupCompletedHost ("20.2.2.2" );
401+ agentShellSpy .setHosts ("10.1.1.1,20.2.2.2" );
402+
403+ Assert .assertArrayEquals (new String [] {"10.1.1.1" , "20.2.2.2" }, agentShellSpy .getHosts ());
404+ }
405+
406+ @ Test
407+ @ PrepareForTest (AgentPropertiesFileHandler .class )
408+ public void getHostsTestMatchIsCaseInsensitiveAndTrimmed () {
409+ mockLastSetupCompletedHost (" HOSTA.EXAMPLE.COM " );
410+ agentShellSpy .setHosts ("hosta.example.com,hostb.example.com" );
411+
412+ Assert .assertArrayEquals (new String [] {"hosta.example.com" , "hostb.example.com" }, agentShellSpy .getHosts ());
413+ }
414+
415+ @ Test
416+ @ PrepareForTest (AgentPropertiesFileHandler .class )
417+ public void getHostsTestBlankLastSetupCompletedHostReturnsConfiguredHostsOnly () {
418+ mockLastSetupCompletedHost (" " );
419+ agentShellSpy .setHosts ("10.1.1.1,20.2.2.2" );
420+
421+ Assert .assertArrayEquals (new String [] {"10.1.1.1" , "20.2.2.2" }, agentShellSpy .getHosts ());
422+ }
372423}
0 commit comments