use of org.terasology.logic.inventory.action.GiveItemAction in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method addItemToPartialAndOverflow.
@Test
public void addItemToPartialAndOverflow() {
ItemComponent itemComp = new ItemComponent();
EntityRef item = Mockito.mock(EntityRef.class);
setupItemRef(item, itemComp, 2, 10);
ItemComponent partialItemComp = new ItemComponent();
EntityRef partialItem = Mockito.mock(EntityRef.class);
setupItemRef(partialItem, partialItemComp, 9, 10);
inventoryComp.itemSlots.set(0, partialItem);
GiveItemAction action = new GiveItemAction(instigator, item);
inventoryAuthoritySystem.giveItem(action, inventory);
Mockito.verify(item, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(item, atLeast(0)).exists();
Mockito.verify(item, atLeast(0)).iterateComponents();
Mockito.verify(item).saveComponent(itemComp);
Mockito.verify(partialItem, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(partialItem, atLeast(0)).exists();
Mockito.verify(partialItem, atLeast(0)).iterateComponents();
Mockito.verify(partialItem).saveComponent(partialItemComp);
Mockito.verify(inventory, atLeast(0)).getComponent(InventoryComponent.class);
Mockito.verify(inventory).saveComponent(inventoryComp);
Mockito.verify(inventory, times(1)).send(any(InventorySlotStackSizeChangedEvent.class));
Mockito.verify(inventory, times(1)).send(any(InventorySlotChangedEvent.class));
Mockito.verify(inventory, times(1)).send(any(BeforeItemPutInInventory.class));
Mockito.verifyNoMoreInteractions(instigator, inventory, entityManager, item, partialItem);
assertEquals(partialItem, inventoryComp.itemSlots.get(0));
assertEquals(item, inventoryComp.itemSlots.get(1));
assertEquals(10, partialItemComp.stackCount);
assertEquals(1, itemComp.stackCount);
assertTrue(action.isConsumed());
}
use of org.terasology.logic.inventory.action.GiveItemAction in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method addItemToEmptyWithVeto.
@Test
public void addItemToEmptyWithVeto() {
ItemComponent itemComp = new ItemComponent();
EntityRef item = Mockito.mock(EntityRef.class);
setupItemRef(item, itemComp, 2, 10);
Mockito.when(inventory.send(any(BeforeItemPutInInventory.class))).then(invocation -> {
BeforeItemPutInInventory event = (BeforeItemPutInInventory) invocation.getArguments()[0];
event.consume();
return null;
});
GiveItemAction action = new GiveItemAction(instigator, item);
inventoryAuthoritySystem.giveItem(action, inventory);
Mockito.verify(item, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(item, atLeast(0)).exists();
Mockito.verify(inventory, atLeast(0)).getComponent(InventoryComponent.class);
Mockito.verify(inventory, times(5)).send(any(BeforeItemPutInInventory.class));
Mockito.verifyNoMoreInteractions(instigator, inventory, entityManager, item);
assertFalse(action.isConsumed());
}
use of org.terasology.logic.inventory.action.GiveItemAction in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method addItemToPartial.
@Test
public void addItemToPartial() {
ItemComponent itemComp = new ItemComponent();
EntityRef item = Mockito.mock(EntityRef.class);
setupItemRef(item, itemComp, 2, 10);
ItemComponent partialItemComp = new ItemComponent();
EntityRef partialItem = Mockito.mock(EntityRef.class);
setupItemRef(partialItem, partialItemComp, 2, 10);
inventoryComp.itemSlots.set(0, partialItem);
GiveItemAction action = new GiveItemAction(instigator, item);
inventoryAuthoritySystem.giveItem(action, inventory);
Mockito.verify(item, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(item, atLeast(0)).exists();
Mockito.verify(item, atLeast(0)).iterateComponents();
Mockito.verify(item).destroy();
Mockito.verify(partialItem, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(partialItem, atLeast(0)).exists();
Mockito.verify(partialItem, atLeast(0)).iterateComponents();
Mockito.verify(partialItem).saveComponent(partialItemComp);
Mockito.verify(inventory, atLeast(0)).getComponent(InventoryComponent.class);
Mockito.verify(inventory).send(any(InventorySlotStackSizeChangedEvent.class));
Mockito.verifyNoMoreInteractions(instigator, inventory, entityManager, item, partialItem);
assertEquals(partialItem, inventoryComp.itemSlots.get(0));
assertEquals(4, partialItemComp.stackCount);
assertTrue(action.isConsumed());
}
use of org.terasology.logic.inventory.action.GiveItemAction in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method addItemToEmpty.
@Test
public void addItemToEmpty() {
ItemComponent itemComp = new ItemComponent();
EntityRef item = Mockito.mock(EntityRef.class);
setupItemRef(item, itemComp, 2, 10);
GiveItemAction action = new GiveItemAction(instigator, item);
inventoryAuthoritySystem.giveItem(action, inventory);
Mockito.verify(item, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(item, atLeast(0)).exists();
Mockito.verify(item).saveComponent(itemComp);
Mockito.verify(inventory, atLeast(0)).getComponent(InventoryComponent.class);
Mockito.verify(inventory).saveComponent(inventoryComp);
Mockito.verify(inventory, times(1)).send(any(BeforeItemPutInInventory.class));
Mockito.verify(inventory, times(1)).send(any(InventorySlotChangedEvent.class));
Mockito.verifyNoMoreInteractions(instigator, inventory, entityManager, item);
assertEquals(item, inventoryComp.itemSlots.get(0));
assertTrue(action.isConsumed());
}
Aggregations