Odd endless loop while testing username generation

I am playing around the the dev kit and working on username creation based on what my org requires. When trying to set up a test to see what happens when an Id is already in use I manage to hit an endless loop where the counter keeps counting. Then if I can get it running I am always returning the wrong value and never step into my while loop.

Basically what is happening is when I check if a username is unique I am not getting the expected true false values. For the second test case I hard coded the expected values to be returned and this seems to caused the endless loop. I am left scratching my head as to how I fix this. Any pointers on what I am missing in order to get this test case to work as expected?

Rule Java

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import sailpoint.object.Application;
import sailpoint.object.Field;
import sailpoint.object.Identity;
import sailpoint.server.IdnRuleUtil;
import sailpoint.tools.GeneralException;


public class SamAccountNameGenerator {
    Logger log = LogManager.getLogger(SamAccountNameGenerator.class);
    Identity identity = new Identity();
    Application application = new Application();
    IdnRuleUtil idn;
    Field field = new Field();

    int MAX_USERNAME_LENGTH = 9;

    public String buildUserNameBase(String firstName, String lastName) throws GeneralException {
        firstName = firstName.replaceAll("[^a-zA-Z0-9]", "");
        String firstIntial = firstName.substring(0, 1);
        lastName = lastName.replaceAll("[^a-zA-Z0-9]","");
        String lastFirst5 = lastName.substring(0, 5);
        String userName =  firstIntial + lastFirst5;
        log.debug("baseUserName is set to: " + userName);
        return userName;
    } 

    public String findNextId(String userNameBase) throws  GeneralException {
        int counter = 1;
        log.debug("Value for Unique: " + isUnique(userNameBase + "9" + Integer.toString(counter)));
        while(!isUnique(userNameBase + "9" + Integer.toString(counter)))
        {
            log.debug("Value for Unique: " + isUnique(userNameBase + "9" + Integer.toString(counter)));
            log.debug("before counter is set to: " + counter);
            counter++;
            log.debug("after counter is set to: " + counter);
        }

        String userName = userNameBase + "9" + Integer.toString(counter);
        log.debug("full userName is set to: " + userName);
        return userName;
    }

    public boolean maxCountCheck(String userName, int maxLength) throws GeneralException {
        int userIdLength = userName.length();
        if(userIdLength <= maxLength){
            return true;
        }
        else{
            return false;
        }
    }

    public boolean isUnique(String username) throws GeneralException {
        log.debug("Stepping into isUnique()");
        log.debug("username is: " + username);
        log.debug("getName is set to: " + application.getName());
        return !idn.accountExistsByDisplayName(application.getName(), username);
    }

    public String SamAccountNameGenerator(String firstName, String lastName) throws GeneralException{
        String userIdBase = buildUserNameBase(firstName, lastName);
        String userId = findNextId(userIdBase);
        log.debug("userId is set to: " + userId);
        if(userId.length() <= MAX_USERNAME_LENGTH){
            return userId.toLowerCase();
        }
        else{
            return null;
        }
    }
}

Rule XML

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule name="SamAccountNameGenerator" type="AttributeGenerator">
  <Description>Calculates LCS based on start and end dates.</Description>
  <Source><![CDATA[
    import org.apache.log4j.LogManager;
    import org.apache.log4j.Logger;

    import sailpoint.object.Application;
    import sailpoint.object.Field;
    import sailpoint.object.Identity;
    import sailpoint.server.IdnRuleUtil;
    import sailpoint.tools.GeneralException;

        int MAX_USERNAME_LENGTH = 9;

    public String buildUserNameBase(String firstName, String lastName) throws GeneralException {
        firstName = firstName.replaceAll("[^a-zA-Z0-9]", "");
        String firstIntial = firstName.substring(0, 1);
        lastName = lastName.replaceAll("[^a-zA-Z0-9]","");
        String lastFirst5 = lastName.substring(0, 5);
        String userName =  firstIntial + lastFirst5;
        log.debug("baseUserName is set to: " + userName);
        return userName;
    } 

     public String findNextId(String userNameBase) throws  GeneralException {
        int counter = 1;
        log.debug("Value for Unique: " + isUnique(userNameBase + "9" + Integer.toString(counter)));
        while(!isUnique(userNameBase + "9" + Integer.toString(counter)))
        {
            log.debug("Value for Unique: " + isUnique(userNameBase + "9" + Integer.toString(counter)));
            log.debug("before counter is set to: " + counter);
            counter++;
            log.debug("after counter is set to: " + counter);
        }

        String userName = userNameBase + "9" + Integer.toString(counter);
        log.debug("full userName is set to: " + userName);
        return userName;
    }


    public boolean maxCountCheck(String userName, int maxLength) throws GeneralException {
        int userIdLength = userName.length();
        if(userIdLength <= maxLength){
            return true;
        }
        else{
            return false;
        }
    }

   public boolean isUnique(String username) throws GeneralException {
        log.debug("Stepping into isUnique()");
        log.debug("username is: " + username);
        log.debug("getName is set to: " + application.getName());
        return !idn.accountExistsByDisplayName(application.getName(), username);
    }

    public String SamAccountNameGenerator(String firstName, String lastName) throws GeneralException{
        String userIdBase = buildUserNameBase(firstName, lastName);
        String userId = findNextId(userIdBase);
        log.debug("userId is set to: " + userId);
        if(userId.length() <= MAX_USERNAME_LENGTH){
            return userId.toLowerCase();
        }
        else{
            return null;
        }
    }
				
		return SamAccountNameGenerator(identity.getFirstname(), identity.getLastname());
 

 ]]></Source>
