-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented junit tests for PauseMenuFactory and PauseMenuTimeStopCom…
…ponent.
- Loading branch information
1 parent
bf377e4
commit c58dc5c
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
.../core/src/test/com/csse3200/game/components/pausemenu/PauseMenuTimeStopComponentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.csse3200.game.components.pausemenu; | ||
|
||
import com.csse3200.game.entities.Entity; | ||
import com.csse3200.game.entities.EntityService; | ||
import com.csse3200.game.extensions.GameExtension; | ||
import com.csse3200.game.services.ServiceLocator; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(GameExtension.class) | ||
public class PauseMenuTimeStopComponentTest { | ||
Entity pauseMenu; | ||
Entity entity; | ||
@BeforeEach | ||
void beforeEach() { | ||
EntityService entityService = new EntityService(); | ||
ServiceLocator.registerEntityService(entityService); | ||
entity = mock(Entity.class); | ||
when(entity.getId()).thenReturn(-1); //Ensure it does not coincide with the pause menu's ID | ||
entityService.register(entity); | ||
PauseMenuTimeStopComponent timeStopComponent = new PauseMenuTimeStopComponent(); | ||
pauseMenu = new Entity(); | ||
pauseMenu.addComponent(timeStopComponent); | ||
} | ||
|
||
@Test | ||
void pausesEntities() { | ||
ServiceLocator.getEntityService().register(pauseMenu); | ||
verify(entity).setEnabled(false); | ||
} | ||
|
||
@Test | ||
void unpausesEntitiesWhenDisposed() { | ||
ServiceLocator.getEntityService().register(pauseMenu); | ||
pauseMenu.dispose(); | ||
verify(entity).setEnabled(true); | ||
} | ||
|
||
@Test | ||
void doesNotPauseNewEntities() { | ||
ServiceLocator.getEntityService().register(pauseMenu); | ||
Entity lateEntity = mock(Entity.class); | ||
when(entity.getId()).thenReturn(-1); //Ensure it does not coincide with the pause menu's ID | ||
ServiceLocator.getEntityService().register(lateEntity); | ||
verify(lateEntity, times(0)).setEnabled(false); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
source/core/src/test/com/csse3200/game/entities/factories/PauseMenuFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.csse3200.game.entities.factories; | ||
|
||
import com.badlogic.gdx.scenes.scene2d.Stage; | ||
import com.csse3200.game.GdxGame; | ||
import com.csse3200.game.components.pausemenu.*; | ||
import com.csse3200.game.entities.Entity; | ||
import com.csse3200.game.entities.EntityService; | ||
import com.csse3200.game.extensions.GameExtension; | ||
import com.csse3200.game.rendering.RenderService; | ||
import com.csse3200.game.rendering.TextureRenderComponent; | ||
import com.csse3200.game.services.ResourceService; | ||
import com.csse3200.game.services.ServiceLocator; | ||
import org.junit.jupiter.api.*; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
|
||
@ExtendWith(GameExtension.class) | ||
public class PauseMenuFactoryTest { | ||
Entity entity; | ||
GdxGame game; | ||
|
||
String[] texture = { | ||
"images/ui/Sprites/UI_Glass_Toggle_Bar_01a.png" | ||
}; | ||
@BeforeEach | ||
void beforeEach() { | ||
EntityService entityService = new EntityService(); | ||
ServiceLocator.registerEntityService(entityService); | ||
RenderService renderService = mock(RenderService.class); | ||
when(renderService.getStage()).thenReturn(mock(Stage.class)); | ||
ServiceLocator.registerRenderService(renderService); | ||
ResourceService resourceService = new ResourceService(); | ||
ServiceLocator.registerResourceService(resourceService); | ||
resourceService.loadTextures(texture); | ||
resourceService.loadAll(); | ||
|
||
game = mock(GdxGame.class); | ||
entity = PauseMenuFactory.createPauseMenu(game); | ||
} | ||
|
||
@Test | ||
void createsEntity() { | ||
assertNotNull(entity); | ||
} | ||
|
||
@Test | ||
void entityHasRequiredComponents() { | ||
assertNotNull(entity.getComponent(PauseMenuTimeStopComponent.class)); | ||
assertNotNull(entity.getComponent(PauseMenuContinueButton.class)); | ||
assertNotNull(entity.getComponent(PauseMenuSettingsButton.class)); | ||
assertNotNull(entity.getComponent(PauseMenuPlanetSelectButton.class)); | ||
assertNotNull(entity.getComponent(PauseMenuMainMenuButton.class)); | ||
assertNotNull(entity.getComponent(TextureRenderComponent.class)); | ||
} | ||
|
||
@Test | ||
void duplicateNotCreated() { | ||
Entity secondEntity = PauseMenuFactory.createPauseMenu(game); | ||
assertNull(secondEntity); | ||
} | ||
|
||
@Test | ||
void createsSecondEntityAfterFirstIsDisposed() { | ||
entity.dispose(); | ||
Entity secondEntity = PauseMenuFactory.createPauseMenu(game); | ||
assertNotNull(secondEntity); | ||
} | ||
} |