Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions driver/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -627,4 +627,10 @@
<method>java.util.Optional rawClassification()</method>
</difference>

<difference>
<className>org/neo4j/driver/net/ServerAddress</className>
<differenceType>7012</differenceType>
<method>org.neo4j.driver.net.ServerAddress of(java.lang.String)</method>
</difference>

</differences>
11 changes: 11 additions & 0 deletions driver/src/main/java/org/neo4j/driver/net/ServerAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ public interface ServerAddress {
static ServerAddress of(String host, int port) {
return new BoltServerAddress(host, port);
}

/**
* Create a new address with the given host using the default bolt port.
*
* @param host the host portion. Should not be {@code null}.
* @return new server address with the specified host and default bolt port.
* @since 5.24.0
*/
static ServerAddress of(String host) {
return ServerAddress.of(host, BoltServerAddress.DEFAULT_PORT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;
import org.neo4j.driver.internal.BoltServerAddress;

class ServerAddressTest {
@Test
Expand All @@ -34,6 +35,13 @@ void shouldFailToCreateAddressWithInvalidHost() {
assertThrows(NullPointerException.class, () -> ServerAddress.of(null, 9999));
}

@Test
void shouldCreateAddressWithDefaultPort() {
var address = ServerAddress.of("my.database.example.com");
assertEquals("my.database.example.com", address.host());
assertEquals(BoltServerAddress.DEFAULT_PORT, address.port());
}

@Test
void shouldFailToCreateAddressWithInvalidPort() {
assertThrows(IllegalArgumentException.class, () -> ServerAddress.of("hello.graphs.com", -42));
Expand Down