Skip to content

Commit

Permalink
Add checkScrappable with armor test
Browse files Browse the repository at this point in the history
  • Loading branch information
sixlettervariables committed Dec 30, 2020
1 parent ca6b6ac commit d2e2e7f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions MekHQ/unittests/mekhq/campaign/parts/MekLocationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -681,9 +681,11 @@ public void checkSalvagableBadHipShoulderTest() {
// Must scrap a limb with a bad hip or shoulder
doReturn(true).when(unit).hasBadHipOrShoulder(eq(location));
assertNotNull(mekLocation.checkSalvagable());
assertNotNull(mekLocation.checkFixable());

doReturn(false).when(unit).hasBadHipOrShoulder(eq(location));
assertNull(mekLocation.checkSalvagable());
assertNull(mekLocation.checkFixable());
}

@Test
Expand All @@ -703,9 +705,11 @@ public void checkSalvagableTorsoWithArmsIntactTest() {
// Cannot salvage a torso if the attached arm is Okay
doReturn(false).when(entity).isLocationBad(eq(Mech.LOC_RARM));
assertNotNull(mekLocation.checkSalvagable());
assertNotNull(mekLocation.checkFixable());

doReturn(true).when(entity).isLocationBad(eq(Mech.LOC_RARM));
assertNull(mekLocation.checkSalvagable());
assertNull(mekLocation.checkFixable());

location = Mech.LOC_LT;
mekLocation = new MekLocation(location, 30, 0, false, false, false, false, false, mockCampaign);
Expand All @@ -714,9 +718,42 @@ public void checkSalvagableTorsoWithArmsIntactTest() {
// Cannot salvage a torso if the attached arm is Okay
doReturn(false).when(entity).isLocationBad(eq(Mech.LOC_LARM));
assertNotNull(mekLocation.checkSalvagable());
assertNotNull(mekLocation.checkFixable());

doReturn(true).when(entity).isLocationBad(eq(Mech.LOC_LARM));
assertNull(mekLocation.checkSalvagable());
assertNull(mekLocation.checkFixable());
}

@Test
public void checkSalvagableArmorStillPresentTest() {
Campaign mockCampaign = mock(Campaign.class);
Unit unit = mock(Unit.class);
Mech entity = mock(Mech.class);
when(unit.getEntity()).thenReturn(entity);
when(entity.getWeight()).thenReturn(30.0);
doCallRealMethod().when(entity).getLocationName(any());
when(unit.isSalvage()).thenReturn(true);

int location = Mech.LOC_LLEG;
MekLocation mekLocation = new MekLocation(location, 30, 0, false, false, false, false, false, mockCampaign);
mekLocation.setUnit(unit);

// No armor
assertNull(mekLocation.checkSalvagable());
assertNull(mekLocation.checkFixable());

// Some armor, for real.
doReturn(1).when(entity).getArmorForReal(eq(location), anyBoolean());
assertNotNull(mekLocation.checkSalvagable());
assertNotNull(mekLocation.checkFixable());

// Some rear armor
doReturn(0).when(entity).getArmorForReal(eq(location), eq(false));
doReturn(true).when(entity).hasRearArmor(eq(location));
doReturn(1).when(entity).getArmorForReal(eq(location), eq(true));
assertNotNull(mekLocation.checkSalvagable());
assertNotNull(mekLocation.checkFixable());
}

@Test
Expand Down

0 comments on commit d2e2e7f

Please sign in to comment.