Skip to content

Commit adcbf49

Browse files
Add host-only factory using default port to ServerAddress (#1566)
* Add host-only factory using default port to ServerAddress * Docs comment: add since tag Co-authored-by: Dmitriy Tverdiakov <[email protected]> --------- Co-authored-by: Dmitriy Tverdiakov <[email protected]>
1 parent 8a9c0a7 commit adcbf49

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

driver/clirr-ignored-differences.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,4 +627,10 @@
627627
<method>java.util.Optional rawClassification()</method>
628628
</difference>
629629

630+
<difference>
631+
<className>org/neo4j/driver/net/ServerAddress</className>
632+
<differenceType>7012</differenceType>
633+
<method>org.neo4j.driver.net.ServerAddress of(java.lang.String)</method>
634+
</difference>
635+
630636
</differences>

driver/src/main/java/org/neo4j/driver/net/ServerAddress.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,15 @@ public interface ServerAddress {
4747
static ServerAddress of(String host, int port) {
4848
return new BoltServerAddress(host, port);
4949
}
50+
51+
/**
52+
* Create a new address with the given host using the default bolt port.
53+
*
54+
* @param host the host portion. Should not be {@code null}.
55+
* @return new server address with the specified host and default bolt port.
56+
* @since 5.24.0
57+
*/
58+
static ServerAddress of(String host) {
59+
return ServerAddress.of(host, BoltServerAddress.DEFAULT_PORT);
60+
}
5061
}

driver/src/test/java/org/neo4j/driver/net/ServerAddressTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.jupiter.api.Assertions.assertThrows;
2121

2222
import org.junit.jupiter.api.Test;
23+
import org.neo4j.driver.internal.BoltServerAddress;
2324

2425
class ServerAddressTest {
2526
@Test
@@ -34,6 +35,13 @@ void shouldFailToCreateAddressWithInvalidHost() {
3435
assertThrows(NullPointerException.class, () -> ServerAddress.of(null, 9999));
3536
}
3637

38+
@Test
39+
void shouldCreateAddressWithDefaultPort() {
40+
var address = ServerAddress.of("my.database.example.com");
41+
assertEquals("my.database.example.com", address.host());
42+
assertEquals(BoltServerAddress.DEFAULT_PORT, address.port());
43+
}
44+
3745
@Test
3846
void shouldFailToCreateAddressWithInvalidPort() {
3947
assertThrows(IllegalArgumentException.class, () -> ServerAddress.of("hello.graphs.com", -42));

0 commit comments

Comments
 (0)