Skip to content

Monkey Animation Controller Tests

LJ edited this page Aug 29, 2024 · 2 revisions
 @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());
    }
Clone this wiki locally