Browse Source

refactoring: TestClientHandlerConstructor

remotes/origin/client-handler
Valentin Spiroski 11 months ago
parent
commit
6a7ab650b9
  1. 31
      src/test/java/TestClientHandlerConstructor.java

31
src/test/java/TestClientHandlerConstructor.java

@ -3,29 +3,28 @@ import org.junit.Test;
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
public class TestClientHandlerConstructor {
public class ClientHandlerTest {
@Test @Test
public void testConstructor() { public void testConstructor() {
Socket mockSocket = new Socket();
int port = 12345;
ChatServer mockChatServer = new ChatServer(port);
// Create a mock Socket
Socket mockSocket = new Socket();
ClientHandler clientHandler = new ClientHandler(mockChatServer, mockSocket);
// Create a ChatServer instance
int port = 12345; // Use any available port for testing
ChatServer mockChatServer = new ChatServer(port);
try {
Thread.sleep(1000); // Adjust the sleep duration as needed
} catch (InterruptedException e) {
e.printStackTrace();
}
// Create a ClientHandler instance using the constructor
ClientHandler clientHandler = new ClientHandler(mockChatServer, mockSocket);
// Wait for a short time to allow the ClientHandler to be added to the ChatServer's list of clients
try {
Thread.sleep(1000); // Adjust the sleep duration as needed
} catch (InterruptedException e) {
e.printStackTrace();
}
// Assert that the clientHandler was added to the list of clients in the ChatServer
assertTrue(mockChatServer.getClients().contains(clientHandler)); assertTrue(mockChatServer.getClients().contains(clientHandler));
} }
} }
Loading…
Cancel
Save