UriUtils { public static String extractHostFromUri(URI uri) { return Optional .ofNullable(uri.getHost()) .orElseThrow(() -> new InvalidHostException("Host name contains invalid chars. Underscore is one of them.")) .replace("/", ""); } private  UriUtils(); static String extractHostFromUri(URI uri); static Integer extractPortFromUri(URI uri); static String extractAddressFromUri(URI uri); static String extractUserNameFromUri(URI uri); static String extractPasswordFromUri(URI uri); static String extractContextFromUri(URI uri); static String extractDestinationTopicFromUri(URI uri); static URI appendContext(URI uri, String context);  }
@Test(expected = InvalidHostException.class) public void shouldThrowExceptionForInvalidHost() { extractHostFromUri(URI.create("jms: }
@Test public void shouldExtractHostFromUri() { assertThat(extractHostFromUri(FULL_URI)).isEqualTo("localhost"); }