Skip to content

Commit

Permalink
Merge pull request MegaMek#4058 from AaronGullickson/fix-tests-weapon…
Browse files Browse the repository at this point in the history
…-bays

Attempt to fix broken bay equipment tests
  • Loading branch information
HammerGS authored May 7, 2024
2 parents f69851c + b141435 commit 9a22cd6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.io.StringWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import static mekhq.campaign.parts.equipment.EquipmentUtilities.getEquipmentType;
Expand Down Expand Up @@ -1447,9 +1448,9 @@ public void checkWeaponBayOnlyWeaponRemovedTest() {
WeaponMounted weaponBay = mock(WeaponMounted.class);
when(weaponBay.getLocation()).thenReturn(location);
when(weaponBay.getType()).thenReturn(bayWeaponType);
Vector<Integer> bayWeapons = new Vector<>();
bayWeapons.addElement(33);
bayWeapons.addElement(equipmentNum);
List<WeaponMounted> bayWeapons = new ArrayList<>();
//bayWeapons.addElement(33);
bayWeapons.add(weaponBay);
when(weaponBay.getBayWeapons()).thenReturn(bayWeapons);
doReturn(weaponBay).when(entity).getEquipment(eq(bayEqNum));
doReturn(bayEqNum).when(entity).getEquipmentNum(eq(weaponBay));
Expand Down Expand Up @@ -1535,9 +1536,9 @@ public void checkWeaponBayWeaponRemovedOthersOkayTest() {
WeaponMounted weaponBay = mock(WeaponMounted.class);
when(weaponBay.getLocation()).thenReturn(location);
when(weaponBay.getType()).thenReturn(bayWeaponType);
Vector<Integer> bayWeapons = new Vector<>();
bayWeapons.addElement(otherEqNum);
bayWeapons.addElement(equipmentNum);
List<WeaponMounted> bayWeapons = new ArrayList<>();
bayWeapons.add(otherMounted);
bayWeapons.add(weaponBay);
when(weaponBay.getBayWeapons()).thenReturn(bayWeapons);
doReturn(weaponBay).when(entity).getEquipment(eq(bayEqNum));
doReturn(bayEqNum).when(entity).getEquipmentNum(eq(weaponBay));
Expand Down Expand Up @@ -1614,7 +1615,7 @@ public void checkWeaponBayWeaponRemovedOthersDestroyedTest() {
doReturn(mounted).when(entity).getEquipment(eq(equipmentNum));

int otherEqNum = 33;
Mounted otherMounted = mock(Mounted.class);
WeaponMounted otherMounted = mock(WeaponMounted.class);
when(otherMounted.getLocation()).thenReturn(location);
when(otherMounted.isDestroyed()).thenReturn(true);
doReturn(otherMounted).when(entity).getEquipment(eq(otherEqNum));
Expand All @@ -1624,9 +1625,9 @@ public void checkWeaponBayWeaponRemovedOthersDestroyedTest() {
WeaponMounted weaponBay = mock(WeaponMounted.class);
when(weaponBay.getLocation()).thenReturn(location);
when(weaponBay.getType()).thenReturn(bayWeaponType);
Vector<Integer> bayWeapons = new Vector<>();
bayWeapons.addElement(otherEqNum);
bayWeapons.addElement(equipmentNum);
List<WeaponMounted> bayWeapons = new ArrayList<>();
bayWeapons.add(otherMounted);
bayWeapons.add(weaponBay);
when(weaponBay.getBayWeapons()).thenReturn(bayWeapons);
doReturn(weaponBay).when(entity).getEquipment(eq(bayEqNum));
doReturn(bayEqNum).when(entity).getEquipmentNum(eq(weaponBay));
Expand Down Expand Up @@ -1699,7 +1700,7 @@ public void checkWeaponBayUpdateConditionFromPartGoodWeaponTest() {
doReturn(mounted).when(entity).getEquipment(eq(equipmentNum));

int otherEqNum = 33;
Mounted otherMounted = mock(Mounted.class);
WeaponMounted otherMounted = mock(WeaponMounted.class);
when(otherMounted.getLocation()).thenReturn(location);
doReturn(otherMounted).when(entity).getEquipment(eq(otherEqNum));

Expand All @@ -1708,9 +1709,9 @@ public void checkWeaponBayUpdateConditionFromPartGoodWeaponTest() {
WeaponMounted weaponBay = mock(WeaponMounted.class);
when(weaponBay.getLocation()).thenReturn(location);
when(weaponBay.getType()).thenReturn(bayWeaponType);
Vector<Integer> bayWeapons = new Vector<>();
bayWeapons.addElement(otherEqNum);
bayWeapons.addElement(equipmentNum);
List<WeaponMounted> bayWeapons = new ArrayList<>();
bayWeapons.add(otherMounted);
bayWeapons.add(weaponBay);
when(weaponBay.getBayWeapons()).thenReturn(bayWeapons);
doReturn(weaponBay).when(entity).getEquipment(eq(bayEqNum));
doReturn(bayEqNum).when(entity).getEquipmentNum(eq(weaponBay));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.UUID;
import java.util.Vector;
import java.util.*;

import static mekhq.campaign.parts.AmmoUtilities.getAmmoType;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -202,14 +199,14 @@ public void getBayReturnsBayMatchingEqNum() {
Unit unit = mock(Unit.class);
Entity entity = mock(Entity.class);
when(unit.getEntity()).thenReturn(entity);
Mounted mounted = mock(Mounted.class);
AmmoMounted mounted = mock(AmmoMounted.class);
when(mounted.getType()).thenReturn(ammoType);
when(entity.getEquipment(equipmentNum)).thenReturn(mounted);
Mounted bay = mock(Mounted.class);
Vector<Integer> bayAmmo = new Vector<>();
bayAmmo.addElement(equipmentNum);
when(entity.getEquipment(equipmentNum)).thenReturn((Mounted) mounted);
WeaponMounted bay = mock(WeaponMounted.class);
List<AmmoMounted> bayAmmo = new ArrayList<>();
bayAmmo.add(mounted);
when(bay.getBayAmmo()).thenReturn(bayAmmo);
when(entity.getEquipment(bayNum)).thenReturn(bay);
when(entity.getEquipment(bayNum)).thenReturn((Mounted) bay);

// Set the bay as if we're in deserialization code
ammoBin.setBay(bayNum);
Expand All @@ -232,14 +229,14 @@ public void getBayFallsBackToMatchingWeaponBayIfMissingBayEquipment() {
Unit unit = mock(Unit.class);
Entity entity = mock(Entity.class);
when(unit.getEntity()).thenReturn(entity);
Mounted mounted = mock(Mounted.class);
AmmoMounted mounted = mock(AmmoMounted.class);
when(mounted.getType()).thenReturn(ammoType);
when(entity.getEquipment(equipmentNum)).thenReturn(mounted);
when(entity.getEquipment(equipmentNum)).thenReturn((Mounted) mounted);
WeaponMounted wrongWeaponBay = mock(WeaponMounted.class);
when(wrongWeaponBay.getBayAmmo()).thenReturn(new Vector<>());
WeaponMounted weaponBay = mock(WeaponMounted.class);
Vector<Integer> bayAmmo = new Vector<>();
bayAmmo.addElement(equipmentNum);
List<AmmoMounted> bayAmmo = new ArrayList<>();
bayAmmo.add(mounted);
when(weaponBay.getBayAmmo()).thenReturn(bayAmmo);
when(entity.getEquipment(bayNum)).thenReturn((Mounted) weaponBay);
ArrayList<WeaponMounted> weaponBays = new ArrayList<>();
Expand All @@ -266,14 +263,14 @@ public void getBayFallsBackToMatchingWeaponBayIfNoBayEquipment() {
Unit unit = mock(Unit.class);
Entity entity = mock(Entity.class);
when(unit.getEntity()).thenReturn(entity);
Mounted mounted = mock(Mounted.class);
AmmoMounted mounted = mock(AmmoMounted.class);
when(mounted.getType()).thenReturn(ammoType);
when(entity.getEquipment(equipmentNum)).thenReturn(mounted);
when(entity.getEquipment(equipmentNum)).thenReturn((Mounted) mounted);
WeaponMounted wrongWeaponBay = mock(WeaponMounted.class);
when(wrongWeaponBay.getBayAmmo()).thenReturn(new Vector<>());
WeaponMounted weaponBay = mock(WeaponMounted.class);
Vector<Integer> bayAmmo = new Vector<>();
bayAmmo.addElement(equipmentNum);
List<AmmoMounted> bayAmmo = new ArrayList<>();
bayAmmo.add(mounted);
when(weaponBay.getBayAmmo()).thenReturn(bayAmmo);
ArrayList<WeaponMounted> weaponBays = new ArrayList<>();
weaponBays.add(wrongWeaponBay);
Expand Down Expand Up @@ -303,9 +300,9 @@ public void getBayReturnsNullIfNoMatch() {
Mounted mounted = mock(Mounted.class);
when(mounted.getType()).thenReturn(ammoType);
when(entity.getEquipment(equipmentNum)).thenReturn(mounted);
Mounted bay = mock(Mounted.class);
when(bay.getBayAmmo()).thenReturn(new Vector<>());
when(entity.getEquipment(bayNum)).thenReturn(bay);
WeaponMounted bay = mock(WeaponMounted.class);
when(bay.getBayAmmo()).thenReturn(new ArrayList<>());
when(entity.getEquipment(bayNum)).thenReturn((Mounted) bay);
when(entity.getWeaponBayList()).thenReturn(new ArrayList<>());

// Set the bay without actually setting it (if through deserialization)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import static mekhq.campaign.parts.AmmoUtilities.getAmmoType;
Expand Down Expand Up @@ -214,8 +216,8 @@ public void fixFindsAcceptableReplacementTest() {
when(mounted.getType()).thenReturn(ammoType);
when(entity.getEquipment(equipmentNum)).thenReturn((Mounted) mounted);
WeaponMounted bay = mock(WeaponMounted.class);
Vector<Integer> bayAmmo = new Vector<>();
bayAmmo.addElement(equipmentNum);
List<AmmoMounted> bayAmmo = new ArrayList<>();
bayAmmo.add(mounted);
when(bay.getBayAmmo()).thenReturn(bayAmmo);
when(entity.getEquipment(bayNum)).thenReturn((Mounted) bay);
missingAmmoBin.setUnit(unit);
Expand Down

0 comments on commit 9a22cd6

Please sign in to comment.