use of org.terasology.logic.inventory.action.RemoveItemAction in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method removePartOfStack.
@Test
public void removePartOfStack() {
ItemComponent itemComp = new ItemComponent();
EntityRef item = Mockito.mock(EntityRef.class);
setupItemRef(item, itemComp, 2, 10);
inventoryComp.itemSlots.set(0, item);
EntityRef itemCopy = Mockito.mock(EntityRef.class);
ItemComponent itemCompCopy = new ItemComponent();
setupItemRef(itemCopy, itemCompCopy, 2, 10);
Mockito.when(entityManager.copy(item)).thenReturn(itemCopy);
RemoveItemAction action = new RemoveItemAction(instigator, item, false, 1);
inventoryAuthoritySystem.removeItem(action, inventory);
assertEquals(1, itemComp.stackCount);
assertEquals(1, itemCompCopy.stackCount);
Mockito.verify(item, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(item, atLeast(0)).iterateComponents();
Mockito.verify(item).saveComponent(itemComp);
Mockito.verify(itemCopy, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(itemCopy, atLeast(0)).iterateComponents();
Mockito.verify(itemCopy).saveComponent(itemCompCopy);
Mockito.verify(inventory, atLeast(0)).getComponent(InventoryComponent.class);
Mockito.verify(inventory).send(any(InventorySlotStackSizeChangedEvent.class));
Mockito.verify(entityManager).copy(item);
Mockito.verifyNoMoreInteractions(instigator, inventory, entityManager, item, itemCopy);
assertTrue(action.isConsumed());
assertEquals(itemCopy, action.getRemovedItem());
}
use of org.terasology.logic.inventory.action.RemoveItemAction in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method removeOverOneStackWithDestroy.
@Test
public void removeOverOneStackWithDestroy() {
EntityRef item1 = Mockito.mock(EntityRef.class);
ItemComponent itemComp1 = new ItemComponent();
setupItemRef(item1, itemComp1, 2, 10);
inventoryComp.itemSlots.set(0, item1);
EntityRef item2 = Mockito.mock(EntityRef.class);
ItemComponent itemComp2 = new ItemComponent();
setupItemRef(item2, itemComp2, 2, 10);
inventoryComp.itemSlots.set(1, item2);
RemoveItemAction action = new RemoveItemAction(instigator, Arrays.asList(item1, item2), true, 3);
inventoryAuthoritySystem.removeItem(action, inventory);
assertEquals(EntityRef.NULL, inventoryComp.itemSlots.get(0));
assertEquals(1, itemComp2.stackCount);
assertTrue(action.isConsumed());
assertNull(action.getRemovedItem());
Mockito.verify(item1, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(item1, atLeast(0)).exists();
Mockito.verify(item1, atLeast(0)).iterateComponents();
Mockito.verify(item1).destroy();
Mockito.verify(item2, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(item2, atLeast(0)).iterateComponents();
Mockito.verify(item2).saveComponent(itemComp2);
Mockito.verify(inventory, atLeast(0)).getComponent(InventoryComponent.class);
Mockito.verify(inventory).saveComponent(inventoryComp);
Mockito.verify(inventory, times(1)).send(any(BeforeItemRemovedFromInventory.class));
Mockito.verify(inventory, times(1)).send(any(InventorySlotChangedEvent.class));
Mockito.verify(inventory, times(1)).send(any(InventorySlotStackSizeChangedEvent.class));
Mockito.verifyNoMoreInteractions(instigator, inventory, entityManager, item1, item2);
}
Aggregations