From 64570a44f7d1b40ff2cbb3bab8dc41d58f92063e Mon Sep 17 00:00:00 2001 From: Richard J Hancock Date: Sun, 6 Apr 2025 15:03:01 -0500 Subject: [PATCH 1/3] No Clone Method fixes. Pulled out 2 inner classes --- .../universe/RATGeneratorConnector.java | 61 +++++++++--------- .../universe/UnitGeneratorParameters.java | 62 ++++++++++--------- 2 files changed, 62 insertions(+), 61 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/universe/RATGeneratorConnector.java b/MekHQ/src/mekhq/campaign/universe/RATGeneratorConnector.java index ef271be2047..42f3c81c962 100644 --- a/MekHQ/src/mekhq/campaign/universe/RATGeneratorConnector.java +++ b/MekHQ/src/mekhq/campaign/universe/RATGeneratorConnector.java @@ -38,6 +38,7 @@ import megamek.client.ratgenerator.FactionRecord; import megamek.client.ratgenerator.MissionRole; import megamek.client.ratgenerator.ModelRecord; +import megamek.client.ratgenerator.Parameters; import megamek.client.ratgenerator.RATGenerator; import megamek.client.ratgenerator.UnitTable; import megamek.common.EntityMovementMode; @@ -47,8 +48,7 @@ import megamek.logging.MMLogger; /** - * Provides access to RATGenerator through the AbstractUnitGenerator and thus - * the IUnitGenerator interface. + * Provides access to RATGenerator through the AbstractUnitGenerator and thus the IUnitGenerator interface. * * @author Neoancient */ @@ -70,9 +70,8 @@ public RATGeneratorConnector(final int year) { } private @Nullable UnitTable findTable(final String faction, final int unitType, final int weightClass, - final int year, final int quality, - final Collection movementModes, - final Collection missionRoles) { + final int year, final int quality, final Collection movementModes, + final Collection missionRoles) { final FactionRecord factionRecord = Factions.getInstance().getFactionRecordOrFallback(faction); if (factionRecord == null) { return null; @@ -82,17 +81,25 @@ public RATGeneratorConnector(final int year) { if (weightClass >= 0) { weightClasses.add(weightClass); } - return UnitTable.findTable(factionRecord, unitType, year, rating, weightClasses, ModelRecord.NETWORK_NONE, - movementModes, missionRoles, 2, factionRecord); + return UnitTable.findTable(factionRecord, + unitType, + year, + rating, + weightClasses, + ModelRecord.NETWORK_NONE, + movementModes, + missionRoles, + 2, + factionRecord); } /** - * Helper function that extracts the string-based unit rating from the given - * int-based unit-rating - * for the given faction. + * Helper function that extracts the string-based unit rating from the given int-based unit-rating for the given + * faction. * * @param factionRecord Faction record * @param quality Unit quality number + * * @return Unit quality string */ public static String getFactionSpecificRating(final FactionRecord factionRecord, final int quality) { @@ -116,29 +123,23 @@ public boolean isSupportedUnitType(final int unitType) { @Override public @Nullable MekSummary generate(final String faction, final int unitType, final int weightClass, - final int year, final int quality, - final Collection movementModes, - final Collection missionRoles, - @Nullable Predicate filter) { + final int year, final int quality, final Collection movementModes, + final Collection missionRoles, @Nullable Predicate filter) { final UnitTable table = findTable(faction, unitType, weightClass, year, quality, movementModes, missionRoles); return (table == null) ? null : table.generateUnit((filter == null) ? null : filter::test); } @Override public List generate(final int count, final String faction, final int unitType, final int weightClass, - final int year, final int quality, - final Collection movementModes, - final Collection missionRoles, - @Nullable Predicate filter) { + final int year, final int quality, final Collection movementModes, + final Collection missionRoles, @Nullable Predicate filter) { final UnitTable table = findTable(faction, unitType, weightClass, year, quality, movementModes, missionRoles); return (table == null) ? new ArrayList<>() : table.generateUnits(count, (filter == null) ? null : filter::test); } /** - * Generates a list of mek summaries from a RAT determined by the given faction, - * quality and other parameters. - * We force a fallback to try to ensure that something is generated if the - * parents have any possible units to generate, + * Generates a list of mek summaries from a RAT determined by the given faction, quality and other parameters. We + * force a fallback to try to ensure that something is generated if the parents have any possible units to generate, * as that is the normally expected behaviour for MekHQ OpFor generation. * * @param count How many units to generate @@ -148,15 +149,13 @@ public List generate(final int count, final String faction, final in public List generate(final int count, final UnitGeneratorParameters parameters) { final UnitTable table = findOpForTable(parameters); return table.generateUnits(count, - (parameters.getFilter() == null) ? null : ms -> parameters.getFilter().test(ms)); + (parameters.getFilter() == null) ? null : ms -> parameters.getFilter().test(ms)); } /** - * Generates a single mek summary from a RAT determined by the given faction, - * quality and other parameters. - * We force a fallback to try to ensure that something is generated if the - * parents have any possible units to generate, - * as that is the normally expected behaviour for MekHQ OpFor generation. + * Generates a single mek summary from a RAT determined by the given faction, quality and other parameters. We force + * a fallback to try to ensure that something is generated if the parents have any possible units to generate, as + * that is the normally expected behaviour for MekHQ OpFor generation. * * @param parameters RATGenerator parameters */ @@ -167,15 +166,15 @@ public List generate(final int count, final UnitGeneratorParameters } /** - * This finds a unit table for OpFor generation. It falls back using the parent - * faction to try to ensure there are + * This finds a unit table for OpFor generation. It falls back using the parent faction to try to ensure there are * units in the unit table, so an OpFor is generated. * * @param unitParameters the base parameters to find the table using. + * * @return the unit table to use in generating OpFor mek summaries */ private UnitTable findOpForTable(final UnitGeneratorParameters unitParameters) { - final UnitTable.Parameters parameters = unitParameters.getRATGeneratorParameters(); + final Parameters parameters = unitParameters.getRATGeneratorParameters(); UnitTable table = UnitTable.findTable(parameters); if (!table.hasUnits()) { // Do Parent Factions Fallbacks to try to ensure units can be generated, at a diff --git a/MekHQ/src/mekhq/campaign/universe/UnitGeneratorParameters.java b/MekHQ/src/mekhq/campaign/universe/UnitGeneratorParameters.java index 284587997d6..07bb997e799 100644 --- a/MekHQ/src/mekhq/campaign/universe/UnitGeneratorParameters.java +++ b/MekHQ/src/mekhq/campaign/universe/UnitGeneratorParameters.java @@ -35,19 +35,16 @@ import megamek.client.ratgenerator.FactionRecord; import megamek.client.ratgenerator.MissionRole; import megamek.client.ratgenerator.ModelRecord; -import megamek.client.ratgenerator.UnitTable.Parameters; +import megamek.client.ratgenerator.Parameters; import megamek.common.EntityMovementMode; import megamek.common.MekSummary; import mekhq.campaign.mission.AtBDynamicScenarioFactory; /** - * Data structure that contains parameters relevant to unit generation via the - * IUnitGenerator interface - * and is capable of translating itself to - * megamek.client.ratgenerator.parameters + * Data structure that contains parameters relevant to unit generation via the IUnitGenerator interface and is capable + * of translating itself to megamek.client.ratgenerator.parameters * * @author NickAragua - * */ public class UnitGeneratorParameters { private String faction; @@ -68,33 +65,29 @@ public UnitGeneratorParameters() { * Thorough deep clone of this generator parameters object. */ @Override - public UnitGeneratorParameters clone() { - UnitGeneratorParameters newParams = new UnitGeneratorParameters(); - - newParams.setFaction(faction); - newParams.setUnitType(unitType); - newParams.setWeightClass(weightClass); - newParams.setYear(year); - newParams.setQuality(quality); - newParams.setFilter(filter); - - Collection newModes = new ArrayList<>(); - for (EntityMovementMode movementMode : movementModes) { - newModes.add(movementMode); - } + public UnitGeneratorParameters clone() throws CloneNotSupportedException { + UnitGeneratorParameters unitGeneratorParameters = (UnitGeneratorParameters) super.clone(); + + unitGeneratorParameters.setFaction(faction); + unitGeneratorParameters.setUnitType(unitType); + unitGeneratorParameters.setWeightClass(weightClass); + unitGeneratorParameters.setYear(year); + unitGeneratorParameters.setQuality(quality); + unitGeneratorParameters.setFilter(filter); + + Collection newModes = new ArrayList<>(movementModes); - newParams.setMovementModes(newModes); + unitGeneratorParameters.setMovementModes(newModes); for (MissionRole missionRole : missionRoles) { - newParams.addMissionRole(missionRole); + unitGeneratorParameters.addMissionRole(missionRole); } - return newParams; + return unitGeneratorParameters; } /** - * Translate the contents of this data structure into a - * megamek.client.ratgenerator.Parameters object + * Translate the contents of this data structure into a megamek.client.ratgenerator.Parameters object * * @return */ @@ -107,11 +100,16 @@ public Parameters getRATGeneratorParameters() { weightClasses.add(getWeightClass()); } - Parameters params = new Parameters(fRec, getUnitType(), getYear(), rating, weightClasses, - ModelRecord.NETWORK_NONE, - getMovementModes(), getMissionRoles(), 2, fRec); - - return params; + return new Parameters(fRec, + getUnitType(), + getYear(), + rating, + weightClasses, + ModelRecord.NETWORK_NONE, + getMovementModes(), + getMissionRoles(), + 2, + fRec); } public String getFaction() { @@ -174,6 +172,10 @@ public void setMissionRoles(Collection missionRoles) { this.missionRoles = missionRoles; } + /** + * @deprecated no indicated uses. + */ + @Deprecated(since = "0.50.05", forRemoval = true) public void clearMissionRoles() { missionRoles.clear(); } From 6da26b42a01a49e1e041c724370598299ac8df4e Mon Sep 17 00:00:00 2001 From: Richard J Hancock Date: Sun, 6 Apr 2025 15:29:52 -0500 Subject: [PATCH 2/3] Added a catch to prevent a massive re-write --- .../universe/UnitGeneratorParameters.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/MekHQ/src/mekhq/campaign/universe/UnitGeneratorParameters.java b/MekHQ/src/mekhq/campaign/universe/UnitGeneratorParameters.java index 07bb997e799..9f21f3df0b6 100644 --- a/MekHQ/src/mekhq/campaign/universe/UnitGeneratorParameters.java +++ b/MekHQ/src/mekhq/campaign/universe/UnitGeneratorParameters.java @@ -65,25 +65,28 @@ public UnitGeneratorParameters() { * Thorough deep clone of this generator parameters object. */ @Override - public UnitGeneratorParameters clone() throws CloneNotSupportedException { - UnitGeneratorParameters unitGeneratorParameters = (UnitGeneratorParameters) super.clone(); - - unitGeneratorParameters.setFaction(faction); - unitGeneratorParameters.setUnitType(unitType); - unitGeneratorParameters.setWeightClass(weightClass); - unitGeneratorParameters.setYear(year); - unitGeneratorParameters.setQuality(quality); - unitGeneratorParameters.setFilter(filter); - - Collection newModes = new ArrayList<>(movementModes); - - unitGeneratorParameters.setMovementModes(newModes); - - for (MissionRole missionRole : missionRoles) { - unitGeneratorParameters.addMissionRole(missionRole); + public UnitGeneratorParameters clone() { + try { + UnitGeneratorParameters unitGeneratorParameters = (UnitGeneratorParameters) super.clone(); + unitGeneratorParameters.setFaction(faction); + unitGeneratorParameters.setUnitType(unitType); + unitGeneratorParameters.setWeightClass(weightClass); + unitGeneratorParameters.setYear(year); + unitGeneratorParameters.setQuality(quality); + unitGeneratorParameters.setFilter(filter); + + Collection newModes = new ArrayList<>(movementModes); + + unitGeneratorParameters.setMovementModes(newModes); + + for (MissionRole missionRole : missionRoles) { + unitGeneratorParameters.addMissionRole(missionRole); + } + + return unitGeneratorParameters; + } catch (CloneNotSupportedException e) { + return null; } - - return unitGeneratorParameters; } /** From 6c99899a882a4eb117e73b06cbfabc7fe0e95c8c Mon Sep 17 00:00:00 2001 From: Richard J Hancock Date: Sun, 6 Apr 2025 19:30:59 -0500 Subject: [PATCH 3/3] Removed tests that were disabled entirely for unknown reasons. --- .../market/ContractMarketIntegrationTest.java | 279 ------------------ .../divorce/AbstractDivorceTest.java | 118 -------- 2 files changed, 397 deletions(-) delete mode 100644 MekHQ/unittests/mekhq/campaign/market/ContractMarketIntegrationTest.java delete mode 100644 MekHQ/unittests/mekhq/campaign/personnel/divorce/AbstractDivorceTest.java diff --git a/MekHQ/unittests/mekhq/campaign/market/ContractMarketIntegrationTest.java b/MekHQ/unittests/mekhq/campaign/market/ContractMarketIntegrationTest.java deleted file mode 100644 index 5182aade20f..00000000000 --- a/MekHQ/unittests/mekhq/campaign/market/ContractMarketIntegrationTest.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (C) 2020-2025 The MegaMek Team. All Rights Reserved. - * - * This file is part of MekHQ. - * - * MekHQ is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License (GPL), - * version 3 or (at your option) any later version, - * as published by the Free Software Foundation. - * - * MekHQ is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * A copy of the GPL should have been included with this project; - * if not, see . - * - * NOTICE: The MegaMek organization is a non-profit group of volunteers - * creating free software for the BattleTech community. - * - * MechWarrior, BattleMech, `Mech and AeroTech are registered trademarks - * of The Topps Company, Inc. All Rights Reserved. - * - * Catalyst Game Labs and the Catalyst Game Labs logo are trademarks of - * InMediaRes Productions, LLC. - */ -package mekhq.campaign.market; - -import megamek.common.*; -import mekhq.campaign.Campaign; -import mekhq.campaign.CampaignOptions; -import mekhq.campaign.force.Force; -import mekhq.campaign.market.contractMarket.AtbMonthlyContractMarket; -import mekhq.campaign.mission.AtBContract; -import mekhq.campaign.mission.Contract; -import mekhq.campaign.mission.enums.AtBContractType; -import mekhq.campaign.mission.enums.ContractCommandRights; -import mekhq.campaign.mission.enums.MissionStatus; -import mekhq.campaign.personnel.Person; -import mekhq.campaign.personnel.enums.PersonnelRole; -import mekhq.campaign.personnel.enums.PersonnelStatus; -import mekhq.campaign.personnel.ranks.Ranks; -import mekhq.campaign.rating.UnitRatingMethod; -import mekhq.campaign.unit.Unit; -import mekhq.campaign.universe.Factions; -import mekhq.campaign.universe.RandomFactionGenerator; -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.Disabled; -import org.junit.jupiter.api.Test; - -import java.security.SecureRandom; -import java.util.ArrayList; -import java.util.UUID; -import java.util.Vector; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.*; - -@Disabled // All tests under this class rely on randomness, and thus doesn't work properly. -public class ContractMarketIntegrationTest { - private static final int REASONABLE_GENERATION_ATTEMPTS = 3; - - private Campaign campaign; - - @BeforeAll - public static void beforeAll() { - EquipmentType.initializeTypes(); - try { - Factions.setInstance(Factions.loadDefault()); - Systems.setInstance(Systems.loadDefault()); - } catch (Exception ex) { - LogManager.getLogger().error("", ex); - } - Ranks.initializeRankSystems(); - } - - @BeforeEach - public void beforeEach() { - CampaignOptions options = new CampaignOptions(); - options.setUnitRatingMethod(UnitRatingMethod.NONE); - - campaign = new Campaign(); - campaign.setCampaignOptions(options); - - RandomFactionGenerator.getInstance().startup(campaign); - - fillHangar(campaign); - } - - @Test - public void addAtBContractMercsTest() { - AtbMonthlyContractMarket market = new AtbMonthlyContractMarket(); - - // Simulate clicking GM Add on the contract market three times - for (int ii = 0; ii < REASONABLE_GENERATION_ATTEMPTS; ii++) { - market.addAtBContract(campaign); - } - - assertFalse(market.getContracts().isEmpty()); - } - - @Test - public void generateContractOffersMercsTest() { - AtbMonthlyContractMarket market = new AtbMonthlyContractMarket(); - - // Simulate three months of contract generation ... - boolean foundContract = false; - for (int ii = 0; ii < REASONABLE_GENERATION_ATTEMPTS; ii++) { - market.generateContractOffers(campaign, true); - - // ... and one of these three should get us a contract! - foundContract |= !market.getContracts().isEmpty(); - } - - assertTrue(foundContract); - } - - @Test - public void addAtBContractMercRetainerTest() { - campaign.setRetainerEmployerCode("LA"); - - AtbMonthlyContractMarket market = new AtbMonthlyContractMarket(); - - // Simulate clicking GM Add on the contract market three times - for (int ii = 0; ii < 3; ii++) { - market.addAtBContract(campaign); - } - - assertFalse(market.getContracts().isEmpty()); - } - - @Test - public void generateContractOffersMercRetainerTest() { - campaign.setRetainerEmployerCode("CS"); - - AtbMonthlyContractMarket market = new AtbMonthlyContractMarket(); - - // Simulate three months of contract generation ... - boolean foundContract = false; - for (int ii = 0; ii < REASONABLE_GENERATION_ATTEMPTS; ii++) { - market.generateContractOffers(campaign, true); - - // ... and one of these three should get us a contract! - foundContract |= !market.getContracts().isEmpty(); - } - - assertTrue(foundContract); - } - - @Test - public void generateContractOffersMercSubcontractTest() { - AtBContract existing = mock(AtBContract.class); - when(existing.getId()).thenReturn(1); - when(existing.getScenarios()).thenReturn(new ArrayList<>()); - when(existing.getContractType()).thenReturn(AtBContractType.GARRISON_DUTY); - when(existing.getStatus()).thenReturn(MissionStatus.ACTIVE); - when(existing.getEmployerCode()).thenReturn("FWL"); - when(existing.getEnemyCode()).thenReturn("CC"); - when(existing.getSystemId()).thenReturn("Sian"); - when(existing.getStartDate()).thenReturn(campaign.getLocalDate().minusDays(3000)); - when(existing.getEndingDate()).thenReturn(campaign.getLocalDate().plusDays(3000)); - when(existing.isActiveOn(campaign.getLocalDate(), false)).thenCallRealMethod(); - when(existing.getCommandRights()).thenReturn(ContractCommandRights.INDEPENDENT); - campaign.importMission(existing); - - AtbMonthlyContractMarket market = new AtbMonthlyContractMarket(); - - SecureRandom realRng = new SecureRandom(); - MMRandom rng = mock(MMRandom.class); - // Override and ensure we are guaranteed a sub-contract - MMRoll roll1d6 = mock(MMRoll.class); - when(roll1d6.getIntValue()).thenReturn(6); - doReturn(roll1d6).when(rng).d6(); - doReturn(roll1d6).when(rng).d6(eq(1)); - MMRoll roll2d6 = mock(MMRoll.class); - when(roll2d6.getIntValue()).thenReturn(12); - doReturn(roll2d6).when(rng).d6(eq(2)); - // Keep the rest random - doAnswer(inv -> { - int max = inv.getArgument(0); - return realRng.nextInt(max); - }).when(rng).randomInt(anyInt()); - - try { - Compute.setRNG(rng); - - // Simulate three months of contract generation to get a sub contract ... - boolean foundContract = false; - for (int ii = 0; ii < REASONABLE_GENERATION_ATTEMPTS; ii++) { - market.generateContractOffers(campaign, true); - - // ... and hopefully, one of these should get us a sub-contract! 3 of 12 chance. - for (Contract c : market.getContracts()) { - foundContract |= (c instanceof AtBContract) - && (((AtBContract) c).getParentContract() == existing); - } - - if (foundContract) { - break; - } - } - - assertTrue(foundContract); - } finally { - Compute.setRNG(MMRandom.R_DEFAULT); - } - } - - @Test - public void addAtBContractHouseTest() { - campaign.setFactionCode("DC"); - - AtbMonthlyContractMarket market = new AtbMonthlyContractMarket(); - - // Simulate clicking GM Add on the contract market three times - for (int ii = 0; ii < 3; ii++) { - market.addAtBContract(campaign); - } - - assertFalse(market.getContracts().isEmpty()); - } - - @Test - public void generateContractOffersHouseTest() { - campaign.setFactionCode("FS"); - - AtbMonthlyContractMarket market = new AtbMonthlyContractMarket(); - - // Simulate three months of contract generation ... - boolean foundContract = false; - for (int ii = 0; ii < REASONABLE_GENERATION_ATTEMPTS; ii++) { - market.generateContractOffers(campaign, true); - - // ... and one of these three should get us a contract! - foundContract |= !market.getContracts().isEmpty(); - } - - assertTrue(foundContract); - } - - private void fillHangar(Campaign campaign) { - // Add 12 meks in 3 forces - for (int jj = 0; jj < 3; ++jj) { - Force force = new Force("Force " + jj); - for (int ii = 0; ii < 4; ++ii) { - Unit unit = createMek(campaign); - force.addUnit(unit.getId()); - - campaign.getHangar().addUnit(unit); - } - - campaign.addForce(force, campaign.getForces()); - } - } - - private Unit createMek(Campaign campaign) { - Mek entity = mock(Mek.class); - when(entity.getCrew()).thenReturn(new Crew(CrewType.SINGLE)); - when(entity.getTransportBays()).thenReturn(new Vector<>()); - Unit unit = new Unit(entity, campaign); - unit.setId(UUID.randomUUID()); - unit.addPilotOrSoldier(createPilot()); - return unit; - } - - private Person createPilot() { - Person person = mock(Person.class); - when(person.getId()).thenReturn(UUID.randomUUID()); - when(person.getPrimaryRole()).thenReturn(PersonnelRole.MEKWARRIOR); - when(person.getSecondaryRole()).thenReturn(PersonnelRole.NONE); - when(person.getStatus()).thenReturn(PersonnelStatus.ACTIVE); - return person; - } -} diff --git a/MekHQ/unittests/mekhq/campaign/personnel/divorce/AbstractDivorceTest.java b/MekHQ/unittests/mekhq/campaign/personnel/divorce/AbstractDivorceTest.java deleted file mode 100644 index df0a67e75ed..00000000000 --- a/MekHQ/unittests/mekhq/campaign/personnel/divorce/AbstractDivorceTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2022-2025 The MegaMek Team. All Rights Reserved. - * - * This file is part of MekHQ. - * - * MekHQ is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License (GPL), - * version 3 or (at your option) any later version, - * as published by the Free Software Foundation. - * - * MekHQ is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * A copy of the GPL should have been included with this project; - * if not, see . - * - * NOTICE: The MegaMek organization is a non-profit group of volunteers - * creating free software for the BattleTech community. - * - * MechWarrior, BattleMech, `Mech and AeroTech are registered trademarks - * of The Topps Company, Inc. All Rights Reserved. - * - * Catalyst Game Labs and the Catalyst Game Labs logo are trademarks of - * InMediaRes Productions, LLC. - */ -package mekhq.campaign.personnel.divorce; - -import mekhq.campaign.Campaign; -import mekhq.campaign.CampaignOptions; -import mekhq.campaign.personnel.Person; -import mekhq.campaign.randomEvents.prisoners.enums.PrisonerStatus; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.Mockito.doCallRealMethod; -import static org.mockito.Mockito.lenient; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -@ExtendWith(value = MockitoExtension.class) -public class AbstractDivorceTest { - @Mock - private Campaign mockCampaign; - - @Mock - private CampaignOptions mockCampaignOptions; - - @Mock - private AbstractDivorce mockDivorce; - - @BeforeEach - public void beforeEach() { - lenient().when(mockCampaign.getCampaignOptions()).thenReturn(mockCampaignOptions); - } - - @Disabled // FIXME : Windchild : Test Missing - @Test - public void testCanDivorce() { - doCallRealMethod().when(mockDivorce).canDivorce(any(), anyBoolean()); - - final Person mockPerson = mock(Person.class); - - // Can't be Clan Personnel with Random Clan Divorce Disabled - when(mockDivorce.isUseRandomClanPersonnelDivorce()).thenReturn(false); - when(mockDivorce.isUseRandomPrisonerDivorce()).thenReturn(true); - assertNotNull(mockDivorce.canDivorce(mockPerson, true)); - - // Can be Non-Clan Personnel with Random Clan Divorce Disabled - when(mockPerson.isClanPersonnel()).thenReturn(false); - assertNull(mockDivorce.canDivorce(mockPerson, true)); - - // Can be a Non-Prisoner with Random Prisoner Divorce Disabled - when(mockPerson.getPrisonerStatus()).thenReturn(PrisonerStatus.FREE); - when(mockDivorce.isUseRandomPrisonerDivorce()).thenReturn(false); - assertNull(mockDivorce.canDivorce(mockPerson, true)); - - // Can't be a Prisoner with Random Prisoner Divorce Disabled - when(mockPerson.getPrisonerStatus()).thenReturn(PrisonerStatus.PRISONER); - assertNotNull(mockDivorce.canDivorce(mockPerson, true)); - - // Can be a Clan Prisoner with Random Clan and Random Prisoner Divorce Enabled - lenient().when(mockPerson.isClanPersonnel()).thenReturn(true); - when(mockDivorce.isUseRandomClanPersonnelDivorce()).thenReturn(true); - when(mockDivorce.isUseRandomPrisonerDivorce()).thenReturn(true); - assertNull(mockDivorce.canDivorce(mockPerson, true)); - } - - @Disabled // FIXME : Windchild : Test Missing - @Test - public void testWidowed() { - - } - - - @Disabled // FIXME : Windchild : Test Missing - @Test - public void testDivorce() { - - } - - //region New Day - @Disabled // FIXME : Windchild : Test Missing - @Test - public void testProcessNewWeek() { - - } - //endregion New Day -}