</Rule>

Test case Java

package sailpoint;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.Test;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import bsh.EvalError;
import bsh.Interpreter;
import sailpoint.object.Application;
import sailpoint.object.Identity;
import sailpoint.rdk.utils.RuleXmlUtils;
import sailpoint.server.IdnRuleUtil;
import sailpoint.tools.GeneralException;


public class SamAccountNameGeneratorTest{
    Logger log = LogManager.getLogger(SamAccountNameGeneratorTest.class);
    private static final String RULE_FILENAME = "src/main/resources/rules/Rule - AttributeGenerator - SamAccountNameGenerator.xml";

    @Test
    public void testSamAccountNameGenerator() throws GeneralException, EvalError{
        Interpreter i = new Interpreter();

        IdnRuleUtil idn = mock();
        when(idn.accountExistsByDisplayName(any(), any())).thenReturn(false);

        Application application = mock(Application.class);
        when(application.getName()).thenReturn("Active Directory [source]");

        Identity identity = mock(Identity.class);
        when(identity.getFirstname()).thenReturn("Tyler");
        when(identity.getLastname()).thenReturn("Smith");
        String result = "";

        i.set("log", log);
        i.set("idn", idn);
        i.set("application", application);
        i.set("identity", identity);

        String source = RuleXmlUtils.readRuleSourceFromFilePath(RULE_FILENAME);
        result = (String) i.eval(source);

        assertNotNull(result);
        assertEquals(result, "tsmith91");

        log.info("Beanshell script returned: " + result);
    }

    @Test
    public void testSamAccountNameGeneratorExist() throws GeneralException, EvalError{
        Interpreter i = new Interpreter();

        IdnRuleUtil idn = mock();
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith91")).thenReturn(true);
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith92")).thenReturn(false);

        Application application = mock(Application.class);
        when(application.getName()).thenReturn("Active Directory [source]");

        Identity identity = mock(Identity.class);
        when(identity.getFirstname()).thenReturn("Tyler");
        when(identity.getLastname()).thenReturn("Smith");
        String result = "";

        i.set("log", log);
        i.set("idn", idn);
        i.set("application", application);
        i.set("identity", identity);

        String source = RuleXmlUtils.readRuleSourceFromFilePath(RULE_FILENAME);
        result = (String) i.eval(source);

        assertNotNull(result);
        assertEquals(result, "tsmith92");

        log.info("Beanshell script returned: " + result);
    }

}

Logs

