-
Notifications
You must be signed in to change notification settings - Fork 1
Enemy Factory Test
LJ edited this page Aug 29, 2024
·
1 revision
class EnemyFactoryTest {
private Entity chicken;
private Entity frog;
private Entity monkey;
private static final NPCConfigs configs =
FileLoader.readClass(NPCConfigs.class, "configs/NPCs.json");
private String[] textures = {
"images/chicken.png",
"images/monkey.png",
"images/frog.png",
};
private String[] atlas = {
"images/chicken.atlas",
"images/monkey.atlas",
"images/frog.atlas"
};
@BeforeEach
void setup() {
GameTime gameTime = mock(GameTime.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);
ResourceService resourceService = new ResourceService();
ServiceLocator.registerResourceService(resourceService);
resourceService.loadTextures(textures);
resourceService.loadTextureAtlases(atlas);
resourceService.loadAll();
Entity player = new Entity();
chicken = EnemyFactory.createChicken(player);
frog = EnemyFactory.createFrog(player);
monkey = EnemyFactory.createMonkey(player);
}
/**
* Tests Creation of a monkey.
*/
@Test
void TestMonkeyCreation() {
assertNotNull(monkey, "monkey should not be null.");
}
/**
* Tests that the monkey is an Entity.
*/
@Test
void TestMonkeyIsEntity() {
assertEquals(monkey.getClass(), Entity.class);
}
/**
* Tests that the monkey has the correct components physics component.
*/
@Test
void TestMonkeyHasComponents() {
assertNotNull(monkey.getComponent(PhysicsComponent.class));
assertNotNull(monkey.getComponent(PhysicsMovementComponent.class));
assertNotNull(monkey.getComponent(MonkeyAnimationController.class));
assertNotNull(monkey.getComponent(CombatStatsComponent.class));
assertNotNull(monkey.getComponent(HitboxComponent.class));
assertNotNull(monkey.getComponent(ColliderComponent.class));
}
/**
* Tests that the monkey has the correct stats.
*/
@Test
void TestMonkeyStats() {
assertEquals(1, monkey.getComponent(CombatStatsComponent.class).getHealth(),
"Cow should have 1 HP.");
assertEquals(0,
monkey.getComponent(CombatStatsComponent.class).getSpeed(),
"monkey should have 0 Base Attack.");
}
/**
* Tests that the monkey has correct animations.
*/
@Test
void TestMonkeyAnimation() {
assertTrue(monkey.getComponent(AnimationRenderComponent.class).hasAnimation("run_down") ,
"Monkey should have run down animation.");
assertTrue(monkey.getComponent(AnimationRenderComponent.class).hasAnimation("run_up") ,
"Monkey should have run up animation.");
assertTrue(monkey.getComponent(AnimationRenderComponent.class).hasAnimation("run_right") ,
"Monkey should have run right animation.");
assertTrue(monkey.getComponent(AnimationRenderComponent.class).hasAnimation("run_down") ,
"Cow should have idle animation.");
assertTrue(monkey.getComponent(AnimationRenderComponent.class).hasAnimation("run_right_down") ,
"Monkey should have run right down animation.");
assertTrue(monkey.getComponent(AnimationRenderComponent.class).hasAnimation("run_left_down") ,
"Monkey should have run left down animation.");
assertTrue(monkey.getComponent(AnimationRenderComponent.class).hasAnimation("run_right_up") ,
"Monkey should have run right up animation.");
assertTrue(monkey.getComponent(AnimationRenderComponent.class).hasAnimation("run_left_up") ,
"Monkey should have run left up animation.");
}
/**
* Tests that the monkey is in the correct spot when placed.
*/
@Test
void TestMonkeySetPosition() {
Vector2 pos = new Vector2(0f, 0f);
monkey.setPosition(pos);
assertEquals(pos, monkey.getPosition());
}
/**
* Tests Creation of a chicken.
*/
@Test
void TestChickenCreation() {
assertNotNull(chicken, "Chicken should not be null.");
}
/**
* Tests that the chicken is an Entity.
*/
@Test
void TestChickenIsEntity() {
assertEquals(chicken.getClass(), Entity.class);
}
/**
* Tests that the chicken has the correct components.
*/
@Test
void TestChickenHasComponents() {
assertNotNull(chicken.getComponent(PhysicsComponent.class));
assertNotNull(chicken.getComponent(PhysicsMovementComponent.class));
assertNotNull(chicken.getComponent(ChickenAnimationController.class));
assertNotNull(chicken.getComponent(CombatStatsComponent.class));
assertNotNull(chicken.getComponent(HitboxComponent.class));
assertNotNull(chicken.getComponent(ColliderComponent.class));
}
/**
* Tests that the chicken has the correct stats.
*/
@Test
void TestChickenStats() {
assertEquals(1, chicken.getComponent(CombatStatsComponent.class).getHealth(),
"chicken should have 1 HP.");
assertEquals(0,
chicken.getComponent(CombatStatsComponent.class).getSpeed(),
"chicken should have 0 speed.");
}
/**
* Tests that the chicken has correct animations.
*/
@Test
void TestChickenAnimation() {
assertTrue(chicken.getComponent(AnimationRenderComponent.class).hasAnimation("walk") ,
"Chicken should have walk animation.");
assertTrue(chicken.getComponent(AnimationRenderComponent.class).hasAnimation("spawn") ,
"Chicken should have spawn animation.");
}
/**
* Tests that the chicken is in the correct spot when placed.
*/
@Test
void TestChickenSetPosition() {
Vector2 pos = new Vector2(0f, 0f);
chicken.setPosition(pos);
assertEquals(pos, chicken.getPosition());
}
/**
* Tests Creation of a frog.
*/
@Test
void TestFrogCreation() {
assertNotNull(frog, "Frog should not be null.");
}
/**
* Tests that the frog is an Entity.
*/
@Test
void TestFrogIsEntity() {
assertEquals(frog.getClass(), Entity.class);
}
/**
* Tests that the frog has the correct components.
*/
@Test
void TestFrogHasComponents() {
assertNotNull(frog.getComponent(PhysicsComponent.class));
assertNotNull(frog.getComponent(PhysicsMovementComponent.class));
assertNotNull(frog.getComponent(FrogAnimationController.class));
assertNotNull(frog.getComponent(CombatStatsComponent.class));
assertNotNull(frog.getComponent(HitboxComponent.class));
assertNotNull(frog.getComponent(ColliderComponent.class));
}
/**
* Tests that the frog has the correct stats.
*/
@Test
void TestFrogStats() {
assertEquals(1, frog.getComponent(CombatStatsComponent.class).getHealth(),
"frog should have 1 HP.");
assertEquals(0 ,
(frog.getComponent(CombatStatsComponent.class).getSpeed()),
"frog should have 0 speed.");
}
/**
* Tests that the Frog has correct animations.
*/
@Test
void TestFrogAnimation() {
assertTrue(frog.getComponent(AnimationRenderComponent.class).hasAnimation("float") ,
"Frog should have wander float animation.");
assertTrue(frog.getComponent(AnimationRenderComponent.class).hasAnimation("angry_float") ,
"Frog should have wander angry_float animation.");
}
/**
* Tests that the frog is in the correct spot when placed.
*/
@Test
void TestFrogSetPosition() {
Vector2 pos = new Vector2(0f, 0f);
frog.setPosition(pos);
assertEquals(pos, frog.getPosition());
}
static class TestComponent1 extends Component {}
}