### Question:
HostnamePortAsListenAddress { static ListenSocketAddress resolve( Config config, Setting<HostnamePort> setting ) { Function<String,ListenSocketAddress> resolveFn = Settings.LISTEN_SOCKET_ADDRESS.compose( HostnamePortAsListenAddress::stripPortRange ); return config.get( Settings.setting( setting.name(), resolveFn, setting.getDefaultValue() ) ); }    }### Answer:
@Test public void shouldParseHostnamePortCorrectly() { Config config = Config.builder().withSetting( OnlineBackupSettings.online_backup_server, combinedHostname() ).build(); ListenSocketAddress listenSocketAddress = HostnamePortAsListenAddress.resolve( config, OnlineBackupSettings.online_backup_server ); assertEquals( new ListenSocketAddress( getSanitizedHostname(), port ), listenSocketAddress ); }
@Test( expected = InvalidSettingException.class ) public void shouldThrowInvalidSettingsExceptionOnEmptyConfig() { Config config = Config.builder().withSetting( OnlineBackupSettings.online_backup_server, "" ).build(); ListenSocketAddress listenSocketAddress = HostnamePortAsListenAddress.resolve( config, OnlineBackupSettings.online_backup_server ); assertEquals( OnlineBackupSettings.online_backup_server.getDefaultValue(), listenSocketAddress.toString() ); }
@Test( expected = InvalidSettingException.class ) public void shouldThrowInvalidSettingsExceptionOnBadFormat() { Config config = Config.builder().withSetting( OnlineBackupSettings.online_backup_server, "localhost" ).build(); ListenSocketAddress listenSocketAddress = HostnamePortAsListenAddress.resolve( config, OnlineBackupSettings.online_backup_server ); assertEquals( OnlineBackupSettings.online_backup_server.getDefaultValue(), listenSocketAddress.toString() ); }