Skip to content

Commit ad674a6

Browse files
author
Stephen Asbury
committed
Improved coverage for connect and dispatcher tests
1 parent c66c54d commit ad674a6

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/test/java/io/nats/client/ConnectTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ public void testConnectionTimeout() throws IOException, InterruptedException {
373373
Options options = new Options.Builder().
374374
server(ts.getURI()).
375375
noReconnect().
376+
traceConnection().
376377
connectionTimeout(Duration.ofSeconds(2)). // 2 is also the default but explicit for test
377378
build();
378379
Connection nc = Nats.connect(options);
@@ -397,4 +398,21 @@ public void testSlowConnectionNoTimeout() throws IOException, InterruptedExcepti
397398
}
398399
}
399400
}
401+
402+
@Test
403+
public void testTimeCheckCoverage() throws IOException, InterruptedException {
404+
try (NatsTestServer ts = new NatsTestServer(Options.DEFAULT_PORT, false)) {
405+
Options options = new Options.Builder().
406+
server(ts.getURI()).
407+
traceConnection().
408+
build();
409+
Connection nc = Nats.connect(options);
410+
try {
411+
assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
412+
} finally {
413+
nc.close();
414+
assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
415+
}
416+
}
417+
}
400418
}

src/test/java/io/nats/client/impl/DispatcherTests.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ public void testDoubleSubscribeWithCustomHandler() throws IOException, Interrupt
707707
Dispatcher d = nc.createDispatcher((msg) -> {});
708708

709709
d.subscribe("subject", (msg) -> { count.incrementAndGet(); });
710-
d.subscribe("subject", (msg) -> { count.incrementAndGet(); });
710+
d.subscribe("subject", "queue", (msg) -> { count.incrementAndGet(); });
711711
d.subscribe("done", (msg) -> { done.complete(Boolean.TRUE); });
712712

713713
nc.flush(Duration.ofSeconds(5)); // wait for them to go through
@@ -769,4 +769,43 @@ public void testDoubleSubscribeWithUnsubscribeAfterWithCustomHandler() throws IO
769769
}
770770
}
771771

772+
@Test(expected=IllegalArgumentException.class)
773+
public void testThrowOnEmptySubjectWithMessageHandler() throws IOException, InterruptedException, TimeoutException {
774+
try (NatsTestServer ts = new NatsTestServer(false);
775+
Connection nc = Nats.connect(ts.getURI())) {
776+
Dispatcher d = nc.createDispatcher((msg) -> {});
777+
d.subscribe("", (msg) -> {});
778+
assertFalse(true);
779+
}
780+
}
781+
782+
@Test(expected=IllegalArgumentException.class)
783+
public void testThrowOnEmptyQueueWithMessageHandler() throws IOException, InterruptedException, TimeoutException {
784+
try (NatsTestServer ts = new NatsTestServer(false);
785+
Connection nc = Nats.connect(ts.getURI())) {
786+
Dispatcher d = nc.createDispatcher((msg) -> {});
787+
d.subscribe("subject", "", (msg) -> {});
788+
assertFalse(true);
789+
}
790+
}
791+
792+
@Test(expected=IllegalArgumentException.class)
793+
public void testThrowOnNullSubjectWithQueueWithMessageHandler() throws IOException, InterruptedException, TimeoutException {
794+
try (NatsTestServer ts = new NatsTestServer(false);
795+
Connection nc = Nats.connect(ts.getURI())) {
796+
Dispatcher d = nc.createDispatcher((msg) -> {});
797+
d.subscribe(null, "quque", (msg) -> {});
798+
assertFalse(true);
799+
}
800+
}
801+
802+
@Test(expected=IllegalArgumentException.class)
803+
public void testThrowOnEmptySubjectWithQueueWithMessageHandler() throws IOException, InterruptedException, TimeoutException {
804+
try (NatsTestServer ts = new NatsTestServer(false);
805+
Connection nc = Nats.connect(ts.getURI())) {
806+
Dispatcher d = nc.createDispatcher((msg) -> {});
807+
d.subscribe("", "quque", (msg) -> {});
808+
assertFalse(true);
809+
}
810+
}
772811
}

0 commit comments

Comments
 (0)