<?xml version="1.0" encoding="UTF-8"?>
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" version="3.0" name="sailpoint.SamAccountNameGeneratorTest" time="0.082" tests="2" errors="0" skipped="0" failures="1">
  <properties>
    <property name="java.specification.version" value="17"/>
    <property name="sun.cpu.isalist" value="amd64"/>
    <property name="sun.jnu.encoding" value="Cp1252"/>
    <property name="java.class.path" value="C:\Users\mpotti\OneDrive - SSM Health\Documents\Visual Studio Code Projects\SailPoint Rule Devkit\rule-development-kit\target\test-classes;C:\Users\mpotti\OneDrive - SSM Health\Documents\Visual Studio Code Projects\SailPoint Rule Devkit\rule-development-kit\target\classes;C:\Users\mpotti\.m2\repository\sailpoint\rule-java-docs\1.1\rule-java-docs-1.1.jar;C:\Users\mpotti\.m2\repository\com\google\inject\guice\7.0.0\guice-7.0.0.jar;C:\Users\mpotti\.m2\repository\jakarta\inject\jakarta.inject-api\2.0.1\jakarta.inject-api-2.0.1.jar;C:\Users\mpotti\.m2\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;C:\Users\mpotti\.m2\repository\org\hibernate\hibernate-core\4.2.21.Final\hibernate-core-4.2.21.Final.jar;C:\Users\mpotti\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;C:\Users\mpotti\.m2\repository\org\jboss\logging\jboss-logging\3.1.0.GA\jboss-logging-3.1.0.GA.jar;C:\Users\mpotti\.m2\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar;C:\Users\mpotti\.m2\repository\org\javassist\javassist\3.18.1-GA\javassist-3.18.1-GA.jar;C:\Users\mpotti\.m2\repository\org\jboss\spec\javax\transaction\jboss-transaction-api_1.1_spec\1.0.1.Final\jboss-transaction-api_1.1_spec-1.0.1.Final.jar;C:\Users\mpotti\.m2\repository\org\hibernate\javax\persistence\hibernate-jpa-2.0-api\1.0.1.Final\hibernate-jpa-2.0-api-1.0.1.Final.jar;C:\Users\mpotti\.m2\repository\org\hibernate\common\hibernate-commons-annotations\4.0.2.Final\hibernate-commons-annotations-4.0.2.Final.jar;C:\Users\mpotti\.m2\repository\javax\inject\javax.inject\1\javax.inject-1.jar;C:\Users\mpotti\.m2\repository\com\google\guava\guava\32.0.1-jre\guava-32.0.1-jre.jar;C:\Users\mpotti\.m2\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;C:\Users\mpotti\.m2\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\Users\mpotti\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;C:\Users\mpotti\.m2\repository\org\checkerframework\checker-qual\3.33.0\checker-qual-3.33.0.jar;C:\Users\mpotti\.m2\repository\com\google\errorprone\error_prone_annotations\2.18.0\error_prone_annotations-2.18.0.jar;C:\Users\mpotti\.m2\repository\com\google\j2objc\j2objc-annotations\2.8\j2objc-annotations-2.8.jar;C:\Users\mpotti\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.15.2\jackson-annotations-2.15.2.jar;C:\Users\mpotti\.m2\repository\com\github\albfernandez\juniversalchardet\2.4.0\juniversalchardet-2.4.0.jar;C:\Users\mpotti\.m2\repository\org\aspectj\aspectjtools\1.6.2\aspectjtools-1.6.2.jar;C:\Users\mpotti\.m2\repository\org\apache\commons\commons-lang3\3.12.0\commons-lang3-3.12.0.jar;C:\Users\mpotti\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\mpotti\.m2\repository\com\jayway\jsonpath\json-path\2.8.0\json-path-2.8.0.jar;C:\Users\mpotti\.m2\repository\net\minidev\json-smart\2.4.10\json-smart-2.4.10.jar;C:\Users\mpotti\.m2\repository\net\minidev\accessors-smart\2.4.9\accessors-smart-2.4.9.jar;C:\Users\mpotti\.m2\repository\org\ow2\asm\asm\9.3\asm-9.3.jar;C:\Users\mpotti\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\mpotti\.m2\repository\net\bytebuddy\byte-buddy\1.14.5\byte-buddy-1.14.5.jar;C:\Users\mpotti\.m2\repository\org\junit\jupiter\junit-jupiter\5.9.2\junit-jupiter-5.9.2.jar;C:\Users\mpotti\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.9.2\junit-jupiter-api-5.9.2.jar;C:\Users\mpotti\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\mpotti\.m2\repository\org\junit\platform\junit-platform-commons\1.9.2\junit-platform-commons-1.9.2.jar;C:\Users\mpotti\.m2\repository\org\apiguardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;C:\Users\mpotti\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.9.2\junit-jupiter-params-5.9.2.jar;C:\Users\mpotti\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.9.2\junit-jupiter-engine-5.9.2.jar;C:\Users\mpotti\.m2\repository\org\junit\platform\junit-platform-engine\1.9.2\junit-platform-engine-1.9.2.jar;C:\Users\mpotti\.m2\repository\org\apache\logging\log4j\log4j-1.2-api\2.20.0\log4j-1.2-api-2.20.0.jar;C:\Users\mpotti\.m2\repository\org\apache\logging\log4j\log4j-api\2.20.0\log4j-api-2.20.0.jar;C:\Users\mpotti\.m2\repository\org\apache\logging\log4j\log4j-core\2.20.0\log4j-core-2.20.0.jar;C:\Users\mpotti\.m2\repository\org\mockito\mockito-core\5.2.0\mockito-core-5.2.0.jar;C:\Users\mpotti\.m2\repository\net\bytebuddy\byte-buddy-agent\1.14.1\byte-buddy-agent-1.14.1.jar;C:\Users\mpotti\.m2\repository\org\objenesis\objenesis\3.3\objenesis-3.3.jar;C:\Users\mpotti\.m2\repository\org\apache-extras\beanshell\bsh\2.0b6\bsh-2.0b6.jar;C:\Users\mpotti\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;C:\Users\mpotti\.m2\repository\com\google\code\gson\gson\2.10.1\gson-2.10.1.jar;"/>
    <property name="java.vm.vendor" value="Oracle Corporation"/>
    <property name="sun.arch.data.model" value="64"/>
    <property name="user.variant" value=""/>
    <property name="java.vendor.url" value="https://java.oracle.com/"/>
    <property name="user.timezone" value="America/Chicago"/>
    <property name="os.name" value="Windows 10"/>
    <property name="java.vm.specification.version" value="17"/>
    <property name="sun.java.launcher" value="SUN_STANDARD"/>
    <property name="user.country" value="US"/>
    <property name="sun.boot.library.path" value="C:\Program Files\Java\jdk-17.0.0.1\bin"/>
    <property name="sun.java.command" value="C:\Users\mpotti\AppData\Local\Temp\surefire379208435273246611\surefirebooter-20250423074640343_3.jar C:\Users\mpotti\AppData\Local\Temp\surefire379208435273246611 2025-04-23T07-46-38_043-jvmRun1 surefire-20250423074640343_1tmp surefire_0-20250423074640343_2tmp"/>
    <property name="jdk.debug" value="release"/>
    <property name="surefire.test.class.path" value="C:\Users\mpotti\OneDrive - SSM Health\Documents\Visual Studio Code Projects\SailPoint Rule Devkit\rule-development-kit\target\test-classes;C:\Users\mpotti\OneDrive - SSM Health\Documents\Visual Studio Code Projects\SailPoint Rule Devkit\rule-development-kit\target\classes;C:\Users\mpotti\.m2\repository\sailpoint\rule-java-docs\1.1\rule-java-docs-1.1.jar;C:\Users\mpotti\.m2\repository\com\google\inject\guice\7.0.0\guice-7.0.0.jar;C:\Users\mpotti\.m2\repository\jakarta\inject\jakarta.inject-api\2.0.1\jakarta.inject-api-2.0.1.jar;C:\Users\mpotti\.m2\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;C:\Users\mpotti\.m2\repository\org\hibernate\hibernate-core\4.2.21.Final\hibernate-core-4.2.21.Final.jar;C:\Users\mpotti\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;C:\Users\mpotti\.m2\repository\org\jboss\logging\jboss-logging\3.1.0.GA\jboss-logging-3.1.0.GA.jar;C:\Users\mpotti\.m2\repository\dom4j\dom4j\1.6.1\dom4j-1.6.1.jar;C:\Users\mpotti\.m2\repository\org\javassist\javassist\3.18.1-GA\javassist-3.18.1-GA.jar;C:\Users\mpotti\.m2\repository\org\jboss\spec\javax\transaction\jboss-transaction-api_1.1_spec\1.0.1.Final\jboss-transaction-api_1.1_spec-1.0.1.Final.jar;C:\Users\mpotti\.m2\repository\org\hibernate\javax\persistence\hibernate-jpa-2.0-api\1.0.1.Final\hibernate-jpa-2.0-api-1.0.1.Final.jar;C:\Users\mpotti\.m2\repository\org\hibernate\common\hibernate-commons-annotations\4.0.2.Final\hibernate-commons-annotations-4.0.2.Final.jar;C:\Users\mpotti\.m2\repository\javax\inject\javax.inject\1\javax.inject-1.jar;C:\Users\mpotti\.m2\repository\com\google\guava\guava\32.0.1-jre\guava-32.0.1-jre.jar;C:\Users\mpotti\.m2\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;C:\Users\mpotti\.m2\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\Users\mpotti\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;C:\Users\mpotti\.m2\repository\org\checkerframework\checker-qual\3.33.0\checker-qual-3.33.0.jar;C:\Users\mpotti\.m2\repository\com\google\errorprone\error_prone_annotations\2.18.0\error_prone_annotations-2.18.0.jar;C:\Users\mpotti\.m2\repository\com\google\j2objc\j2objc-annotations\2.8\j2objc-annotations-2.8.jar;C:\Users\mpotti\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.15.2\jackson-annotations-2.15.2.jar;C:\Users\mpotti\.m2\repository\com\github\albfernandez\juniversalchardet\2.4.0\juniversalchardet-2.4.0.jar;C:\Users\mpotti\.m2\repository\org\aspectj\aspectjtools\1.6.2\aspectjtools-1.6.2.jar;C:\Users\mpotti\.m2\repository\org\apache\commons\commons-lang3\3.12.0\commons-lang3-3.12.0.jar;C:\Users\mpotti\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\mpotti\.m2\repository\com\jayway\jsonpath\json-path\2.8.0\json-path-2.8.0.jar;C:\Users\mpotti\.m2\repository\net\minidev\json-smart\2.4.10\json-smart-2.4.10.jar;C:\Users\mpotti\.m2\repository\net\minidev\accessors-smart\2.4.9\accessors-smart-2.4.9.jar;C:\Users\mpotti\.m2\repository\org\ow2\asm\asm\9.3\asm-9.3.jar;C:\Users\mpotti\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;C:\Users\mpotti\.m2\repository\net\bytebuddy\byte-buddy\1.14.5\byte-buddy-1.14.5.jar;C:\Users\mpotti\.m2\repository\org\junit\jupiter\junit-jupiter\5.9.2\junit-jupiter-5.9.2.jar;C:\Users\mpotti\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.9.2\junit-jupiter-api-5.9.2.jar;C:\Users\mpotti\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;C:\Users\mpotti\.m2\repository\org\junit\platform\junit-platform-commons\1.9.2\junit-platform-commons-1.9.2.jar;C:\Users\mpotti\.m2\repository\org\apiguardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;C:\Users\mpotti\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.9.2\junit-jupiter-params-5.9.2.jar;C:\Users\mpotti\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.9.2\junit-jupiter-engine-5.9.2.jar;C:\Users\mpotti\.m2\repository\org\junit\platform\junit-platform-engine\1.9.2\junit-platform-engine-1.9.2.jar;C:\Users\mpotti\.m2\repository\org\apache\logging\log4j\log4j-1.2-api\2.20.0\log4j-1.2-api-2.20.0.jar;C:\Users\mpotti\.m2\repository\org\apache\logging\log4j\log4j-api\2.20.0\log4j-api-2.20.0.jar;C:\Users\mpotti\.m2\repository\org\apache\logging\log4j\log4j-core\2.20.0\log4j-core-2.20.0.jar;C:\Users\mpotti\.m2\repository\org\mockito\mockito-core\5.2.0\mockito-core-5.2.0.jar;C:\Users\mpotti\.m2\repository\net\bytebuddy\byte-buddy-agent\1.14.1\byte-buddy-agent-1.14.1.jar;C:\Users\mpotti\.m2\repository\org\objenesis\objenesis\3.3\objenesis-3.3.jar;C:\Users\mpotti\.m2\repository\org\apache-extras\beanshell\bsh\2.0b6\bsh-2.0b6.jar;C:\Users\mpotti\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;C:\Users\mpotti\.m2\repository\com\google\code\gson\gson\2.10.1\gson-2.10.1.jar;"/>
    <property name="sun.cpu.endian" value="little"/>
    <property name="user.home" value="C:\Users\mpotti"/>
    <property name="user.language" value="en"/>
    <property name="java.specification.vendor" value="Oracle Corporation"/>
    <property name="java.version.date" value="2024-07-02"/>
    <property name="java.home" value="C:\Program Files\Java\jdk-17.0.0.1"/>
    <property name="file.separator" value="\"/>
    <property name="basedir" value="C:\Users\mpotti\OneDrive - SSM Health\Documents\Visual Studio Code Projects\SailPoint Rule Devkit\rule-development-kit"/>
    <property name="java.vm.compressedOopsMode" value="Zero based"/>
    <property name="line.separator" value="&#10;"/>
    <property name="java.vm.specification.vendor" value="Oracle Corporation"/>
    <property name="java.specification.name" value="Java Platform API Specification"/>
    <property name="surefire.real.class.path" value="C:\Users\mpotti\AppData\Local\Temp\surefire379208435273246611\surefirebooter-20250423074640343_3.jar"/>
    <property name="user.script" value=""/>
    <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
    <property name="java.runtime.version" value="17.0.0.1+2-3"/>
    <property name="user.name" value="mpotti"/>
    <property name="path.separator" value=";"/>
    <property name="os.version" value="10.0"/>
    <property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
    <property name="file.encoding" value="Cp1252"/>
    <property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
    <property name="localRepository" value="C:\Users\mpotti\.m2\repository"/>
    <property name="java.vendor.url.bug" value="https://bugreport.java.com/bugreport/"/>
    <property name="java.io.tmpdir" value="C:\Users\mpotti\AppData\Local\Temp\"/>
    <property name="java.version" value="17.0.0.1"/>
    <property name="user.dir" value="C:\Users\mpotti\OneDrive - SSM Health\Documents\Visual Studio Code Projects\SailPoint Rule Devkit\rule-development-kit"/>
    <property name="os.arch" value="amd64"/>
    <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
    <property name="sun.os.patch.level" value=""/>
    <property name="native.encoding" value="Cp1252"/>
    <property name="java.library.path" value="C:\Program Files\Java\jdk-17.0.0.1\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\PowerShell\7;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\Citrix\HDX\bin;C:\Program Files\Citrix\HDX\bin;C:\Program Files (x86)\Gpg4win\..\GnuPG\bin;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files\Maven\apache-maven-3.9.9\bin;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Program Files\SailPoint CLI\;C:\Program Files\PowerShell\7\;c:\Program Files (x86)\Citrix\HDX\bin\;c:\Program Files\Citrix\HDX\bin\;C:\Program Files\dotnet\;C:\Program Files\Yubico\YubiKey Manager CLI\;C:\Program Files\Java\jdk-17.0.0.1\bin;C:\Users\mpotti\AppData\Local\Programs\Microsoft\jdk-17.0.13.11-hotspot\bin;C:\Users\mpotti\AppData\Local\Microsoft\WindowsApps;;C:\Users\mpotti\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\mpotti\.dotnet\tools;."/>
    <property name="java.vm.info" value="mixed mode, sharing"/>
    <property name="java.vendor" value="Oracle Corporation"/>
    <property name="java.vm.version" value="17.0.0.1+2-3"/>
    <property name="java.specification.maintenance.version" value="1"/>
    <property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
    <property name="java.class.version" value="61.0"/>
  </properties>
  <testcase name="testSamAccountNameGeneratorExist" classname="sailpoint.SamAccountNameGeneratorTest" time="0.046">
    <failure message="expected: &lt;tsmith91&gt; but was: &lt;tsmith92&gt;" type="org.opentest4j.AssertionFailedError"><![CDATA[org.opentest4j.AssertionFailedError: expected: <tsmith91> but was: <tsmith92>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1142)
	at sailpoint.SamAccountNameGeneratorTest.testSamAccountNameGeneratorExist(SamAccountNameGeneratorTest.java:79)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.apache.maven.surefire.junitplatform.LazyLauncher.execute(LazyLauncher.java:56)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.execute(JUnitPlatformProvider.java:184)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:148)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:122)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
	at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
]]></failure>
    <system-out><![CDATA[07:46:56.948 [main] DEBUG sailpoint.SamAccountNameGeneratorTest - baseUserName is set to: TSmith
07:46:56.950 [main] DEBUG sailpoint.SamAccountNameGeneratorTest - getName is set to: Active Directory [source]
07:46:56.951 [main] DEBUG sailpoint.SamAccountNameGeneratorTest - Value for Unique: true
07:46:56.951 [main] DEBUG sailpoint.SamAccountNameGeneratorTest - getName is set to: Active Directory [source]
07:46:56.952 [main] DEBUG sailpoint.SamAccountNameGeneratorTest - full userName is set to: TSmith91
07:46:56.952 [main] DEBUG sailpoint.SamAccountNameGeneratorTest - userId is set to: TSmith91
]]></system-out>
  </testcase>
  <testcase name="testSamAccountNameGenerator" classname="sailpoint.SamAccountNameGeneratorTest" time="0.017">
    <system-out><![CDATA[07:46:56.987 [main] DEBUG sailpoint.SamAccountNameGeneratorTest - baseUserName is set to: TSmith
07:46:56.989 [main] DEBUG sailpoint.SamAccountNameGeneratorTest - getName is set to: Active Directory [source]
07:46:56.989 [main] DEBUG sailpoint.SamAccountNameGeneratorTest - Value for Unique: true
07:46:56.989 [main] DEBUG sailpoint.SamAccountNameGeneratorTest - getName is set to: Active Directory [source]
07:46:56.990 [main] DEBUG sailpoint.SamAccountNameGeneratorTest - full userName is set to: TSmith91
07:46:56.990 [main] DEBUG sailpoint.SamAccountNameGeneratorTest - userId is set to: TSmith91
07:46:56.991 [main] INFO  sailpoint.SamAccountNameGeneratorTest - Beanshell script returned: tsmith91
]]></system-out>
  </testcase>
