Skip to content

Commit

Permalink
Fixed test failure caused by NullPointerException present when Engine…
Browse files Browse the repository at this point in the history
…erCountDisplay is updated
  • Loading branch information
Hasakev committed Oct 16, 2023
1 parent e0701d9 commit fc92869
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ private void addActors() {
* Updates the engineer count on the UI component
*/
public void updateCount() {
int currentCount = ServiceLocator.getGameEndService().getEngineerCount();
String text = String.format("%d", currentCount);
engineerTb.getLabel().setText(text);
if (currentCount < ServiceLocator.getGameEndService().getThreshold()) {
if (engineerTb != null) { // fix for null pointer exception
int currentCount = ServiceLocator.getGameEndService().getEngineerCount();
String text = String.format("%d", currentCount);
engineerTb.getLabel().setText(text);
if (currentCount < ServiceLocator.getGameEndService().getThreshold()) {
// engineerTb.addAction(Actions.color(Color.RED, 0.5f, Interpolation.swingIn));
engineerTb.addAction(Actions.forever(new SequenceAction(Actions.fadeOut(0.5f),
Actions.fadeIn(0.5f))));
engineerTb.addAction(Actions.forever(new SequenceAction(Actions.fadeOut(0.5f),
Actions.fadeIn(0.5f))));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ public void update() {

if(mob.getCenterPosition().x <= 1) {
mob.getComponent(CombatStatsComponent.class).setHealth(0);
ServiceLocator.getGameEndService().updateEngineerCount();
}

// death check
if ((mob.getComponent(CombatStatsComponent.class).getHealth() <= 0 && !deathFlag)) {
// decrement engineer count
// ! tests failing because of textbox
// ServiceLocator.getGameEndService().updateEngineerCount();

changeState(State.DEATH);
animate();
movementTask.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.ArrayList;
import java.util.Arrays;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -57,6 +58,7 @@ public void setUp() {
ServiceLocator.registerPhysicsService(new PhysicsService());

ServiceLocator.registerEntityService(new EntityService());
ServiceLocator.registerGameEndService(new GameEndService());

RenderService render = new RenderService();
render.setDebug(mock(DebugRenderer.class));
Expand All @@ -79,8 +81,7 @@ public void setUp() {
@Test
void shouldNotBeNull() {
Entity mob = createSplitMob(5);
assertNotNull("Mobling components does not exists",
mob.getComponent(SplitMoblings.class));
Assertions.assertNotNull(mob.getComponent(SplitMoblings.class), "Mobling components does not exists");
}

@Test
Expand All @@ -94,8 +95,7 @@ void shouldHaveAsset() {
if (entity.equals(baseMob) || entity.equals(projectile))
continue;

assertTrue("moblings does not contain the right asset",
ServiceLocator.getResourceService().containsAsset(atlas[0], entity.getClass()));
Assertions.assertTrue(ServiceLocator.getResourceService().containsAsset(atlas[0], entity.getClass()), "moblings does not contain the right asset");

}
}
Expand Down

0 comments on commit fc92869

Please sign in to comment.