Class ChatBotPlatformTest

java.lang.Object
com.gophers.services.testCases.ChatBotPlatformTest

public class ChatBotPlatformTest extends Object
Test suite for the ChatBotPlatform class which manages a collection of ChatBot instances. Tests the initialization, bot management, interaction limits, and reporting functionality.
  • Constructor Details

    • ChatBotPlatformTest

      public ChatBotPlatformTest()
  • Method Details

    • setUp

      public void setUp() throws Exception
      Sets up the test environment before each test. Initializes the ChatBot and ChatBotPlatform classes through reflection, creates a new platform instance, and resets any static fields.
      Throws:
      Exception - if initialization fails
    • resetStaticFields

      public void resetStaticFields()
      Resets static message counter in the ChatBot class to ensure consistent test conditions for each test case.
    • getMethod

      public Method getMethod(Class<?> methodClass, String methodName, Class<?>... parameterTypes)
      Helper method to get a method reference using reflection.
      Parameters:
      methodClass - the class containing the method
      methodName - the name of the method to retrieve
      parameterTypes - the parameter types of the method
      Returns:
      Method object or null if method not found
    • testBotsCollectionInitialized

      public void testBotsCollectionInitialized() throws NoSuchFieldException, IllegalAccessException
      Tests that the bots collection is properly initialized when creating a new ChatBotPlatform instance.
      Throws:
      NoSuchFieldException - if bots field doesn't exist
      IllegalAccessException - if bots field cannot be accessed
    • testBotsCollectionIsPrivate

      public void testBotsCollectionIsPrivate() throws NoSuchFieldException
      Verifies that the bots collection field is declared as private to ensure proper encapsulation.
      Throws:
      NoSuchFieldException - if bots field doesn't exist
    • testBotsCollectionEmptyInitially

      public void testBotsCollectionEmptyInitially() throws NoSuchFieldException, IllegalAccessException
      Confirms that the bots collection is empty when a new ChatBotPlatform instance is created.
      Throws:
      NoSuchFieldException - if bots field doesn't exist
      IllegalAccessException - if bots field cannot be accessed
    • testChatBotPlatformConstructor

      public void testChatBotPlatformConstructor()
      Tests the successful creation of a ChatBotPlatform instance.
    • testChatBotPlatformBotsCollectionInitialized

      public void testChatBotPlatformBotsCollectionInitialized() throws NoSuchFieldException, IllegalAccessException
      Verifies that the bots collection is initialized as an ArrayList when creating a new ChatBotPlatform instance.
      Throws:
      NoSuchFieldException - if bots field doesn't exist
      IllegalAccessException - if bots field cannot be accessed
    • testAddChatBotAddsFirstBot

      public void testAddChatBotAddsFirstBot() throws Exception
      Tests adding the first ChatBot to the platform with LLM code 1. Verifies both successful addition and correct bot name (LLaMa).
      Throws:
      Exception - if method invocation fails
    • testAddChatBotAddsSecondBot

      public void testAddChatBotAddsSecondBot() throws Exception
      Tests adding a second ChatBot to the platform with LLM code 2. Verifies both successful addition and correct bot name (Mistral7B).
      Throws:
      Exception - if method invocation fails
    • testAddChatBotIncrementsBotCount

      public void testAddChatBotIncrementsBotCount() throws Exception
      Verifies that the bot count increments correctly as new bots are added. Tests adding up to three bots and checks collection size after each addition.
      Throws:
      Exception - if method invocation fails
    • testAddChatBotReachesLimit

      public void testAddChatBotReachesLimit() throws Exception
      Tests that the message limit is properly enforced across all bots. Adds bots and sends messages until the limit is reached.
      Throws:
      Exception - if method invocation fails
    • testAddChatBotAfterLimitReached

      public void testAddChatBotAfterLimitReached() throws Exception
      Verifies that adding a new ChatBot fails when the message limit is reached.
      Throws:
      Exception - if method invocation fails
    • testGetChatBotListContainsBotNumbers

      public void testGetChatBotListContainsBotNumbers() throws Exception
      Tests that getChatBotList output contains correct bot numbers. Verifies presence of "Bot Number: 0" and "Bot Number: 1" in output.
      Throws:
      Exception - if method invocation fails
    • testGetChatBotListContainsBotNames

      public void testGetChatBotListContainsBotNames() throws Exception
      Tests that getChatBotList output contains correct bot names. Verifies presence of "LLaMa" and "Mistral7B" in output.
      Throws:
      Exception - if method invocation fails
    • testGetChatBotListContainsMessageCountPerBot

      public void testGetChatBotListContainsMessageCountPerBot() throws Exception
      Tests that getChatBotList correctly reports message count per bot. Verifies message counts after sending different numbers of messages to different bots.
      Throws:
      Exception - if method invocation fails
    • testGetChatBotListContainsTotalMessagesUsed

      public void testGetChatBotListContainsTotalMessagesUsed() throws Exception
      Tests that getChatBotList correctly reports total messages used across all bots.
      Throws:
      Exception - if method invocation fails
    • testGetChatBotListContainsTotalMessagesRemaining

      public void testGetChatBotListContainsTotalMessagesRemaining() throws Exception
      Tests that getChatBotList correctly reports remaining available messages.
      Throws:
      Exception - if method invocation fails
    • testInteractWithValidBot

      public void testInteractWithValidBot() throws Exception
      Tests successful interaction with a valid bot index. Verifies response contains bot name and generated text.
      Throws:
      Exception - if method invocation fails
    • testInteractWithBotInvalidNegativeIndex

      public void testInteractWithBotInvalidNegativeIndex() throws Exception
      Tests interaction with invalid negative bot index. Verifies appropriate error message is returned.
      Throws:
      Exception - if method invocation fails
    • testInteractWithBotAfterLimitReached

      public void testInteractWithBotAfterLimitReached() throws Exception
      Tests interaction with invalid out-of-range bot index. Verifies appropriate error message is returned.
      Throws:
      Exception - if method invocation fails