diff --git a/megamek/src/megamek/common/equipment/ArmorType.java b/megamek/src/megamek/common/equipment/ArmorType.java index 106ec32d22d..5ec70441995 100644 --- a/megamek/src/megamek/common/equipment/ArmorType.java +++ b/megamek/src/megamek/common/equipment/ArmorType.java @@ -34,6 +34,9 @@ public class ArmorType extends MiscType { private static final List allTypes = new ArrayList<>(); public static ArmorType of(int type, boolean clan) { + if (armorTypeLookupClan.isEmpty() && armorTypeLookupIS.isEmpty()) { + initializeTypes(); + } ArmorType armor = clan ? armorTypeLookupClan.get(type) : armorTypeLookupIS.get(type); // Some mixed tech unit files use the unit tech base instead of the armor tech base. if (armor == null) { diff --git a/megamek/unittests/megamek/client/bot/princess/BasicPathRankerTest.java b/megamek/unittests/megamek/client/bot/princess/BasicPathRankerTest.java index 57be603bc06..c5f9966f3a2 100644 --- a/megamek/unittests/megamek/client/bot/princess/BasicPathRankerTest.java +++ b/megamek/unittests/megamek/client/bot/princess/BasicPathRankerTest.java @@ -25,6 +25,7 @@ import megamek.codeUtilities.StringUtility; import megamek.common.*; import megamek.common.MovePath.Key; +import megamek.common.equipment.ArmorType; import megamek.common.options.GameOptions; import megamek.common.options.OptionsConstants; import megamek.common.options.PilotOptions; @@ -61,6 +62,11 @@ public class BasicPathRankerTest { @BeforeEach public void beforeEach() { + + // We now need to make sure all armor types are initialized or mockito will complain. + if (!ArmorType.getAllTypes().hasMoreElements()) { + ArmorType.initializeTypes(); + } final BehaviorSettings mockBehavior = mock(BehaviorSettings.class); when(mockBehavior.getFallShameValue()).thenReturn(BehaviorSettings.FALL_SHAME_VALUES[5]); when(mockBehavior.getBraveryValue()).thenReturn(BehaviorSettings.BRAVERY[5]); diff --git a/megamek/unittests/megamek/common/loaders/TdbFileTest.java b/megamek/unittests/megamek/common/loaders/TdbFileTest.java index 4d6f0ee2dd1..ba98ac09c47 100644 --- a/megamek/unittests/megamek/common/loaders/TdbFileTest.java +++ b/megamek/unittests/megamek/common/loaders/TdbFileTest.java @@ -39,34 +39,34 @@ * @author nderwin */ public class TdbFileTest { - + @Test public void testJenner() throws Exception { InputStream is = getClass().getResourceAsStream("JR7-D Jenner.xml"); assertNotNull(is); - + TdbFile testMe = TdbFile.getInstance(is); - + assertEquals(6, testMe.mounted.items.size()); - + Entity result = testMe.getEntity(); assertTrue(result instanceof BipedMech); BipedMech mek = (BipedMech) result; - + assertEquals("Jenner", mek.getChassis()); assertEquals("JR7-D", mek.getModel()); assertEquals(35.0f, mek.getWeight(), 0.0f); assertEquals(Mech.COCKPIT_STANDARD, mek.getCockpitType()); assertEquals(Mech.GYRO_STANDARD, mek.getGyroType()); - + assertTrue(mek.getEngine().engineValid); assertTrue(mek.getEngine().isFusion()); assertEquals(Engine.NORMAL_ENGINE, mek.getEngine().getEngineType()); assertEquals(7, mek.getWalkMP()); assertEquals(11, mek.getRunMP()); - + assertEquals(10, mek.getActiveSinks()); assertEquals(7, mek.getArmor(Mech.LOC_HEAD)); @@ -80,7 +80,7 @@ public void testJenner() throws Exception { assertEquals(4, mek.getArmor(Mech.LOC_LARM)); assertEquals(6, mek.getArmor(Mech.LOC_RLEG)); assertEquals(6, mek.getArmor(Mech.LOC_LLEG)); - + assertFalse(mek.getFailedEquipment().hasNext()); boolean foundSRM = false; @@ -90,14 +90,14 @@ public void testJenner() throws Exception { int jjCT = 0; int jjRT = 0; int jjLT = 0; - + for (Mounted m : mek.getEquipment()) { switch (m.getLocation()) { case Mech.LOC_CT: if ("Jump Jet".equals(m.getName())) { jjCT++; } - + if (!foundSRM && "SRM 4".equals(m.getName())) { foundSRM = true; } else if (foundSRM && "SRM 4".equals(m.getName())) { @@ -112,7 +112,7 @@ public void testJenner() throws Exception { if ("Jump Jet".equals(m.getName())) { jjRT++; } - + if (!foundAmmo && "SRM 4 Ammo".equals(m.getName())) { foundAmmo = true; } else if (foundAmmo && "SRM 4 Ammo".equals(m.getName())) { @@ -151,7 +151,7 @@ public void testJenner() throws Exception { break; } } - + assertTrue(foundSRM, "Found SRM-4"); assertTrue(foundAmmo, "Found SRM-4 ammo"); assertEquals(1, jjCT, "Found 1 Jump Jet in CT"); @@ -160,36 +160,36 @@ public void testJenner() throws Exception { assertEquals(2, mlRARM, "Found 2 Medium Lasers in RARM"); assertEquals(2, mlLARM, "Found 2 Medium Lasers in LARM"); } - + @Test public void testTarantula() throws Exception { InputStream is = getClass().getResourceAsStream("ZPH-1A Tarantula.xml"); assertNotNull(is); - + TdbFile testMe = TdbFile.getInstance(is); - + assertEquals(4, testMe.mounted.items.size()); - + Entity result = testMe.getEntity(); assertTrue(result instanceof QuadMech); QuadMech mek = (QuadMech) result; - + assertEquals("Tarantula", mek.getChassis()); assertEquals("ZPH-1A", mek.getModel()); assertEquals(25.0f, mek.getWeight(), 0.0f); assertEquals(Mech.COCKPIT_STANDARD, mek.getCockpitType()); assertEquals(Mech.GYRO_STANDARD, mek.getGyroType()); - + assertTrue(mek.getEngine().engineValid); assertTrue(mek.getEngine().isFusion()); assertEquals(Engine.XL_ENGINE, mek.getEngine().getEngineType()); assertEquals(8, mek.getWalkMP()); assertEquals(12, mek.getRunMP()); - + assertEquals(10, mek.getActiveSinks()); - + assertEquals(6, mek.getArmor(Mech.LOC_HEAD)); assertEquals(7, mek.getArmor(Mech.LOC_RT)); assertEquals(10, mek.getArmor(Mech.LOC_CT)); @@ -201,7 +201,7 @@ public void testTarantula() throws Exception { assertEquals(7, mek.getArmor(Mech.LOC_LARM)); assertEquals(7, mek.getArmor(Mech.LOC_RLEG)); assertEquals(7, mek.getArmor(Mech.LOC_LLEG)); - + assertFalse(mek.getFailedEquipment().hasNext()); boolean foundSSRM = false; @@ -222,7 +222,7 @@ public void testTarantula() throws Exception { } else if (foundSSRM && "Streak SRM 2".equals(m.getName())) { fail("Only 1 SSRM-2 in CT"); } - + if (!foundAmmo && "Streak SRM 2 Ammo".equals(m.getName())) { foundAmmo = true; } else if (foundAmmo && "Streak SRM 2 Ammo".equals(m.getName())) { @@ -250,7 +250,7 @@ public void testTarantula() throws Exception { if ("Double Heat Sink".equals(m.getName())) { dblHS++; } - + if ("Medium Laser".equals(m.getName())) { mlLT++; } @@ -263,7 +263,7 @@ public void testTarantula() throws Exception { if ("Jump Jet".equals(m.getName())) { jjFRL++; } - + assertFalse(m.getName().contains("Heat Sink"), "Found a Heat Sink in RARM"); assertNotEquals("Medium Laser", m.getName(), "Found a Medium Laser in RARM"); assertNotEquals("Streak SRM 2", m.getName(), "Found a SSRM-2 in RARM"); @@ -273,7 +273,7 @@ public void testTarantula() throws Exception { if ("Jump Jet".equals(m.getName())) { jjFLL++; } - + assertFalse(m.getName().contains("Heat Sink"), "Found a Heat Sink in LARM"); assertNotEquals("Medium Laser", m.getName(), "Found a Medium Laser in LARM"); assertNotEquals("Streak SRM 2", m.getName(), "Found a SSRM-2 in LARM");