From 84d05ba4adb5d091e6ad99f5179745985efc833f Mon Sep 17 00:00:00 2001 From: sleet01 Date: Thu, 9 Jan 2025 23:58:18 -0800 Subject: [PATCH] Add unit test to verify IS Unofficial saving --- .../Puma Assault Tank PAT-001.blk | 103 ++++++++++++++++++ .../ui/generalUnit/BasicInfoViewTest.java | 66 +++++++++++ 2 files changed, 169 insertions(+) create mode 100644 megameklab/testresources/ui/generalUnit/BasicInfoViewTest/Puma Assault Tank PAT-001.blk create mode 100644 megameklab/unittests/megameklab/ui/generalUnit/BasicInfoViewTest.java diff --git a/megameklab/testresources/ui/generalUnit/BasicInfoViewTest/Puma Assault Tank PAT-001.blk b/megameklab/testresources/ui/generalUnit/BasicInfoViewTest/Puma Assault Tank PAT-001.blk new file mode 100644 index 000000000..0fd2da954 --- /dev/null +++ b/megameklab/testresources/ui/generalUnit/BasicInfoViewTest/Puma Assault Tank PAT-001.blk @@ -0,0 +1,103 @@ +#Saved from version 0.50.03-SNAPSHOT on 2025-01-09 + +Tank + + + +Puma Assault Tank + + + +PAT-001 + + + +4879 + + + +2650 + + + +2650 + + + +IS Level 1 + + + +None + + + +Tracked + + + +3 + + + +0 + + + +0 + + + +0 + + + +0 + + + +48 +32 +32 +24 +48 + + + +IS Vehicle Flamer Ammo +IS Ammo SRM-4 +IS Ammo LRM-20 +IS Ammo LRM-20 + + + +Medium Laser +Medium Laser +SRM 4 + + + +LRM 20 + + + +LRM 20 + + + +Small Laser +Flamer (Vehicle) + + + +PPC + + + +TRO: 3050 + + + +95.0 + + diff --git a/megameklab/unittests/megameklab/ui/generalUnit/BasicInfoViewTest.java b/megameklab/unittests/megameklab/ui/generalUnit/BasicInfoViewTest.java new file mode 100644 index 000000000..7916fa249 --- /dev/null +++ b/megameklab/unittests/megameklab/ui/generalUnit/BasicInfoViewTest.java @@ -0,0 +1,66 @@ +package megameklab.ui.generalUnit; + +import megamek.common.*; +import megamek.common.loaders.BLKFile; +import megamek.common.loaders.BLKTankFile; +import megamek.common.loaders.EntityLoadingException; +import megamek.common.loaders.EntitySavingException; +import megamek.common.util.BuildingBlock; +import megameklab.testing.util.InitializeTypes; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.io.InputStream; + +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(value = InitializeTypes.class) +class BasicInfoViewTest { + + // Filenames must be preceded with a slash to load from the testresources path + private final String resourcesPath = "/ui/generalUnit/BasicInfoViewTest/"; + + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + private Entity loadEntity(String filename) throws EntityLoadingException { + String path = resourcesPath + filename; + InputStream is = getClass().getResourceAsStream(path); + assertNotNull(is); + return new MekFileParser(is, filename).getEntity(); + } + + @Test + void testSetTechAdvancementFromEarlyISUnofficial() throws EntityLoadingException, EntitySavingException { + String fname = "Puma Assault Tank PAT-001.blk"; + Entity te = loadEntity(fname); + + // Confirm expected Tech Base (IS) and Tech Level (Simple Intro) + int techBase = te.getTechBase(); + int techLevel = te.getTechLevel(); + assertEquals(TechAdvancement.TECH_BASE_IS, techBase); + assertEquals(TechConstants.T_SIMPLE_INTRO, techLevel); + + // Update Tech Level + te.setTechLevel(TechConstants.T_IS_UNOFFICIAL); + + // Convert test entity to BLK block and back to a new entity using BLKFile conversion + BLKTankFile blkTankFile = new BLKTankFile(BLKFile.getBlock(te)); + Entity newTE = blkTankFile.getEntity(); + + // Confirm values were saved correctly + techBase = newTE.getTechBase(); + techLevel = newTE.getTechLevel(); + // Confirm expected Tech Base (IS) and Tech Level (IS Unofficial) + assertEquals(TechAdvancement.TECH_BASE_IS, techBase); + assertEquals(TechConstants.T_IS_UNOFFICIAL, techLevel); + assertFalse(newTE.isClan()); + } +}