</testsuite>

Ok I found the issue. The issue was I needed to make the base all lower case. This fixed the issue.

Updated Rule

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import sailpoint.object.Application;
import sailpoint.object.Field;
import sailpoint.object.Identity;
import sailpoint.server.IdnRuleUtil;
import sailpoint.tools.GeneralException;


public class SamAccountNameGenerator {
    Logger log = LogManager.getLogger(SamAccountNameGenerator.class);
    Identity identity = new Identity();
    Application application = new Application();
    IdnRuleUtil idn;
    Field field = new Field();

    int MAX_USERNAME_LENGTH = 9;

    public String buildUserNameBase(String firstName, String lastName) throws GeneralException {
        firstName = firstName.replaceAll("[^a-zA-Z0-9]", "");
        String firstIntial = firstName.substring(0, 1);
        lastName = lastName.replaceAll("[^a-zA-Z0-9]","");
        String lastFirst5 = lastName.substring(0, 5);
        String userName =  firstIntial + lastFirst5;
        log.debug("baseUserName is set to: " + userName);
        return userName;
    } 

    public String findNextId(String userNameBase) throws  GeneralException {
        int counter = 1;
        log.debug("Value for Unique: " + isUnique(userNameBase.toLowerCase() + "9" + Integer.toString(counter)));
        while(!isUnique(userNameBase.toLowerCase() + "9" + Integer.toString(counter)))
        {
            log.debug("inside Value for Unique: " + isUnique(userNameBase.toLowerCase() + "9" + Integer.toString(counter)));
            log.debug("before counter is set to: " + counter);
            counter++;
            log.debug("after counter is set to: " + counter);
            if(counter == 12)
            {
                break;
            }
        }

        String userName = userNameBase + "9" + Integer.toString(counter);
        log.debug("full userName is set to: " + userName);
        return userName;
    }

