GatewayReceiverImpl implements GatewayReceiver { @Override public String getHost() { if (receiverServer != null) { return receiverServer.getExternalAddress(); } if (hostnameForSenders != null && !hostnameForSenders.isEmpty()) { return hostnameForSenders; } if (bindAddress != null && !bindAddress.isEmpty()) { return bindAddress; } try { return LocalHostUtil.getLocalHostName(); } catch (UnknownHostException e) { throw new IllegalStateException("Could not get host name", e); } } GatewayReceiverImpl(final InternalCache cache, final int startPort, final int endPort,
      final int maximumTimeBetweenPings, final int socketBufferSize, final String bindAddress,
      final List<GatewayTransportFilter> gatewayTransportFilters, final String hostnameForSenders,
      final boolean manualStart); @VisibleForTesting  GatewayReceiverImpl(final InternalCache cache, final int startPort, final int endPort,
      final int maximumTimeBetweenPings, final int socketBufferSize, final String bindAddress,
      final List<GatewayTransportFilter> gatewayTransportFilters, final String hostnameForSenders,
      final boolean manualStart, final boolean isPortAvailableResult,
      final int getRandomAvailablePortInRangeResult); private  GatewayReceiverImpl(final InternalCache cache, final int startPort, final int endPort,
      final int maximumTimeBetweenPings, final int socketBufferSize, final String bindAddress,
      final List<GatewayTransportFilter> gatewayTransportFilters, final String hostnameForSenders,
      final boolean manualStart, final Function<Integer, Boolean> isPortAvailableFunction,
      final Function<PortRange, Integer> getRandomAvailablePortInRangeFunction); @Override String getHostnameForSenders(); @Override String getHost(); @Override List<GatewayTransportFilter> getGatewayTransportFilters(); @Override int getMaximumTimeBetweenPings(); @Override int getPort(); @Override int getStartPort(); @Override int getEndPort(); @Override int getSocketBufferSize(); @Override boolean isManualStart(); @Override CacheServer getServer(); @Override void start(); @Override void stop(); @Override void destroy(); @Override String getBindAddress(); @Override boolean isRunning(); @Override String toString();  }
@Test public void getHostOnUnstartedGatewayShouldReturnLocalHostName() throws UnknownHostException { GatewayReceiver gateway = new GatewayReceiverImpl(cache, 2000, 2001, 5, 100, null, null, null, true, true, 2000); assertThat(gateway.getHost()).isEqualTo(LocalHostUtil.getLocalHostName()); }