Package com.gophers.services.testCases
Class ChatBotTest
java.lang.Object
com.gophers.services.testCases.ChatBotTest
Unit tests for the `ChatBot` class, focusing on verifying methods are correctly
implemented and returns expected
results
based on various input codes. Tests check method statics, expected return
values,
and handling of invalid input codes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRetrieves a method from the `ChatBot` class using reflection.voidInstantiates two ChatBot objects: one using the default constructor and the other using the overloaded constructor with an integer argument.voidResets the static field `messageNumber` in the `ChatBot` class to 0.voidsetUp()Sets up the test environment by initializing the ChatBot class, instantiating default and overloaded ChatBot instances, and preparing method references and static field resets.voidTests that the `chatBotName` field exists, is private, and is of type `String`.voidTests that the default constructor assigns the correct default name, "ChatGPT-3.5", to the `ChatBot` instance.voidTests that the default constructor initializes the `numResponsesGenerated` field to 0.voidTests that the default constructor of the `ChatBot` class creates a non-null instance.voidVerifies that the `generateResponse` method generates unique message numbers for each response.voidTests that the `generateResponse` method increments the response counters (both `numResponsesGenerated` and `totalNumResponsesGenerated`) when invoked.voidTests that the `generateResponse` method is private.voidTests that the `generateResponse` method returns a response with the correct format, including the message number and generated text.voidTests that the `generateResponse` method returns a String.voidTests that the `getChatBotName` method returns the correct names for the default and bard ChatBot instances.voidVerifies that the `getTotalNumMessagesRemaining` method is static.voidTests that the `getTotalNumMessagesRemaining` method correctly reaches zero when the message limit is reached.voidTests that the `getTotalNumMessagesRemaining` method correctly calculates the remaining messages based on the message limit and responses generated.voidVerifies that the `getTotalNumResponsesGenerated` method is static.voidTests that the `getTotalNumResponsesGenerated` method correctly returns the total number of messages generated, after multiple responses.voidVerifies that the `limitReached` method returns false initially (before the limit is reached).voidVerifies that the `limitReached` method is static.voidTests that the `limitReached` method returns true when the message limit is reached.voidTests that the `messageLimit` field has a value of 10.voidTests that the `messageLimit` field exists in the `ChatBot` class.voidTests that the `messageLimit` field is private, static, and of type `int`.voidTests that the `messageNumber` field exists, is private, and is static, with an initial value of 0.voidTests that the `messageNumber` field is private, static, and has an initial value of 0.voidTests that the `numResponsesGenerated` field is correctly initialized to 0 and increments when the bot is prompted with a message.voidTests that the `numResponsesGenerated` field exists, is private, and is of type `int`.voidTests that the overloaded constructor assigns the default name "ChatGPT-3.5" when an invalid LLM code is provided.voidTests that the overloaded constructor of the `ChatBot` class creates a non-null instance.voidTests that the overloaded constructor correctly assigns valid names based on the provided LLM code (e.g., "LLaMa", "Mistral7B", "Bard", "Solar").voidTests that the `toString` method includes the ChatBot's name as a header.
-
Constructor Details
-
ChatBotTest
public ChatBotTest()
-
-
Method Details
-
setUp
Sets up the test environment by initializing the ChatBot class, instantiating default and overloaded ChatBot instances, and preparing method references and static field resets.- Throws:
Exception- if any initialization fails.
-
resetStaticFields
public void resetStaticFields()Resets the static field `messageNumber` in the `ChatBot` class to 0. This ensures a clean state before each test is run. -
instantiateChatBots
Instantiates two ChatBot objects: one using the default constructor and the other using the overloaded constructor with an integer argument.- Throws:
Exception- if instantiation of the constructors fails.
-
getMethod
Retrieves a method from the `ChatBot` class using reflection.- Parameters:
methodName- The name of the method to retrieve.parameterTypes- The parameter types for the method (if any).- Returns:
- The method object, or null if not found.
-
testChatBotNameField
Tests that the `chatBotName` field exists, is private, and is of type `String`.- Throws:
Exception- if the field cannot be accessed.
-
testNumResponsesGeneratedField
Tests that the `numResponsesGenerated` field exists, is private, and is of type `int`.- Throws:
NoSuchFieldException- if the field is not found.
-
testMessageLimitField_Exists
Tests that the `messageLimit` field exists in the `ChatBot` class.- Throws:
Exception- if the field cannot be accessed.
-
testMessageLimitField_StaticPrivateInteger
Tests that the `messageLimit` field is private, static, and of type `int`.- Throws:
Exception- if the field cannot be accessed.
-
testMessageLimitField_EqualsTen
Tests that the `messageLimit` field has a value of 10.- Throws:
Exception- if the field cannot be accessed.
-
testMessageNumberField_Exists
Tests that the `messageNumber` field exists, is private, and is static, with an initial value of 0.- Throws:
Exception- if the field cannot be accessed.
-
testMessageNumberField_PrivateStaticEqualsZero
Tests that the `messageNumber` field is private, static, and has an initial value of 0.- Throws:
Exception- if the field cannot be accessed.
-
testDefaultConstructor_ObjectNotNull
public void testDefaultConstructor_ObjectNotNull()Tests that the default constructor of the `ChatBot` class creates a non-null instance. -
testDefaultConstructor_CorrectName
Tests that the default constructor assigns the correct default name, "ChatGPT-3.5", to the `ChatBot` instance.- Throws:
Exception- if the field cannot be accessed.
-
testDefaultConstructor_InitialResponseCount
Tests that the default constructor initializes the `numResponsesGenerated` field to 0.- Throws:
Exception- if the field cannot be accessed.
-
testOverloadedConstructor_ObjectNotNull
public void testOverloadedConstructor_ObjectNotNull()Tests that the overloaded constructor of the `ChatBot` class creates a non-null instance. -
testOverloadedConstructor_ValidLLMCodes
Tests that the overloaded constructor correctly assigns valid names based on the provided LLM code (e.g., "LLaMa", "Mistral7B", "Bard", "Solar").- Throws:
Exception- if the constructor or field cannot be accessed.
-
testOverloadedConstructor_InvalidLLMCode
Tests that the overloaded constructor assigns the default name "ChatGPT-3.5" when an invalid LLM code is provided.- Throws:
Exception- if the constructor or field cannot be accessed.
-
testGetChatBotName
Tests that the `getChatBotName` method returns the correct names for the default and bard ChatBot instances. The default bot name should be "ChatGPT-3.5" and the bard bot name should be "Bard".- Throws:
Exception- if the method invocation fails.
-
testNumResponsesGenerated
Tests that the `numResponsesGenerated` field is correctly initialized to 0 and increments when the bot is prompted with a message.- Throws:
Exception- if the method invocation fails.
-
testGetTotalNumResponsesGenerated_IsStatic
Verifies that the `getTotalNumResponsesGenerated` method is static.- Throws:
Exception- if the method cannot be accessed.
-
testGetTotalNumResponsesGenerated_ReturnsTotalMessages
Tests that the `getTotalNumResponsesGenerated` method correctly returns the total number of messages generated, after multiple responses.- Throws:
Exception- if the method invocation fails.
-
testGetTotalNumMessagesRemaining_IsStatic
Verifies that the `getTotalNumMessagesRemaining` method is static.- Throws:
Exception- if the method cannot be accessed.
-
testGetTotalNumMessagesRemaining_ReturnsCorrectValue
Tests that the `getTotalNumMessagesRemaining` method correctly calculates the remaining messages based on the message limit and responses generated.- Throws:
Exception- if the method invocation fails.
-
testGetTotalNumMessagesRemaining_ReachesZero
Tests that the `getTotalNumMessagesRemaining` method correctly reaches zero when the message limit is reached.- Throws:
Exception- if the method invocation fails.
-
testLimitReached_InitiallyFalse
Verifies that the `limitReached` method returns false initially (before the limit is reached).- Throws:
Exception- if the method invocation fails.
-
testLimitReached_TrueWhenLimitReached
Tests that the `limitReached` method returns true when the message limit is reached.- Throws:
Exception- if the method invocation fails.
-
testLimitReached_IsStatic
Verifies that the `limitReached` method is static.- Throws:
Exception- if the method invocation fails.
-
testGenerateResponse_isPrivate
Tests that the `generateResponse` method is private.- Throws:
Exception- if the method cannot be accessed.
-
testGenerateResponse_ReturnsString
Tests that the `generateResponse` method returns a String.- Throws:
Exception- if the method invocation fails.
-
testGenerateResponse_IncrementsCounters
Tests that the `generateResponse` method increments the response counters (both `numResponsesGenerated` and `totalNumResponsesGenerated`) when invoked.- Throws:
Exception- if the method invocation fails.
-
testGenerateResponse_ReturnsCorrectStringFormat
Tests that the `generateResponse` method returns a response with the correct format, including the message number and generated text.- Throws:
Exception- if the method invocation fails.
-
testGenerateResponse_ContainsUniqueMessageNumber
Verifies that the `generateResponse` method generates unique message numbers for each response.- Throws:
Exception- if the method invocation fails.
-
testToString_BotNameHeaderExists
Tests that the `toString` method includes the ChatBot's name as a header.- Throws:
Exception- if the method invocation fails.
-