Skip to content

Commit

Permalink
Fix code smells (remove public) in task tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhatminh451 committed Oct 16, 2023
1 parent b2cef1c commit d0689cc
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class DroidCombatTaskTest {
class DroidCombatTaskTest {
DroidCombatTask droidCombatTask;

@BeforeEach
Expand All @@ -35,7 +35,7 @@ void setUp() {
}

@Test
public void testStartTriggersWalkEvent() {
void testStartTriggersWalkEvent() {
Entity entity = createDroid();
EventListener0 walkListener = mock(EventListener0.class);
// Deploy Droid in the walking state
Expand All @@ -45,7 +45,7 @@ public void testStartTriggersWalkEvent() {
}

@Test
public void testUpdateTowerStateWithTargetInRange() {
void testUpdateTowerStateWithTargetInRange() {
Entity entity = createDroid();
entity.setPosition(10,10);

Expand Down Expand Up @@ -98,7 +98,7 @@ public void testUpdateTowerStateWithTargetInRange() {
}

@Test
public void testUpdateTowerStateWithTargetNotInRange() {
void testUpdateTowerStateWithTargetNotInRange() {
Entity entity = createDroid();
entity.setPosition(10, 10);

Expand All @@ -124,7 +124,6 @@ public void testUpdateTowerStateWithTargetNotInRange() {
assertEquals(DroidCombatTask.STATE.IDLE, droidCombatTask.getState());
}


Entity createDroid() {
AITaskComponent aiTaskComponent = new AITaskComponent().addTask(droidCombatTask);
Entity entity = new Entity().addComponent(aiTaskComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class PierceTowerCombatTaskTest {
class PierceTowerCombatTaskTest {
PierceTowerCombatTask pierceTowerCombatTask;

@BeforeEach
Expand All @@ -39,7 +39,7 @@ void setUp() {
* in DroidCombatTaskTest by Mohamad Dabboussi
*/
@Test
public void testStartTriggersIdleEvent() {
void testStartTriggersIdleEvent() {
Entity entity = createPierceTower();
EventListener0 idleListener = mock(EventListener0.class);
// Deploy Droid in the walking state
Expand All @@ -53,7 +53,7 @@ public void testStartTriggersIdleEvent() {
* in DroidCombatTaskTest by Mohamad Dabboussi
*/
@Test
public void testUpdateTowerStateWithTargetInRange() {
void testUpdateTowerStateWithTargetInRange() {
Entity entity = createPierceTower();
entity.setPosition(10, 10);

Expand Down Expand Up @@ -81,7 +81,7 @@ public void testUpdateTowerStateWithTargetInRange() {
* in DroidCombatTaskTest by Mohamad Dabboussi
*/
@Test
public void testUpdateTowerStateWithTargetNotInRange() {
void testUpdateTowerStateWithTargetNotInRange() {
Entity entity = createPierceTower();
entity.setPosition(10, 10);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class RicochetTowerCombatTaskTest {
class RicochetTowerCombatTaskTest {
RicochetTowerCombatTask ricochetTowerCombatTask;

@BeforeEach
Expand All @@ -39,7 +39,7 @@ void setUp() {
* in DroidCombatTaskTest by Mohamad Dabboussi
*/
@Test
public void testStartTriggersIdleEvent() {
void testStartTriggersIdleEvent() {
Entity entity = createRicochetTower();
EventListener0 idleListener = mock(EventListener0.class);
// Deploy Droid in the walking state
Expand All @@ -53,7 +53,7 @@ public void testStartTriggersIdleEvent() {
* in DroidCombatTaskTest by Mohamad Dabboussi
*/
@Test
public void testUpdateTowerStateWithTargetInRange() {
void testUpdateTowerStateWithTargetInRange() {
Entity entity = createRicochetTower();
entity.setPosition(10, 10);

Expand All @@ -80,7 +80,7 @@ public void testUpdateTowerStateWithTargetInRange() {
* in DroidCombatTaskTest by Mohamad Dabboussi
*/
@Test
public void testUpdateTowerStateWithTargetNotInRange() {
void testUpdateTowerStateWithTargetNotInRange() {
Entity entity = createRicochetTower();
entity.setPosition(10, 10);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class StunTowerCombatTaskTest {
class StunTowerCombatTaskTest {
StunTowerCombatTask stunTowerCombatTask;

@BeforeEach
Expand All @@ -39,7 +39,7 @@ void setUp() {
* in DroidCombatTaskTest by Mohamad Dabboussi
*/
@Test
public void testStartTriggersIdleEvent() {
void testStartTriggersIdleEvent() {
Entity entity = createStunTower();
EventListener0 idleListener = mock(EventListener0.class);
// Deploy Droid in the walking state
Expand All @@ -53,7 +53,7 @@ public void testStartTriggersIdleEvent() {
* in DroidCombatTaskTest by Mohamad Dabboussi
*/
@Test
public void testUpdateTowerStateWithTargetInRange() {
void testUpdateTowerStateWithTargetInRange() {
Entity entity = createStunTower();
entity.setPosition(10, 10);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
public class TNTTowerCombatTaskTest {
class TNTTowerCombatTaskTest {
TNTTowerCombatTask tntTowerCombatTask;

@BeforeEach
Expand All @@ -34,7 +34,7 @@ void setUp() {
}

@Test
public void testStartTriggersDefaultEvent() {
void testStartTriggersDefaultEvent() {
Entity entity = createTNT();

EventListener0 defaultStartListener = mock(EventListener0.class);
Expand All @@ -46,7 +46,7 @@ public void testStartTriggersDefaultEvent() {
}

@Test
public void testUpdateTowerStateWithTargetInRange() {
void testUpdateTowerStateWithTargetInRange() {
Entity entity = createTNT();
entity.setPosition(10,10);

Expand Down Expand Up @@ -89,7 +89,7 @@ public void testUpdateTowerStateWithTargetInRange() {
}

@Test
public void testStayAtIdleWhenNoTargetInRange() {
void testStayAtIdleWhenNoTargetInRange() {
Entity entity = createTNT();
entity.setPosition(10,10);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(GameExtension.class)
public class DroidAnimationControllerTest {

class DroidAnimationControllerTest {
private Entity mockEntity;
private final String[] texture = {"images/towers/DroidTower.png"};
private final String[] atlas = {"images/towers/DroidTower.atlas"};

@BeforeEach
public void setUp() {
void setUp() {
ServiceLocator.registerPhysicsService(new PhysicsService());
RenderService render = new RenderService();
render.setDebug(mock(DebugRenderer.class));
Expand All @@ -40,43 +39,43 @@ public void setUp() {
}

@Test
public void testAnimateWalk() {
void testAnimateWalk() {
mockEntity.getEvents().trigger("walkStart");
assertEquals("walk", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateDefault() {
void testAnimateDefault() {
mockEntity.getEvents().trigger("idleStart");
assertEquals("idle", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateGoUp() {
void testAnimateGoUp() {
mockEntity.getEvents().trigger("goUpStart");
assertEquals("goUp", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateGoDown() {
void testAnimateGoDown() {
mockEntity.getEvents().trigger("goDownStart");
assertEquals("goDown", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateAttackUp() {
void testAnimateAttackUp() {
mockEntity.getEvents().trigger("attackUpStart");
assertEquals("attackUp", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateAttackDown() {
void testAnimateAttackDown() {
mockEntity.getEvents().trigger("attackDownStart");
assertEquals("attackDown", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateDeath() {
void testAnimateDeath() {
mockEntity.getEvents().trigger("deathStart");
assertEquals("death", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(GameExtension.class)
public class FireTowerAnimationControllerTest {

class FireTowerAnimationControllerTest {
private Entity mockEntity;
private final String[] texture = {"images/towers/fire_tower_atlas.png"};
private final String[] atlas = {"images/towers/fire_tower_atlas.atlas"};

@BeforeEach
public void setUp() {
void setUp() {
ServiceLocator.registerPhysicsService(new PhysicsService());
RenderService render = new RenderService();
render.setDebug(mock(DebugRenderer.class));
Expand All @@ -40,25 +39,25 @@ public void setUp() {
}

@Test
public void testAnimateWalk() {
void testAnimateWalk() {
mockEntity.getEvents().trigger("startIdle");
assertEquals("idle", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateDefault() {
void testAnimateDefault() {
mockEntity.getEvents().trigger("startAttackPrep");
assertEquals("prepAttack", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateGoUp() {
void testAnimateGoUp() {
mockEntity.getEvents().trigger("startAttack");
assertEquals("attack", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateDeath() {
void testAnimateDeath() {
mockEntity.getEvents().trigger("startDeath");
assertEquals("death", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(GameExtension.class)
public class StunTowerAnimationControllerTest {

class StunTowerAnimationControllerTest {
private Entity mockEntity;
private final String[] texture = {"images/towers/stun_tower.png"};
private final String[] atlas = {"images/towers/stun_tower.atlas"};

@BeforeEach
public void setUp() {
void setUp() {
ServiceLocator.registerPhysicsService(new PhysicsService());
RenderService render = new RenderService();
render.setDebug(mock(DebugRenderer.class));
Expand All @@ -40,19 +39,19 @@ public void setUp() {
}

@Test
public void testAnimateWalk() {
void testAnimateWalk() {
mockEntity.getEvents().trigger("startIdle");
assertEquals("idle", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateDefault() {
void testAnimateDefault() {
mockEntity.getEvents().trigger("startAttack");
assertEquals("attack", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}

@Test
public void testAnimateGoUp() {
void testAnimateGoUp() {
mockEntity.getEvents().trigger("startDeath");
assertEquals("death", mockEntity.getComponent(AnimationRenderComponent.class).getCurrentAnimation());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;



@ExtendWith(GameExtension.class)
public class TNTAnimationControllerTest {

class TNTAnimationControllerTest {
private Entity mockEntity;
private final String[] texture = {"images/towers/TNTTower.png"};
private final String[] atlas = {"images/towers/TNTTower.atlas"};


@BeforeEach
public void setUp() {
void setUp() {
// Initialize the TNTAnimationController object
ServiceLocator.registerPhysicsService(new PhysicsService());
RenderService render = new RenderService();
Expand All @@ -44,7 +40,7 @@ public void setUp() {
}

@Test
public void testAnimateDig() {
void testAnimateDig() {

// Trigger the animateDig method
mockEntity.getEvents().trigger("digStart");
Expand All @@ -54,7 +50,7 @@ public void testAnimateDig() {
}

@Test
public void testAnimateDefault() {
void testAnimateDefault() {
// Trigger the animateDefault method
mockEntity.getEvents().trigger("defaultStart");

Expand All @@ -63,7 +59,7 @@ public void testAnimateDefault() {
}

@Test
public void testAnimateExplode() {
void testAnimateExplode() {
// Trigger the animateExplode method
mockEntity.getEvents().trigger("explodeStart");

Expand Down
Loading

0 comments on commit d0689cc

Please sign in to comment.