diff --git a/src/test/java/TestClientHandlerConstructor.java b/src/test/java/TestClientHandlerConstructor.java index 0a20691..eb1c0ff 100644 --- a/src/test/java/TestClientHandlerConstructor.java +++ b/src/test/java/TestClientHandlerConstructor.java @@ -3,29 +3,28 @@ import org.junit.Test; import java.io.*; import java.net.*; -public class TestClientHandlerConstructor { +public class ClientHandlerTest { @Test - public void testConstructor() { - Socket mockSocket = new Socket(); + // Create a mock Socket + Socket mockSocket = new Socket(); + // Create a ChatServer instance + int port = 12345; // Use any available port for testing + ChatServer mockChatServer = new ChatServer(port); - int port = 12345; - - - ChatServer mockChatServer = new ChatServer(port); + // Create a ClientHandler instance using the constructor + ClientHandler clientHandler = new ClientHandler(mockChatServer, mockSocket); - - 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(); + } - 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)); } }