Package com.gophers.services.testCases
Class ChatBotPlatformTest
java.lang.Object
com.gophers.services.testCases.ChatBotPlatformTest
Test suite for the ChatBotPlatform class which manages a collection of
ChatBot instances.
Tests the initialization, bot management, interaction limits, and reporting
functionality.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionHelper method to get a method reference using reflection.voidResets static message counter in the ChatBot class to ensure consistent test conditions for each test case.voidsetUp()Sets up the test environment before each test.voidTests adding the first ChatBot to the platform with LLM code 1.voidTests adding a second ChatBot to the platform with LLM code 2.voidVerifies that adding a new ChatBot fails when the message limit is reached.voidVerifies that the bot count increments correctly as new bots are added.voidTests that the message limit is properly enforced across all bots.voidConfirms that the bots collection is empty when a new ChatBotPlatform instance is created.voidTests that the bots collection is properly initialized when creating a new ChatBotPlatform instance.voidVerifies that the bots collection field is declared as private to ensure proper encapsulation.voidVerifies that the bots collection is initialized as an ArrayListwhen creating a new ChatBotPlatform instance. voidTests the successful creation of a ChatBotPlatform instance.voidTests that getChatBotList output contains correct bot names.voidTests that getChatBotList output contains correct bot numbers.voidTests that getChatBotList correctly reports message count per bot.voidTests that getChatBotList correctly reports remaining available messages.voidTests that getChatBotList correctly reports total messages used across all bots.voidTests interaction with invalid out-of-range bot index.voidTests interaction with invalid negative bot index.voidTests successful interaction with a valid bot index.
-
Constructor Details
-
ChatBotPlatformTest
public ChatBotPlatformTest()
-
-
Method Details
-
setUp
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
Helper method to get a method reference using reflection.- Parameters:
methodClass- the class containing the methodmethodName- the name of the method to retrieveparameterTypes- the parameter types of the method- Returns:
- Method object or null if method not found
-
testBotsCollectionInitialized
Tests that the bots collection is properly initialized when creating a new ChatBotPlatform instance.- Throws:
NoSuchFieldException- if bots field doesn't existIllegalAccessException- if bots field cannot be accessed
-
testBotsCollectionIsPrivate
Verifies that the bots collection field is declared as private to ensure proper encapsulation.- Throws:
NoSuchFieldException- if bots field doesn't exist
-
testBotsCollectionEmptyInitially
Confirms that the bots collection is empty when a new ChatBotPlatform instance is created.- Throws:
NoSuchFieldException- if bots field doesn't existIllegalAccessException- if bots field cannot be accessed
-
testChatBotPlatformConstructor
public void testChatBotPlatformConstructor()Tests the successful creation of a ChatBotPlatform instance. -
testChatBotPlatformBotsCollectionInitialized
public void testChatBotPlatformBotsCollectionInitialized() throws NoSuchFieldException, IllegalAccessExceptionVerifies that the bots collection is initialized as an ArrayListwhen creating a new ChatBotPlatform instance. - Throws:
NoSuchFieldException- if bots field doesn't existIllegalAccessException- if bots field cannot be accessed
-
testAddChatBotAddsFirstBot
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
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
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
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
Verifies that adding a new ChatBot fails when the message limit is reached.- Throws:
Exception- if method invocation fails
-
testGetChatBotListContainsBotNumbers
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
Tests that getChatBotList output contains correct bot names. Verifies presence of "LLaMa" and "Mistral7B" in output.- Throws:
Exception- if method invocation fails
-
testGetChatBotListContainsMessageCountPerBot
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
Tests that getChatBotList correctly reports total messages used across all bots.- Throws:
Exception- if method invocation fails
-
testGetChatBotListContainsTotalMessagesRemaining
Tests that getChatBotList correctly reports remaining available messages.- Throws:
Exception- if method invocation fails
-
testInteractWithValidBot
Tests successful interaction with a valid bot index. Verifies response contains bot name and generated text.- Throws:
Exception- if method invocation fails
-
testInteractWithBotInvalidNegativeIndex
Tests interaction with invalid negative bot index. Verifies appropriate error message is returned.- Throws:
Exception- if method invocation fails
-
testInteractWithBotAfterLimitReached
Tests interaction with invalid out-of-range bot index. Verifies appropriate error message is returned.- Throws:
Exception- if method invocation fails
-