    public boolean maxCountCheck(String userName, int maxLength) throws GeneralException {
        int userIdLength = userName.length();
        if(userIdLength <= maxLength){
            return true;
        }
        else{
            return false;
        }
    }

    public boolean isUnique(String username) throws GeneralException {
        log.debug("Stepping into isUnique()");
        log.debug("username is: " + username);
        log.debug("getName is set to: " + application.getName());
        return !idn.accountExistsByDisplayName(application.getName(), username);
    }

    public String SamAccountNameGenerator(String firstName, String lastName) throws GeneralException{
        String userIdBase = buildUserNameBase(firstName, lastName);
        String userId = findNextId(userIdBase);
        log.debug("userId is set to: " + userId);
        if(userId.length() <= MAX_USERNAME_LENGTH){
            return userId.toLowerCase();
        }
        else{
            return null;
        }
    }
}

Updated Test Cases

package sailpoint;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.Test;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import bsh.EvalError;
import bsh.Interpreter;
import sailpoint.object.Application;
import sailpoint.object.Identity;
import sailpoint.rdk.utils.RuleXmlUtils;
import sailpoint.server.IdnRuleUtil;
import sailpoint.tools.GeneralException;


public class SamAccountNameGeneratorTest{
    Logger log = LogManager.getLogger(SamAccountNameGeneratorTest.class);
    private static final String RULE_FILENAME = "src/main/resources/rules/Rule - AttributeGenerator - SamAccountNameGenerator.xml";

