-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5513 from SJuliez/ds-loading
DS loading, issue 5495
- Loading branch information
Showing
2 changed files
with
60 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package megamek.common; | ||
|
||
import megamek.common.enums.GamePhase; | ||
import megamek.common.net.enums.PacketCommand; | ||
import megamek.common.net.packets.Packet; | ||
import megamek.common.verifier.TestEntity; | ||
import megamek.server.GameManager; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class DropShipMekLoadTest { | ||
|
||
@Test | ||
public void test() throws Exception { | ||
MechSummaryCache instance = MechSummaryCache.getInstance(true); | ||
Mech atlas = (Mech) instance.getMech("Atlas AS7-D").loadEntity(); | ||
atlas.setId(2); | ||
Dropship leopard = (Dropship) instance.getMech("Leopard (2537)").loadEntity(); | ||
leopard.setId(1); | ||
|
||
Game game = new Game(); | ||
game.setPhase(GamePhase.LOUNGE); | ||
game.addPlayer(0, new Player(0, "TestPlayer")); | ||
game.addEntity(atlas); | ||
game.addEntity(leopard); | ||
|
||
GameManager gm = mock(GameManager.class); | ||
doNothing().when(gm).entityUpdate(anyInt()); | ||
when(gm.getGame()).thenReturn(game); | ||
doCallRealMethod().when(gm).setGame(any(Game.class)); | ||
doCallRealMethod().when(gm).handlePacket(anyInt(), any(Packet.class)); | ||
gm.setGame(game); | ||
|
||
Packet packet = new Packet(PacketCommand.ENTITY_LOAD, atlas.getId(), leopard.getId(), -1); | ||
gm.handlePacket(0, packet); | ||
|
||
doAssertions(leopard, atlas); | ||
|
||
leopard.setAltitude(0); | ||
|
||
doAssertions(leopard, atlas); | ||
} | ||
|
||
private void doAssertions(Entity leopard, Entity atlas) { | ||
StringBuffer errors = new StringBuffer(); | ||
assertTrue(isValid(leopard, errors), "Leopard is not valid after loading Atlas, errors: " + errors); | ||
assertTrue(isValid(atlas, errors), "Atlas is not valid after loading onto Leopard, errors: " + errors); | ||
assertEquals(atlas.getTransportId(), leopard.getId(), | ||
"Carrier ID " + atlas.getTransportId() + " wrong, should be " + leopard.getId()); | ||
assertEquals(1, leopard.getLoadedUnits().size(), | ||
"Loaded unit list size" + leopard.getLoadedUnits().size() + " wrong, should be 1"); | ||
assertNull(atlas.getPosition(), "Loaded Atlas position is " + atlas.getPosition() + ", should be null"); | ||
} | ||
|
||
private boolean isValid(Entity entity, StringBuffer errors) { | ||
return TestEntity.getEntityVerifier(entity).correctEntity(errors); | ||
} | ||
} |