BAEL-4786 - DatagramChannel - review fix

This commit is contained in:
Anshul BANSAL
2021-04-03 13:55:55 +03:00
parent 90f71a5d5b
commit 93487b6c61
4 changed files with 122 additions and 0 deletions
@@ -0,0 +1,24 @@
package com.baeldung.datagramchannel;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.DatagramChannel;
import org.junit.jupiter.api.Test;
public class DatagramChannelUnitTest {
@Test
public void whenClientSendsAndServerReceivesUDPPacket_thenCorrect() throws IOException {
DatagramChannel server = DatagramServer.startServer();
DatagramChannel client = DatagramClient.startClient();
String msg = "Hello, this is a Baeldung's DatagramChannel based UDP client!";
InetSocketAddress serverAddress = new InetSocketAddress("localhost", 7001);
DatagramClient.sendMessage(client, msg, serverAddress);
assertEquals("Hello, this is a Baeldung's DatagramChannel based UDP client!", DatagramServer.receiveMessage(server));
}
}