    @Test
    public void testSamAccountNameGenerator() throws GeneralException, EvalError{
        Interpreter i = new Interpreter();

        IdnRuleUtil idn = mock();
        when(idn.accountExistsByDisplayName(any(), any())).thenReturn(false);

        Application application = mock(Application.class);
        when(application.getName()).thenReturn("Active Directory [source]");

        Identity identity = mock(Identity.class);
        when(identity.getFirstname()).thenReturn("Tyler");
        when(identity.getLastname()).thenReturn("Smith");
        String result = "";

        i.set("log", log);
        i.set("idn", idn);
        i.set("application", application);
        i.set("identity", identity);

        String source = RuleXmlUtils.readRuleSourceFromFilePath(RULE_FILENAME);
        result = (String) i.eval(source);

        assertNotNull(result);
        assertEquals(result, "tsmith91");

        log.info("Beanshell script returned: " + result);
    }

    @Test
    public void testSamAccountNameGeneratorExist() throws GeneralException, EvalError{
        Interpreter i = new Interpreter();

        IdnRuleUtil idn = mock();
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith91")).thenReturn(true);
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith92")).thenReturn(false);

        Application application = mock(Application.class);
        when(application.getName()).thenReturn("Active Directory [source]");

        Identity identity = mock(Identity.class);
        when(identity.getFirstname()).thenReturn("Tyler");
        when(identity.getLastname()).thenReturn("Smith");
        String result = "";

        i.set("log", log);
        i.set("idn", idn);
        i.set("application", application);
        i.set("identity", identity);

        String source = RuleXmlUtils.readRuleSourceFromFilePath(RULE_FILENAME);
        result = (String) i.eval(source);

        assertNotNull(result);
        assertEquals(result, "tsmith92");

        log.info("Beanshell script returned: " + result);
    }

