HmsGenericUtil { public static boolean isHostReachable( String ipAddress ) { try { final String pingCommandTemplate = Constants.HMS_HOST_REACHABILITY_VERIFICATION_COMMAND_TEMPLATE; String command = String.format( pingCommandTemplate, ipAddress ); List<String> commands = new ArrayList<String>(); commands.add( "bash" ); commands.add( "-c" ); commands.add( command ); int status = ProcessUtil.executeCommand( commands ); logger.debug( "Ip '{}' reachability status: {}", ipAddress, status ); if ( status == 0 ) { return true; } else { return false; } } catch ( Exception e ) { String message = String.format( "Exception while trying to reach ip: '%s'.", ipAddress ); logger.error( message, e ); return false; } }  static Object maskPassword( Object obj ); static String getBuildVersion(); static BaseResponse getBaseResponse( final Status status, final String errorMessage ); static BaseResponse getBaseResponse( final int statusCode, final String statusMessage,
                                                final String errorMessage ); static void sleepThread( boolean isTaskCompleted, long sleepInterval ); static Map<String, Object> parseJson( String input ); static T parseStringAsValueType( final String content, Class<T> valueType ); static T parseStringAsTypeReference( final String content, TypeReference<T> typeRef ); static String getPayload( T object ); static boolean isHostReachable( String ipAddress ); static void deleteLatestInventoryBackup();  }
@Test public void testIsHostReachable() { PowerMockito.mockStatic( ProcessUtil.class ); Mockito.when( ProcessUtil.executeCommand( Mockito.anyListOf( String.class ) ) ).thenReturn( 0 ); assertTrue( HmsGenericUtil.isHostReachable( "127.0.0.1" ) ); }