Skip to content

Commit

Permalink
Merge pull request #4796 from Algebro7/fix-untreated-personnel-nag-fo…
Browse files Browse the repository at this point in the history
…r-prisoners

Remove untreated personnel nag for prisoner-defectors and add unit tests
  • Loading branch information
IllianiCBT authored Sep 13, 2024
2 parents 127ec24 + f5083a8 commit 82cc25f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import javax.swing.*;

public class UntreatedPersonnelNagDialog extends AbstractMHQNagDialog {
private static boolean isUntreatedInjury (Campaign campaign) {
static boolean isUntreatedInjury(Campaign campaign) {
return campaign.getActivePersonnel().stream()
.filter(p -> (p.needsFixing()) && (p.getDoctorId() == null))
.anyMatch(p -> !p.getPrisonerStatus().isPrisoner());
.anyMatch(p -> !p.getPrisonerStatus().isCurrentPrisoner());
}

//region Constructors
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package mekhq.gui.dialog.nagDialogs;

import megamek.common.EquipmentType;
import mekhq.campaign.Campaign;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.personnel.SkillType;
import mekhq.campaign.personnel.enums.PersonnelRole;
import mekhq.campaign.personnel.enums.PersonnelStatus;
import mekhq.campaign.personnel.enums.PrisonerStatus;
import mekhq.campaign.personnel.ranks.Ranks;
import mekhq.campaign.universe.Systems;
import org.apache.logging.log4j.LogManager;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;


import static mekhq.gui.dialog.nagDialogs.UntreatedPersonnelNagDialog.isUntreatedInjury;
import static org.junit.jupiter.api.Assertions.*;

class UntreatedPersonnelNagDialogTest {
Campaign campaign;
Person person;

@BeforeAll
public static void setup() {
EquipmentType.initializeTypes();
SkillType.initializeTypes();
Ranks.initializeRankSystems();
try {
Systems.setInstance(Systems.loadDefault());
} catch (Exception ex) {
LogManager.getLogger().error("", ex);
}
}

@BeforeEach
public void init() {
campaign = new Campaign();
person = campaign.newPerson(PersonnelRole.MECHWARRIOR);
person.setHits(1);
}

@Test
public void isUntreatedInjuryIncludesNonPrisonersTest() {
person.setPrisonerStatus(campaign, PrisonerStatus.FREE, false);
campaign.importPerson(person);
assertTrue(isUntreatedInjury(campaign));
}

@Test
public void isUntreatedInjuryExcludesPrisonersTest() {
person.setPrisonerStatus(campaign, PrisonerStatus.PRISONER, false);
campaign.importPerson(person);
assertFalse(isUntreatedInjury(campaign));
}

@Test
public void isUntreatedInjuryExcludesPrisonerDefectorsTest() {
person.setPrisonerStatus(campaign, PrisonerStatus.PRISONER_DEFECTOR, false);
campaign.importPerson(person);
assertFalse(isUntreatedInjury(campaign));
}

@Test
public void isUntreatedInjuryExcludesBondsmenTest() {
person.setPrisonerStatus(campaign, PrisonerStatus.BONDSMAN, false);
campaign.importPerson(person);
assertTrue(isUntreatedInjury(campaign));
}

@Test
public void isUntreatedInjuryExcludesInactivePersonnelTest() {
person.setStatus(PersonnelStatus.AWOL);
campaign.importPerson(person);
assertFalse(isUntreatedInjury(campaign));
}
}

0 comments on commit 82cc25f

Please sign in to comment.