Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
szysas committed Aug 26, 2024
1 parent 6092097 commit b64c1f7
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

0 comments on commit b64c1f7

Please sign in to comment.