QuestManagerTests - UQcsse3200/2024-studio-2 GitHub Wiki

This plan outlines the tests conducted to ensure the correct functionality of the QuestManager, including adding, retrieving, progressing, completing, and failing quests. More information regarding QuestManager can be found in Quests Wiki.

Testing Plan

Initialisation

The setUp() method configures the mock objects for testing. Using @BeforeEach, it ensures that mocks like the EventHandler, ResourceService, and Entity (representing the player) are set up before each test. A mock Sound is returned for quest completion sounds, and the player's event handling is simulated. The ServiceLocator registers the resourceService, and the QuestManager is initialized with the player mock.

  void setUp() {
      eventHandler = mock(EventHandler.class);
      ResourceService resourceService = mock(ResourceService.class);
      player = mock(Entity.class);

      Sound mockSound = mock(Sound.class);

      when(resourceService.getAsset("sounds/QuestComplete.wav", Sound.class)).thenReturn(mockSound);


      when(player.getEvents()).thenReturn(eventHandler);
      ServiceLocator.registerResourceService(resourceService);

      questManager = new QuestManager(player);
  }

Quest and Task Setup

A Task is created with basic parameters like its name, description, and completion criteria. This task is added to a new Quest object, which is then passed to the QuestManager. The quest can be saved using the SaveHandler, ensuring the system can use quest data during testing.


Quest quest = new Quest("Test Quest",  "Description", List.of(task),  false, null, null, true, false, 0, new String[] {});

questManager.addQuest(quest);

SaveHandler.save(GameState.class, "test/saves/quests", FileLoader.Location.LOCAL);

Tests

  • AddQuest(): Verifies that a new quest can be added to the QuestManager and retrieved correctly.
  • GetAllQuests(): Checks that all added given quests are returned when retrieving the list of all quests.
  • HandleProgressQuest(): Tests that progressing a specific quest's task results in the quest properly being marked as complete.
  • HandleQuestCompletion(): Ensures that specified events are triggered when a quest is completed.
  • HandleFailQuest(): Verifies that failing a quest updates its state to "failed", which is used to halt any further progression.
  • HandleNoQuestForProgression(): Confirms that no events are triggered when attempting to progress a non-existent quest.
  • TestFinishingMultipleTasks(): Tests that multiple tasks within a quest can be progressed and completed in the correct order.
  • HandleInvalidQuestProgression(): Ensures there is no invalid quest progression.
  • shouldSaveLoadQuestProgression(): Tests that quest progression can be saved and loaded correctly.