diff --git a/coap-core/src/test/java/com/mbed/coap/server/CoapServerBuilderTest.java b/coap-core/src/test/java/com/mbed/coap/server/CoapServerBuilderTest.java index 52181f03..bdf6670d 100644 --- a/coap-core/src/test/java/com/mbed/coap/server/CoapServerBuilderTest.java +++ b/coap-core/src/test/java/com/mbed/coap/server/CoapServerBuilderTest.java @@ -16,11 +16,12 @@ */ package com.mbed.coap.server; +import static com.mbed.coap.transport.InMemoryCoapTransport.create; +import static com.mbed.coap.utils.Networks.localhost; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import com.mbed.coap.client.CoapClient; -import com.mbed.coap.transport.InMemoryCoapTransport; import java.time.Duration; import java.util.concurrent.ScheduledExecutorService; import org.junit.jupiter.api.Test; @@ -62,20 +63,19 @@ public void shouldFail_whenIllegalTimeoutValue() throws Exception { @Test public void shouldReuseBuilder() throws Exception { CoapServer server = new CoapServerBuilder() - .transport(InMemoryCoapTransport.create(5683)) + .transport(create(5683)) .build().start(); // when, builder is created - CoapServerBuilder builder = CoapServer.builder() - .transport(InMemoryCoapTransport.create()); + CoapServerBuilder builder = CoapServer.builder(); // then, it can be reused multiple times - for (int i = 0; i < 3; i++) { - CoapClient client = builder.buildClient(server.getLocalSocketAddress()); - assertNotNull(client.ping().get()); - client.close(); - } + CoapClient client1 = builder.transport(create()).buildClient(localhost(5683)); + CoapClient client2 = builder.transport(create()).buildClient(localhost(5683)); + assertNotNull(client1.ping().get()); + assertNotNull(client2.ping().get()); + client1.close(); server.stop(); } }