-
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.
- Loading branch information
1 parent
c9ad35f
commit 03c0905
Showing
4 changed files
with
128 additions
and
171 deletions.
There are no files selected for viewing
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
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
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
284 changes: 118 additions & 166 deletions
284
source/core/src/test/com/csse3200/game/input/BuildInputComponentTest.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 |
---|---|---|
@@ -1,166 +1,118 @@ | ||
//package com.csse3200.game.input; | ||
// | ||
//import com.badlogic.gdx.Gdx; | ||
//import com.badlogic.gdx.Graphics; | ||
//import com.badlogic.gdx.graphics.g2d.TextureAtlas; | ||
//import com.badlogic.gdx.maps.tiled.TiledMap; | ||
//import com.badlogic.gdx.math.Vector2; | ||
//import com.csse3200.game.GdxGame; | ||
//import com.csse3200.game.components.CameraComponent; | ||
//import com.csse3200.game.currency.Currency; | ||
//import com.csse3200.game.entities.Entity; | ||
//import com.csse3200.game.entities.EntityService; | ||
//import com.csse3200.game.entities.factories.TowerFactory; | ||
//import com.csse3200.game.extensions.GameExtension; | ||
//import com.csse3200.game.physics.PhysicsService; | ||
//import com.csse3200.game.rendering.DebugRenderer; | ||
//import com.csse3200.game.rendering.RenderService; | ||
//import com.csse3200.game.services.*; | ||
//import org.junit.jupiter.api.AfterEach; | ||
//import org.junit.jupiter.api.BeforeEach; | ||
//import org.junit.jupiter.api.Test; | ||
//import org.junit.jupiter.api.extension.ExtendWith; | ||
// | ||
//import static org.junit.jupiter.api.Assertions.assertEquals; | ||
//import static org.junit.jupiter.api.Assertions.assertFalse; | ||
//import static org.mockito.Mockito.*; | ||
// | ||
//@ExtendWith(GameExtension.class) | ||
//class BuildInputComponentTest { | ||
// | ||
// private BuildInputComponent buildInputComponent; | ||
// private Entity baseTower; | ||
// private Entity weaponTower; | ||
// private Entity wallTower; | ||
// private Entity stunTower; | ||
// private Entity fireTower; | ||
// private Entity tntTower; | ||
// private Entity droidTower; | ||
// private String[] texture = { | ||
// "images/towers/turret_deployed.png", | ||
// "images/towers/turret01.png", | ||
// "images/towers/wall_tower.png", | ||
// "images/towers/fire_tower_atlas.png", | ||
// "images/towers/stun_tower.png", | ||
// "images/towers/DroidTower.png", | ||
// "images/towers/TNTTower.png" | ||
// }; | ||
// private String[] atlas = { | ||
// "images/towers/turret01.atlas", | ||
// "images/towers/stun_tower.atlas", | ||
// "images/towers/fire_tower_atlas.atlas", | ||
// "images/towers/DroidTower.atlas", | ||
// "images/towers/TNTTower.atlas", | ||
// "images/towers/barrier.atlas" | ||
// }; | ||
// private static final String[] sounds = { | ||
// "sounds/towers/gun_shot_trimmed.mp3", | ||
// "sounds/towers/deploy.mp3", | ||
// "sounds/towers/stow.mp3" | ||
// }; | ||
// | ||
// @BeforeEach | ||
// void setup() { | ||
// Gdx.graphics = mock(Graphics.class); | ||
// when(Gdx.graphics.getDeltaTime()).thenReturn(10f); | ||
// | ||
// GameTime gameTime = mock(GameTime.class); | ||
// CameraComponent camera = mock(CameraComponent.class); | ||
// when(gameTime.getDeltaTime()).thenReturn(0.02f); | ||
// ServiceLocator.registerTimeSource(gameTime); | ||
// ServiceLocator.registerPhysicsService(new PhysicsService()); | ||
// RenderService render = new RenderService(); | ||
// render.setDebug(mock(DebugRenderer.class)); | ||
// ServiceLocator.registerRenderService(render); | ||
// | ||
// CurrencyService currencyService = new CurrencyService(); | ||
// ResourceService resourceService = new ResourceService(); | ||
// MapService mapService = mock(MapService.class); | ||
// when(mapService.getComponent().tileToWorldPosition(0,0)).thenReturn(new Vector2(0,0)); | ||
// EntityService entityService = new EntityService(); | ||
// | ||
// ServiceLocator.registerResourceService(resourceService); | ||
// ServiceLocator.registerCurrencyService(currencyService); | ||
// ServiceLocator.registerMapService(mapService); | ||
// ServiceLocator.registerEntityService(entityService); | ||
// | ||
// resourceService.loadTextures(texture); | ||
// resourceService.loadTextureAtlases(atlas); | ||
// resourceService.loadSounds(sounds); | ||
// resourceService.loadAll(); | ||
// | ||
// ServiceLocator.getResourceService() | ||
// .getAsset("images/towers/turret01.atlas", TextureAtlas.class); | ||
// baseTower = TowerFactory.createBaseTower(); | ||
// weaponTower = TowerFactory.createWeaponTower(); | ||
// wallTower = TowerFactory.createWallTower(); | ||
// fireTower = TowerFactory.createFireTower(); | ||
// stunTower = TowerFactory.createFireTower(); | ||
// tntTower = TowerFactory.createTNTTower(); | ||
// droidTower = TowerFactory.createDroidTower(); | ||
// | ||
// buildInputComponent = new BuildInputComponent(camera.getCamera()); | ||
// } | ||
// | ||
// @Test | ||
// void shouldUpdatePriority() { | ||
// int newPriority = 100; | ||
// InputComponent inputComponent = spy(InputComponent.class); | ||
// | ||
// inputComponent.setPriority(newPriority); | ||
// verify(inputComponent).setPriority(newPriority); | ||
// | ||
// int priority = inputComponent.getPriority(); | ||
// verify(inputComponent).getPriority(); | ||
// | ||
// assertEquals(newPriority, priority); | ||
// } | ||
// | ||
// @Test | ||
// void shouldRegisterOnCreate() { | ||
// InputService inputService = spy(InputService.class); | ||
// ServiceLocator.registerInputService(inputService); | ||
// | ||
// InputComponent inputComponent = spy(InputComponent.class); | ||
// inputComponent.create(); | ||
// verify(inputService).register(inputComponent); | ||
// } | ||
// | ||
// @Test | ||
// void shouldHandleTouchDown() { | ||
// BuildInputComponent inputComponent = spy(BuildInputComponent.class); | ||
// assertFalse(inputComponent.touchDown( 5, 6, 7, 8)); | ||
// } | ||
// | ||
// @Test | ||
// void shouldRejectOccupiedTile() { | ||
// Vector2 tile = ServiceLocator.getMapService().getComponent().tileToWorldPosition(0, 0); | ||
// tntTower.setPosition(0,0); | ||
// assertFalse(buildInputComponent.touchDown(0,0, 7,8)); | ||
// } | ||
// | ||
// @Test | ||
// void shouldRejectInvalidTile() { | ||
// | ||
// } | ||
// | ||
// @Test | ||
// void shouldHandleMissingMapService() { | ||
// | ||
// } | ||
// | ||
// @Test | ||
// void shouldHandleMissingCurrencyService() { | ||
// | ||
// } | ||
// | ||
// @Test | ||
// void shouldHandleInvalidTower() { | ||
// | ||
// } | ||
// | ||
// @Test | ||
// void shouldHandleMissingEntityService() { | ||
// | ||
// } | ||
//} | ||
package com.csse3200.game.input; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.Graphics; | ||
import com.badlogic.gdx.graphics.Camera; | ||
import com.badlogic.gdx.graphics.g2d.TextureAtlas; | ||
import com.badlogic.gdx.math.Vector2; | ||
import com.csse3200.game.areas.terrain.TerrainComponent; | ||
import com.csse3200.game.components.CameraComponent; | ||
import com.csse3200.game.entities.Entity; | ||
import com.csse3200.game.entities.EntityService; | ||
import com.csse3200.game.entities.factories.TowerFactory; | ||
import com.csse3200.game.extensions.GameExtension; | ||
import com.csse3200.game.physics.PhysicsService; | ||
import com.csse3200.game.rendering.DebugRenderer; | ||
import com.csse3200.game.rendering.RenderService; | ||
import com.csse3200.game.services.*; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(GameExtension.class) | ||
class BuildInputComponentTest { | ||
|
||
private BuildInputComponent buildInputComponent; | ||
EntityService entityService; | ||
|
||
@BeforeEach | ||
void setup() { | ||
Gdx.graphics = mock(Graphics.class); | ||
when(Gdx.graphics.getDeltaTime()).thenReturn(10f); | ||
|
||
GameTime gameTime = mock(GameTime.class); | ||
CameraComponent camera = mock(CameraComponent.class); | ||
when(camera.getCamera()).thenReturn(mock(Camera.class)); | ||
when(gameTime.getDeltaTime()).thenReturn(0.02f); | ||
ServiceLocator.registerTimeSource(gameTime); | ||
ServiceLocator.registerPhysicsService(new PhysicsService()); | ||
RenderService render = new RenderService(); | ||
render.setDebug(mock(DebugRenderer.class)); | ||
ServiceLocator.registerRenderService(render); | ||
|
||
CurrencyService currencyService = new CurrencyService(); | ||
ResourceService resourceService = new ResourceService(); | ||
MapService mapService = mock(MapService.class); | ||
when(mapService.getComponent()).thenReturn(mock(TerrainComponent.class)); | ||
entityService = mock(EntityService.class); | ||
|
||
ServiceLocator.registerResourceService(resourceService); | ||
ServiceLocator.registerCurrencyService(currencyService); | ||
ServiceLocator.registerMapService(mapService); | ||
ServiceLocator.registerEntityService(entityService); | ||
|
||
buildInputComponent = new BuildInputComponent(camera.getCamera()); | ||
} | ||
|
||
@Test | ||
void shouldUpdatePriority() { | ||
int newPriority = 100; | ||
InputComponent inputComponent = spy(InputComponent.class); | ||
|
||
inputComponent.setPriority(newPriority); | ||
verify(inputComponent).setPriority(newPriority); | ||
|
||
int priority = inputComponent.getPriority(); | ||
verify(inputComponent).getPriority(); | ||
|
||
assertEquals(newPriority, priority); | ||
} | ||
|
||
@Test | ||
void shouldRegisterOnCreate() { | ||
InputService inputService = spy(InputService.class); | ||
ServiceLocator.registerInputService(inputService); | ||
|
||
InputComponent inputComponent = spy(InputComponent.class); | ||
inputComponent.create(); | ||
verify(inputService).register(inputComponent); | ||
} | ||
|
||
@Test | ||
void shouldHandleTouchDown() { | ||
when(entityService.entitiesInTile(5, 5)).thenReturn(false); | ||
assert(buildInputComponent.touchDown( 5, 5, 7, 8)); | ||
} | ||
|
||
@Test | ||
void shouldRejectOccupiedOrInvalidTile() { | ||
// entitiesInTile checks for out of bounds condition as well | ||
when(entityService.entitiesInTile(5, 5)).thenReturn(true); | ||
assertFalse(buildInputComponent.touchDown(5,5, 7,8), | ||
"Attempting to build on an existing tower should return False"); | ||
} | ||
|
||
@Test | ||
void shouldHandleMissingMapService() { | ||
|
||
} | ||
|
||
@Test | ||
void shouldHandleMissingCurrencyService() { | ||
|
||
} | ||
|
||
@Test | ||
void shouldHandleInvalidTower() { | ||
|
||
} | ||
|
||
@Test | ||
void shouldHandleMissingEntityService() { | ||
|
||
} | ||
} |