ActiveAnimalsManager Test - UQcsse3200/2024-studio-3 GitHub Wiki

Dependencies

  • ActiveAnimalsManager: The singleton class being tested, which manages a set of active animals in the game.
  • GameTime: A service that mimics and controls the time of the game.
  • EventListener0: To ensure that the right events are triggered, a mocked event listener is used.
  • ServiceLocator: Registers services used in the game to isolate the class being tested.
  • GameExtension, MockitoExtension: These are JUnit extensions that allow for game-specific configuration and Mockito functionality.

Implementation

  • setUp(): To guarantee test independence, the active animals set is cleaned and the singleton instance of ActiveAnimalsManager is fetched prior to each test.
  • testSingletonInstance(): This test ensures that ActiveAnimalsManager follows the singleton design pattern by asserting that two calls to getInstance() return the same instance.
  • testAddAnimal(): The test verifies that an animal (such as "Monkey") introduced to the manager shows up in the collection of active animals.
  • testRemoveAnimal(): It confirms the ability to correctly remove an animal (like "Gorilla") introduced to the active animals set.
  • testGetActiveAnimals(): The test makes sure that only the animals that have been added are returned as the correct set of active animals by the getActiveAnimals() method.