Skip to content

Commit

Permalink
Merge pull request #5725 from IllianiCBT/maternityLeave_plsWork
Browse files Browse the repository at this point in the history
Fixed Maternity Leave... yet again
  • Loading branch information
HammerGS authored Jan 15, 2025
2 parents e6715a5 + 3f0eecf commit a9ec2eb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
21 changes: 0 additions & 21 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -4291,27 +4291,6 @@ private void processWeeklyRelationshipEvents(Person person) {
getDivorce().processNewWeek(this, getLocalDate(), person, false);
getMarriage().processNewWeek(this, getLocalDate(), person, false);
getProcreation().processNewWeek(this, getLocalDate(), person);

if (person.getGender().isFemale()) {
if (campaignOptions.isUseMaternityLeave()) {
if ((person.isPregnant())
&& (person.getStatus().isActive())
&& (person.getDueDate().minusWeeks(20).isAfter(currentDay.minusDays(1)))) {

person.changeStatus(this, currentDay, PersonnelStatus.ON_MATERNITY_LEAVE);
}

List<Person> children = person.getGenealogy().getChildren();

if ((person.getStatus().isOnMaternityLeave()) && (!children.isEmpty())) {
LocalDate lastChildBirthDate = getYoungestChildDateOfBirth(children);

if (currentDay.isAfter(lastChildBirthDate)) {
person.changeStatus(this, getLocalDate(), PersonnelStatus.ACTIVE);
}
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ public void birth(final Campaign campaign, final LocalDate today, final Person m

// Cleanup Data
removePregnancy(mother);

// Return from Maternity leave
if (mother.getStatus().isOnMaternityLeave()) {
mother.changeStatus(campaign, today, PersonnelStatus.ACTIVE);
}
}

/**
Expand Down Expand Up @@ -553,7 +558,17 @@ public void processNewWeek(final Campaign campaign, final LocalDate today, final
// They give birth if the due date has passed
if ((today.isAfter(person.getDueDate())) || (today.isEqual(person.getDueDate()))) {
birth(campaign, today, person);

return;
}

if (campaign.getCampaignOptions().isUseMaternityLeave()) {
if (person.getStatus().isActive()
&& (person.getDueDate().minusWeeks(20).isAfter(today.minusDays(1)))) {
person.changeStatus(campaign, today, PersonnelStatus.ON_MATERNITY_LEAVE);
}
}

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,27 +445,47 @@ public void testProcessPregnancyComplications() {
}
//endregion Pregnancy Complications

//region New Day
//region Process New Week

@Test
public void testProcessNewWeek() {
public void testProcessNewWeek_ForNonPregnantMale() {
doCallRealMethod().when(mockProcreation).processNewWeek(any(), any(), any());
doNothing().when(mockProcreation).birth(any(), any(), any());

final Person mockPerson = mock(Person.class);

when(mockPerson.getGender()).thenReturn(Gender.MALE);
mockProcreation.processNewWeek(mockCampaign, LocalDate.ofYearDay(3025, 1), mockPerson);
verify(mockPerson, never()).isPregnant();
verify(mockProcreation, never()).randomlyProcreates(any(), any());
}

@Test
public void testProcessNewWeek_ForPregnantFemale() {
doCallRealMethod().when(mockProcreation).processNewWeek(any(), any(), any());

final Person mockPerson = mock(Person.class);

when(mockPerson.getGender()).thenReturn(Gender.FEMALE);
when(mockPerson.isPregnant()).thenReturn(true);
when(mockPerson.getDueDate()).thenReturn(LocalDate.ofYearDay(3025, 2));

mockProcreation.processNewWeek(mockCampaign, LocalDate.ofYearDay(3025, 1), mockPerson);

verify(mockProcreation, never()).birth(any(), any(), any());
verify(mockProcreation, never()).randomlyProcreates(any(), any());
}

@Test
public void testProcessNewWeek_ForPregnantFemaleWithDueDate() {
doCallRealMethod().when(mockProcreation).processNewWeek(any(), any(), any());
doNothing().when(mockProcreation).birth(any(), any(), any());

final Person mockPerson = mock(Person.class);

// Ensure proper stubbing
when(mockPerson.getGender()).thenReturn(Gender.FEMALE);
when(mockPerson.isPregnant()).thenReturn(true);
when(mockPerson.getDueDate()).thenReturn(LocalDate.ofYearDay(3025, 1));

mockProcreation.processNewWeek(mockCampaign, LocalDate.ofYearDay(3025, 1), mockPerson);
verify(mockProcreation, times(1)).birth(any(), any(), any());
verify(mockProcreation, never()).randomlyProcreates(any(), any());
Expand Down

0 comments on commit a9ec2eb

Please sign in to comment.