content: /*
   * This file was automatically generated by UTestGen and EvoSuite
   * Mon Mar 18 01:22:08 GMT 2024
   */
  
  package org.jsecurity.web.filter.authc;
  
  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.shaded.org.mockito.Mockito.*;
  import static org.evosuite.runtime.EvoAssertions.*;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import javax.servlet.ServletResponseWrapper;
  import org.evosuite.runtime.EvoRunner;
  import org.evosuite.runtime.EvoRunnerParameters;
  import org.evosuite.runtime.ViolatedAssumptionAnswer;
  import org.jsecurity.web.filter.authc.BasicHttpAuthenticationFilter;
  import org.junit.runner.RunWith;
  
  @RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, separateClassLoader = true) 
  public class BasicHttpAuthenticationFilter_ESTest extends BasicHttpAuthenticationFilter_ESTest_scaffolding {
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testCreateTokenThrowsNullPointerException() throws Throwable  {
        // Arrange
        BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
        ServletResponse arg0 = mock(ServletResponse.class, new ViolatedAssumptionAnswer());
        ServletResponseWrapper arg1 = new ServletResponseWrapper(arg0);
        
        // Act and Assert
        basicHttpAuthenticationFilter.createToken((ServletRequest) null, arg1);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testIsLoginAttemptReturningTrue() throws Throwable  {
        // Create a new instance of BasicHttpAuthenticationFilter
        BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
        
        // Verify that the default authentication scheme is "BASIC"
        assertEquals("BASIC", basicHttpAuthenticationFilter.getAuthzScheme());
        
        // Set the authentication scheme to an empty string
        basicHttpAuthenticationFilter.setAuthzScheme("");
        
        // Verify that a login attempt is detected when the authzScheme is set to ""
        boolean loginAttempt = basicHttpAuthenticationFilter.isLoginAttempt("k");
        assertTrue(loginAttempt);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetPrincipalsAndCredentialsTaking2Strings() throws Throwable  {
        // Set up the test data
        String authHeader = "WWW-Authenticate";
        String authResponse = "2tR}S{=Xl";
        
        // Create a new instance of the BasicHttpAuthenticationFilter and call the getPrincipalsAndCredentials method
        BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
        String[] principalsAndCredentials = basicHttpAuthenticationFilter.getPrincipalsAndCredentials(authHeader, authResponse);
        
        // Assert that the auth scheme returned is BASIC
        assertEquals("BASIC", basicHttpAuthenticationFilter.getAuthcScheme());
        assertEquals("BASIC", basicHttpAuthenticationFilter.getAuthzScheme());
        
        // Assert that the length of the principalsAndCredentials array is 1
        assertEquals(1, principalsAndCredentials.length);
        
        // Assert that the application name returned is "application"
        assertEquals("application", basicHttpAuthenticationFilter.getApplicationName());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetAuthzSchemeReturningEmptyString() throws Throwable  {
        // Given a BasicHttpAuthenticationFilter object
        BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
        
        // When the authzScheme is retrieved or set
        String authzScheme = basicHttpAuthenticationFilter.getAuthzScheme();
        basicHttpAuthenticationFilter.setAuthzScheme("");
        
        // Then the expected value is returned
        assertEquals("BASIC", authzScheme);
        assertEquals("", basicHttpAuthenticationFilter.getAuthzScheme());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSetApplicationName() throws Throwable  {
        // Given an instance of BasicHttpAuthenticationFilter
        BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
        
        // When the application name is set to "application"
        basicHttpAuthenticationFilter.setApplicationName("application");
        
        // Then the getApplicationName method returns "application"
        assertEquals("application", basicHttpAuthenticationFilter.getApplicationName());
        
        // Given the application name is set to null
        basicHttpAuthenticationFilter.setApplicationName(null);
        
        // When the getAuthzScheme method is called
        String authzScheme = basicHttpAuthenticationFilter.getAuthzScheme();
        
        // Then the returned value should be "BASIC"
        assertEquals("BASIC", authzScheme);
        
        // When the getAuthcScheme method is called
        String authcScheme = basicHttpAuthenticationFilter.getAuthcScheme();
        
        // Then the returned value should also be "BASIC"
        assertEquals("BASIC", authcScheme);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetAuthzSchemeReturningNonEmptyString() throws Throwable  {
        // Given: a BasicHttpAuthenticationFilter object has been created
        BasicHttpAuthenticationFilter basicHttpAuth = new BasicHttpAuthenticationFilter();
        
        // When: the authzScheme and authcScheme properties are accessed
        String authzScheme = basicHttpAuth.getAuthzScheme();
        String authcScheme = basicHttpAuth.getAuthcScheme();
        
        // Then: the expected values for both schemes should be returned
        assertEquals("BASIC", authzScheme);
        assertEquals("BASIC", authcScheme);
        
        // Also, the application name should be accessible and have the expected value
        assertEquals("application", basicHttpAuth.getApplicationName());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetPrincipalsAndCredentialsTaking1And1ReturningNull() throws Throwable  {
        // Given a BasicHttpAuthenticationFilter instance named "basicHttpAuthenticationFilter"
        BasicHttpAuthenticationFilter filter = new BasicHttpAuthenticationFilter();
        
        // When the getPrincipalsAndCredentials method is called with "username" as the username and null as the ServletRequest
        String[] principalsAndCredentials = filter.getPrincipalsAndCredentials("username", (ServletRequest) null);
        
        // Then, the authzScheme returned should be "BASIC"
        assertEquals("BASIC", filter.getAuthzScheme());
        
        // And the method should return null for principals and credentials
        assertNull(principalsAndCredentials);
        
        // Also, the applicationName should be "application"
        assertEquals("application", filter.getApplicationName());
        
        // Finally, the authcScheme should also be "BASIC"
        assertEquals("BASIC", filter.getAuthcScheme());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetPrincipalsAndCredentialsTaking1And1WithNull() throws Throwable  {
        // rollbacked to evosuite
        BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
        basicHttpAuthenticationFilter.getPrincipalsAndCredentials((String) null, (ServletRequest) null);
        assertEquals("application", basicHttpAuthenticationFilter.getApplicationName());
        assertEquals("BASIC", basicHttpAuthenticationFilter.getAuthzScheme());
        assertEquals("BASIC", basicHttpAuthenticationFilter.getAuthcScheme());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSendChallengeThrowsNullPointerException() throws Throwable  {
        BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
        try {
        basicHttpAuthenticationFilter.sendChallenge(null, null);
        fail("Expecting exception: NullPointerException");
        } catch (NullPointerException e) {
        // no message in exception (getMessage() returned null)
        verifyException("org.jsecurity.web.filter.authc.BasicHttpAuthenticationFilter", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetApplicationNameReturningNonEmptyString() throws Throwable  {
        // Given a BasicHttpAuthenticationFilter instance
        BasicHttpAuthenticationFilter filter = new BasicHttpAuthenticationFilter();
        
        // When the application name is retrieved
        String applicationName = filter.getApplicationName();
        
        // Then the application name should be "application"
        assertEquals("application", applicationName);
        
        // And the authentication scheme should be BASIC
        assertEquals("BASIC", filter.getAuthzScheme());
        
        // And the authorization scheme should also be BASIC
        assertEquals("BASIC", filter.getAuthcScheme());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSetAuthcScheme() throws Throwable  {
        // Create a new BasicHttpAuthenticationFilter instance
        BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
        
        // Verify that the default authentication scheme is "BASIC"
        assertEquals("BASIC", basicHttpAuthenticationFilter.getAuthcScheme());
        
        // Set the authentication scheme to null and verify it has no effect
        basicHttpAuthenticationFilter.setAuthcScheme((String) null);
        assertEquals("BASIC", basicHttpAuthenticationFilter.getAuthcScheme()); // Since null is ignored, the default authc scheme should still be "BASIC"
        
        // Verify that the authorization scheme can be set and retrieved
        basicHttpAuthenticationFilter.setAuthzScheme("application");
        assertEquals("application", basicHttpAuthenticationFilter.getAuthzScheme());
        
        // Verify that the application name can be set and retrieved
        basicHttpAuthenticationFilter.setApplicationName("my-application");
        assertEquals("my-application", basicHttpAuthenticationFilter.getApplicationName());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetAuthcSchemeReturningNonEmptyString() throws Throwable  {
        // Given a BasicHttpAuthenticationFilter instance
        BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
        
        // When we call the getAuthcScheme method
        String authcScheme = basicHttpAuthenticationFilter.getAuthcScheme();
        
        // Then we should get the expected "BASIC" authentication scheme
        assertEquals("BASIC", authcScheme);
        
        // When we call the getApplicationName method
        String applicationName = basicHttpAuthenticationFilter.getApplicationName();
        
        // Then we should get the expected "application" name
        assertEquals("application", applicationName);
        
        // When we call the getAuthzScheme method
        String authzScheme = basicHttpAuthenticationFilter.getAuthzScheme();
        
        // Then we should get the expected "BASIC" authorization scheme
        assertEquals("BASIC", authzScheme);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetPrincipalsAndCredentialsTaking1And1ReturningNonEmptyArray() throws Throwable  {
        // rollbacked to evosuite
        BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
        String[] principalsAndCredentials = basicHttpAuthenticationFilter.getPrincipalsAndCredentials("Unable to acquire account data from realm [realmname]", (ServletRequest) null);
        assertEquals("application", basicHttpAuthenticationFilter.getApplicationName());
        assertNotNull(principalsAndCredentials);
        assertEquals("BASIC", basicHttpAuthenticationFilter.getAuthzScheme());
        assertEquals(1, principalsAndCredentials.length);
        assertEquals("BASIC", basicHttpAuthenticationFilter.getAuthcScheme());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testIsLoginAttemptReturningFalse() throws Throwable  {
        // No Comments were added
        BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
        boolean loginAttempt = basicHttpAuthenticationFilter.isLoginAttempt("Password123!");
        assertEquals("BASIC", basicHttpAuthenticationFilter.getAuthzScheme());
        assertEquals("application", basicHttpAuthenticationFilter.getApplicationName());
        assertFalse(loginAttempt);
        assertEquals("BASIC", basicHttpAuthenticationFilter.getAuthcScheme());
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testGetAuthzHeaderThrowsNullPointerException() throws Throwable  {
        BasicHttpAuthenticationFilter basicHttpAuthenticationFilter = new BasicHttpAuthenticationFilter();
        // Given a null ServletRequest
        
        try {
        // When the getAuthzHeader method is called with a null ServletRequest
        basicHttpAuthenticationFilter.getAuthzHeader(null);
        // Then an NullPointerException should be thrown
        fail("Expecting exception: NullPointerException");
        
        } catch (NullPointerException e) {
        // Verify that the correct exception is thrown
        verifyException("org.jsecurity.web.filter.authc.BasicHttpAuthenticationFilter", e);}
    }
  }
  