Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Maternity Leave... yet again #5725

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -393,6 +393,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 @@ -556,7 +561,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
Loading