    @Test
    public void testSamAccountNameGeneratorExist2() throws GeneralException, EvalError{
        Interpreter i = new Interpreter();

        IdnRuleUtil idn = mock();
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith91")).thenReturn(true);
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith92")).thenReturn(true);
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith93")).thenReturn(false);        

        Application application = mock(Application.class);
        when(application.getName()).thenReturn("Active Directory [source]");

        Identity identity = mock(Identity.class);
        when(identity.getFirstname()).thenReturn("Tyler");
        when(identity.getLastname()).thenReturn("Smith");
        String result = "";

        i.set("log", log);
        i.set("idn", idn);
        i.set("application", application);
        i.set("identity", identity);

        String source = RuleXmlUtils.readRuleSourceFromFilePath(RULE_FILENAME);
        result = (String) i.eval(source);

        assertNotNull(result);
        assertEquals(result, "tsmith93");

        log.info("Beanshell script returned: " + result);
    }

    @Test
    public void testSamAccountNameGeneratorExist3() throws GeneralException, EvalError{
        Interpreter i = new Interpreter();

        IdnRuleUtil idn = mock();
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith91")).thenReturn(true);
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith92")).thenReturn(true);
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith93")).thenReturn(true);    
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith94")).thenReturn(false);    

        Application application = mock(Application.class);
        when(application.getName()).thenReturn("Active Directory [source]");

        Identity identity = mock(Identity.class);
        when(identity.getFirstname()).thenReturn("Tyler");
        when(identity.getLastname()).thenReturn("Smith");
        String result = "";

        i.set("log", log);
        i.set("idn", idn);
        i.set("application", application);
        i.set("identity", identity);

        String source = RuleXmlUtils.readRuleSourceFromFilePath(RULE_FILENAME);
        result = (String) i.eval(source);

        assertNotNull(result);
        assertEquals(result, "tsmith94");

        log.info("Beanshell script returned: " + result);
    }

    @Test
    public void testSamAccountNameGeneratorExist4() throws GeneralException, EvalError{
        Interpreter i = new Interpreter();

        IdnRuleUtil idn = mock();
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith91")).thenReturn(true);
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith92")).thenReturn(true);
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith93")).thenReturn(true);    
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith94")).thenReturn(true); 
        when(idn.accountExistsByDisplayName("Active Directory [source]", "tsmith95")).thenReturn(false); 

        Application application = mock(Application.class);
        when(application.getName()).thenReturn("Active Directory [source]");

        Identity identity = mock(Identity.class);
        when(identity.getFirstname()).thenReturn("Tyler");
        when(identity.getLastname()).thenReturn("Smith");
        String result = "";

        i.set("log", log);
        i.set("idn", idn);
        i.set("application", application);
        i.set("identity", identity);

        String source = RuleXmlUtils.readRuleSourceFromFilePath(RULE_FILENAME);
        result = (String) i.eval(source);

        assertNotNull(result);
        assertEquals(result, "tsmith95");

        log.info("Beanshell script returned: " + result);
    }

}