Skip to content

Commit bb0a559

Browse files
committed
Improving defaults
1 parent f8272b8 commit bb0a559

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/test/java/io/nats/NatsRunnerUtilsTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
import static org.junit.jupiter.api.Assertions.*;
2020

2121
public class NatsRunnerUtilsTest extends TestBase {
22-
2322
@Test
2423
public void testGetNatsLocalhostUri() {
25-
assertEquals("nats://localhost:1234", getNatsLocalhostUri(1234));
24+
assertEquals(natsLocalHostFromDefault(1234), getNatsLocalhostUri(1234));
2625
}
2726

2827
@Test
@@ -32,7 +31,7 @@ public void testGetNatsUri() {
3231

3332
@Test
3433
public void testGetLocalhostUri() {
35-
assertEquals("schema://localhost:1234", getLocalhostUri("schema", 1234));
34+
assertEquals(localHostFromDefault("schema", 1234), getLocalhostUri("schema", 1234));
3635
}
3736

3837
@Test

src/test/java/io/nats/TestBase.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ public class TestBase {
3333
setDefaultOutputLevel(Level.WARNING);
3434
}
3535

36+
public static String localHostFromDefaultNoPort(String schema) {
37+
return schema + "://" + getDefaultLocalhostHost().host;
38+
}
39+
40+
public static String localHostFromDefault(String schema, int port) {
41+
return localHostFromDefaultNoPort(schema) + ":" + port;
42+
}
43+
44+
public static String natsLocalHostFromDefaultNoPort() {
45+
return "nats://" + getDefaultLocalhostHost().host;
46+
}
47+
48+
public static String natsLocalHostFromDefault(int port) {
49+
return natsLocalHostFromDefaultNoPort() + ":" + port;
50+
}
51+
3652
protected void validateBasics(NatsServerRunner runner, boolean debug, boolean jetStream) throws IOException {
3753
validateCommandLine(runner, debug, jetStream);
3854
validateHostAndPort(runner);
@@ -51,7 +67,7 @@ protected void validateCommandLine(NatsServerRunner runner, boolean debug, boole
5167
protected void validateHostAndPort(NatsServerRunner server) {
5268
assertTrue(server.getPort() > 0);
5369
assertTrue(server.getPort() != 1234);
54-
assertTrue(server.getURI().startsWith("nats://" + getDefaultLocalhostHost().host));
70+
assertTrue(server.getURI().startsWith(natsLocalHostFromDefaultNoPort()));
5571
}
5672

5773
protected void validateConfigLines(NatsServerRunner runner) throws IOException {

0 commit comments

Comments
 (0)