/** * {@link ChassisOmniMech#getFixedMass()} shall return the mass of the chassis with all non fixed * items and armor removed. */ @Test public final void testGetFixedHeatSinks() { ChassisOmniMech cut = makeDefaultCUT(); List<Item> fixed1 = new ArrayList<>(); List<Item> fixed2 = new ArrayList<>(); List<Item> fixed3 = new ArrayList<>(); Item item1 = Mockito.mock(Item.class); HeatSink hs1 = Mockito.mock(HeatSink.class); HeatSink hs2 = Mockito.mock(HeatSink.class); Mockito.when(item1.getMass()).thenReturn(1.0); Mockito.when(hs1.getMass()).thenReturn(2.0); Mockito.when(hs2.getMass()).thenReturn(3.0); fixed1.add(item1); fixed1.add(hs1); fixed2.add(hs1); fixed2.add(hs1); fixed3.add(hs2); Mockito.when(components[2].getFixedItems()).thenReturn(fixed1); Mockito.when(components[3].getFixedItems()).thenReturn(fixed2); Mockito.when(components[5].getFixedItems()).thenReturn(fixed3); assertEquals(4, cut.getFixedHeatSinks()); }
private void makeDefaultCut() { Mockito.when(shs.getNumCriticalSlots()).thenReturn(1); Mockito.when(shsUpgrade.getHeatSinkType()).thenReturn(shs); Mockito.when(dhs.getNumCriticalSlots()).thenReturn(2); Mockito.when(dhsUpgrade.getHeatSinkType()).thenReturn(dhs); Mockito.when(upgrades.getHeatSink()).thenReturn(shsUpgrade); Mockito.when(component.getItemsEquipped()).thenReturn(items); Mockito.when(component.getEngineHeatsinksMax()).thenReturn(engineHsSlots); Mockito.doAnswer( new Answer<Void>() { @Override public Void answer(InvocationOnMock aInvocation) throws Throwable { if (equippedHs >= maxEquippableNewType) throw new IllegalArgumentException("Can't Add!"); equippedHs++; return null; } }) .when(component) .addItem(newType); Mockito.when(component.canEquip(newType)) .then( new Answer<EquipResult>() { @Override public EquipResult answer(InvocationOnMock aInvocation) throws Throwable { if (equippedHs < maxEquippableNewType) { return EquipResult.SUCCESS; } return EquipResult.make(Type.NotEnoughSlots); } }); Mockito.doAnswer( new Answer<Void>() { @Override public Void answer(InvocationOnMock aInvocation) throws Throwable { if (equippedHs <= 0) throw new IllegalArgumentException("Can't remove!"); equippedHs--; return null; } }) .when(component) .removeItem(oldType); Mockito.when(component.canRemoveItem(oldType)) .then( new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock aInvocation) throws Throwable { return equippedHs > 0; } }); Mockito.when(loadout.getName()).thenReturn("Mock Loadout"); Mockito.when(loadout.getUpgrades()).thenReturn(upgrades); Mockito.when(loadout.getComponents()).thenReturn(Arrays.asList(component)); Mockito.when(loadout.canEquip(newType)) .then( new Answer<EquipResult>() { @Override public EquipResult answer(InvocationOnMock aInvocation) throws Throwable { if (equippedHs < maxGloballyEquippableNewType) { return EquipResult.SUCCESS; } return EquipResult.make(Type.NotEnoughSlots); } }); }