diff --git a/MekHQ/src/mekhq/campaign/Campaign.java b/MekHQ/src/mekhq/campaign/Campaign.java index dfa601762f..4c0dea9015 100644 --- a/MekHQ/src/mekhq/campaign/Campaign.java +++ b/MekHQ/src/mekhq/campaign/Campaign.java @@ -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 children = person.getGenealogy().getChildren(); - - if ((person.getStatus().isOnMaternityLeave()) && (!children.isEmpty())) { - LocalDate lastChildBirthDate = getYoungestChildDateOfBirth(children); - - if (currentDay.isAfter(lastChildBirthDate)) { - person.changeStatus(this, getLocalDate(), PersonnelStatus.ACTIVE); - } - } - } - } } } diff --git a/MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java b/MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java index 9ef0d7b5cd..47a34dac38 100644 --- a/MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java +++ b/MekHQ/src/mekhq/campaign/personnel/procreation/AbstractProcreation.java @@ -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); + } } /** @@ -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; } diff --git a/MekHQ/unittests/mekhq/campaign/personnel/procreation/AbstractProcreationTest.java b/MekHQ/unittests/mekhq/campaign/personnel/procreation/AbstractProcreationTest.java index 7cdafedfae..879ce8d811 100644 --- a/MekHQ/unittests/mekhq/campaign/personnel/procreation/AbstractProcreationTest.java +++ b/MekHQ/unittests/mekhq/campaign/personnel/procreation/AbstractProcreationTest.java @@ -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());