content: /*
   * This file was automatically generated by UTestGen and EvoSuite
   * Mon Mar 18 08:48:21 GMT 2024
   */
  
  package org.quickserver.net.server.impl;
  
  import org.junit.jupiter.api.Test;
  import static org.junit.jupiter.api.Assertions.*;
  import org.junit.jupiter.api.Timeout;
  import java.util.concurrent.TimeUnit;
  import static org.evosuite.runtime.EvoAssertions.*;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.nio.channels.SelectionKey;
  import java.nio.channels.SocketChannel;
  import java.util.logging.Logger;
  import org.evosuite.runtime.EvoRunner;
  import org.evosuite.runtime.EvoRunnerParameters;
  import org.junit.runner.RunWith;
  import org.quickserver.net.server.ClientEvent;
  import org.quickserver.net.server.ClientWriteHandler;
  import org.quickserver.net.server.DataMode;
  import org.quickserver.net.server.DataType;
  import org.quickserver.net.server.impl.BlockingClientHandler;
  
  @RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, separateClassLoader = true) 
  public class BlockingClientHandler_ESTest extends BlockingClientHandler_ESTest_scaffolding {
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testClean() throws Throwable  {
        // Create a new instance of BlockingClientHandler and clean it up
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        blockingClientHandler.clean();
        
        // Check that the handler has the expected name
        assertEquals("ClientHandler-Pool#-1-ID:130", blockingClientHandler.getName());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSetDataMode0() throws Throwable  {
        // Given
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        Logger anonymousLogger = Logger.getAnonymousLogger();
        DataType dataType = DataType.OUT;
        
        // When
        blockingClientHandler.appLogger = anonymousLogger;
        DataMode dataMode = DataMode.BYTE;
        blockingClientHandler.setDataMode(dataMode, dataType);
        
        // Then
        assertEquals("<ClientHandler-Pool#-1-ID:117>", blockingClientHandler.getName());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSetDataModeThrowsNullPointerException() throws Throwable  {
        // rollbacked to evosuite
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        DataType arg1 = DataType.OUT;
        Logger anonymousLogger = Logger.getAnonymousLogger();
        blockingClientHandler.appLogger = anonymousLogger;
        DataMode arg0 = DataMode.OBJECT;
        // Undeclared exception!
        try { 
          blockingClientHandler.setDataMode(arg0, arg1);
          fail("Expecting exception: NullPointerException");
        
        } catch(NullPointerException e) {
           //
           // no message in exception (getMessage() returned null)
           //
        }
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSetDataMode1() throws Throwable  {
        // rollbacked to evosuite
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        DataType arg1 = DataType.OUT;
        Logger anonymousLogger = Logger.getAnonymousLogger();
        blockingClientHandler.appLogger = anonymousLogger;
        DataMode arg0 = DataMode.STRING;
        blockingClientHandler.setDataMode(arg0, arg1);
        assertEquals("<ClientHandler-Pool#-1-ID:75>", blockingClientHandler.getName());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSetDataMode2() throws Throwable  {
        // Given
        BlockingClientHandler handler = new BlockingClientHandler();
        DataType arg1 = DataType.OUT;
        Logger anonymousLogger = Logger.getAnonymousLogger();
        handler.appLogger = anonymousLogger;
        DataMode arg0 = DataMode.BINARY;
        
        // When
        handler.setDataMode(arg0, arg1);
        
        // Then
        assertEquals("<ClientHandler-Pool#-1-ID:54>", handler.getName());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSetDataModeWithNull() throws Throwable  {
        // Given a BlockingClientHandler object with the name "<ClientHandler-Pool#-1-ID:50>"
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // And a data mode argument of DataType.IN
        DataType arg1 = DataType.IN;
        
        // When setDataMode is called with null and the data type argument
        blockingClientHandler.setDataMode(null, arg1);
        
        // Then the name of the BlockingClientHandler object should be "<ClientHandler-Pool#-1-ID:50>"
        assertEquals("<ClientHandler-Pool#-1-ID:50>", blockingClientHandler.getName());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testRun0() throws Throwable  {
        // Given: A BlockingClientHandler instance has been created
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // When: The run() method is called on the handler
        blockingClientHandler.run();
        
        // Then: The name of the handler should be "<ClientHandler-Pool#-1-ID:46>"
        assertEquals("<ClientHandler-Pool#-1-ID:46>", blockingClientHandler.getName());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testRun1() throws Throwable  {
        // Create a new instance of BlockingClientHandler and add an event to it
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        ClientEvent arg0 = ClientEvent.READ;
        blockingClientHandler.addEvent(arg0);
        
        // Run the handler and verify that it will clean up the resources
        assertTrue(blockingClientHandler.getWillClean());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testCloseConnection() throws Throwable  {
        // Given a BlockingClientHandler instance is created
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // When the connection is closed
        blockingClientHandler.closeConnection();
        
        // Then the name of the client handler should be "<ClientHandler-Pool#-1-ID:31>"
        assertEquals("<ClientHandler-Pool#-1-ID:31>", blockingClientHandler.getName());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSetInputStream() throws Throwable  {
        // Given
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // When
        blockingClientHandler.setInputStream((InputStream) null);
        
        // Then
        assertEquals("<ClientHandler-Pool#-1-ID:25>", blockingClientHandler.getName());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testUpdateInputOutputStreamsThrowsNullPointerException() throws Throwable  {
        // Setup
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // Test
        try {
        blockingClientHandler.updateInputOutputStreams();
        fail("Expected exception: NullPointerException");
        } catch (NullPointerException e) {
        // Verify exception
        verifyException("org.quickserver.net.server.impl.BlockingClientHandler", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testCheckReturnClientHandler() throws Throwable  {
        // Given: A client handler that will be used to block the client
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // When: The checkReturnClientHandler method is called on the client handler
        boolean checkReturnClientHandler = blockingClientHandler.checkReturnClientHandler();
        
        // Then: The method should return true as the client is blocked
        assertTrue(checkReturnClientHandler);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSetSocketChannelThrowsIllegalStateException() throws Throwable  {
        // Arrange
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler(1);
        
        // Act & Assert
        try {
        blockingClientHandler.setSocketChannel((SocketChannel) null);
        fail("Expecting exception: IllegalStateException");
        } catch (IllegalStateException e) {
        // Can't set in blocking mode!
        verifyException("org.quickserver.net.server.impl.BlockingClientHandler", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetBlockingMode() throws Throwable  {
        // Given: A BlockingClientHandler instance with blocking mode enabled
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // When: We call the getBlockingMode method on the handler
        boolean blockingMode = blockingClientHandler.getBlockingMode();
        
        // Then: The value returned should be true, indicating that the handler is in blocking mode
        assertTrue(blockingMode);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSetSelectionKeyThrowsIllegalStateException() throws Throwable  {
        // Given a BlockingClientHandler instance
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // When the setSelectionKey method is called with null as parameter
        try {
        blockingClientHandler.setSelectionKey((SelectionKey) null);
        } catch (IllegalStateException e) {
        // Then an IllegalStateException should be thrown
        verifyException("org.quickserver.net.server.impl.BlockingClientHandler", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testReturnClientHandler() throws Throwable  {
        // Given a BlockingClientHandler object
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // When the getCharset method is called on the BlockingClientHandler object
        String charset = blockingClientHandler.getCharset();
        
        // Then the method should return null, as no charset has been set
        assertNull(charset);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testRegisterForReadThrowsIllegalStateException() throws Throwable  {
        // Given: A BlockingClientHandler instance
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        try {
        // When: Trying to register for read in blocking mode
        blockingClientHandler.registerForRead();
        
        // Then: Expecting an IllegalStateException to be thrown
        fail("Expecting exception: IllegalStateException");
        
        } catch(IllegalStateException e) {
        // Can't register in blocking mode!
        verifyException("org.quickserver.net.server.impl.BlockingClientHandler", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testReadInputStreamThrowsIOException() throws Throwable  {
        // Given: a BlockingClientHandler with null input stream
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // When: reading the input stream
        try {
        blockingClientHandler.readInputStream();
        fail("Expecting exception: IOException");
        } catch(IOException e) {
        // Then: an IOException is thrown, as expected
        verifyException("org.quickserver.net.server.impl.BasicClientHandler", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSetClientWriteHandlerThrowsIllegalStateException() throws Throwable  {
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        // This test is checking that an attempt to set a null client write handler in blocking mode
        // results in an IllegalStateException being thrown.
        try {
        blockingClientHandler.setClientWriteHandler((ClientWriteHandler) null);
        fail("Expecting exception: IllegalStateException");
        
        } catch(IllegalStateException e) {
        // This is the expected behavior, as it is not possible to register a null client write handler in blocking mode.
        verifyException("org.quickserver.net.server.impl.BlockingClientHandler", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetBufferedReader() throws Throwable  {
        // Given
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // When
        BufferedReader bufferedReader = blockingClientHandler.getBufferedReader();
        
        // Then
        assertNotNull(bufferedReader);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testRegisterForWriteThrowsIllegalStateException() throws Throwable  {
        // Given a BlockingClientHandler instance
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // When attempting to register for write in blocking mode
        try {
        blockingClientHandler.registerForWrite();
        } catch(IllegalStateException e) {
        // Then an IllegalStateException is thrown because the handler cannot register in blocking mode
        assertEquals("org.quickserver.net.server.impl.BlockingClientHandler", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testFinalize() throws Throwable  {
        // Given a BlockingClientHandler instance
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // When the finalize method is called on the handler
        blockingClientHandler.finalize();
        
        // Then the name of the handler should be "<ClientHandler-Pool#-1-ID:3>"
        assertEquals("<ClientHandler-Pool#-1-ID:3>", blockingClientHandler.getName());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetSelectionKeyThrowsIllegalStateException() throws Throwable  {
        // Given: A BlockingClientHandler object is created.
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler();
        
        // When: The getSelectionKey method is called on the handler.
        try {
        blockingClientHandler.getSelectionKey();
        } catch(IllegalStateException e) {
        // Then: An IllegalStateException is thrown because the handler cannot be in blocking mode.
        verifyException("org.quickserver.net.server.impl.BlockingClientHandler", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetSocketChannelThrowsIllegalStateException() throws Throwable  {
        // Given
        BlockingClientHandler blockingClientHandler = new BlockingClientHandler(60);
        
        // When
        try {
        blockingClientHandler.getSocketChannel();
        } catch (IllegalStateException e) {
        // Then
        verifyException("org.quickserver.net.server.impl.BlockingClientHandler", e);}
    }
  }
  