Search in sources :

Example 1 with RemoveItemAction

use of org.terasology.logic.inventory.action.RemoveItemAction in project Terasology by MovingBlocks.

the class InventoryAuthoritySystemTest method removePartOfStackWithDestroy.

@Test
public void removePartOfStackWithDestroy() {
    ItemComponent itemComp = new ItemComponent();
    EntityRef item = Mockito.mock(EntityRef.class);
    setupItemRef(item, itemComp, 2, 10);
    inventoryComp.itemSlots.set(0, item);
    RemoveItemAction action = new RemoveItemAction(instigator, item, true, 1);
    inventoryAuthoritySystem.removeItem(action, inventory);
    assertEquals(1, itemComp.stackCount);
    Mockito.verify(item, atLeast(0)).getComponent(ItemComponent.class);
    Mockito.verify(item).saveComponent(itemComp);
    Mockito.verify(inventory, atLeast(0)).getComponent(InventoryComponent.class);
    Mockito.verify(inventory).send(any(InventorySlotStackSizeChangedEvent.class));
    Mockito.verifyNoMoreInteractions(instigator, inventory, entityManager, item);
    assertTrue(action.isConsumed());
    assertNull(action.getRemovedItem());
}
Also used : InventorySlotStackSizeChangedEvent(org.terasology.logic.inventory.events.InventorySlotStackSizeChangedEvent) RemoveItemAction(org.terasology.logic.inventory.action.RemoveItemAction) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 2 with RemoveItemAction

use of org.terasology.logic.inventory.action.RemoveItemAction in project Terasology by MovingBlocks.

the class InventoryAuthoritySystemTest method removeWholeStackWithVeto.

@Test
public void removeWholeStackWithVeto() {
    ItemComponent itemComp = new ItemComponent();
    EntityRef item = Mockito.mock(EntityRef.class);
    setupItemRef(item, itemComp, 2, 10);
    inventoryComp.itemSlots.set(0, item);
    Mockito.when(inventory.send(any(BeforeItemRemovedFromInventory.class))).then(invocation -> {
        BeforeItemRemovedFromInventory event = (BeforeItemRemovedFromInventory) invocation.getArguments()[0];
        event.consume();
        return null;
    });
    RemoveItemAction action = new RemoveItemAction(instigator, item, true, 2);
    inventoryAuthoritySystem.removeItem(action, inventory);
    assertFalse(action.isConsumed());
    assertNull(action.getRemovedItem());
    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).send(any(BeforeItemRemovedFromInventory.class));
    Mockito.verifyNoMoreInteractions(instigator, inventory, entityManager, item);
}
Also used : BeforeItemRemovedFromInventory(org.terasology.logic.inventory.events.BeforeItemRemovedFromInventory) RemoveItemAction(org.terasology.logic.inventory.action.RemoveItemAction) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 3 with RemoveItemAction

use of org.terasology.logic.inventory.action.RemoveItemAction in project Terasology by MovingBlocks.

the class InventoryAuthoritySystemTest method removeWholeStack.

@Test
public void removeWholeStack() {
    ItemComponent itemComp = new ItemComponent();
    EntityRef item = Mockito.mock(EntityRef.class);
    setupItemRef(item, itemComp, 2, 10);
    inventoryComp.itemSlots.set(0, item);
    RemoveItemAction action = new RemoveItemAction(instigator, item, false, 2);
    inventoryAuthoritySystem.removeItem(action, inventory);
    assertTrue(action.isConsumed());
    assertEquals(item, action.getRemovedItem());
    assertEquals(EntityRef.NULL, inventoryComp.itemSlots.get(0));
    Mockito.verify(item, atLeast(0)).getComponent(ItemComponent.class);
    Mockito.verify(item, atLeast(0)).exists();
    Mockito.verify(item, atLeast(0)).iterateComponents();
    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.verifyNoMoreInteractions(instigator, inventory, entityManager, item);
}
Also used : BeforeItemRemovedFromInventory(org.terasology.logic.inventory.events.BeforeItemRemovedFromInventory) RemoveItemAction(org.terasology.logic.inventory.action.RemoveItemAction) EntityRef(org.terasology.entitySystem.entity.EntityRef) InventorySlotChangedEvent(org.terasology.logic.inventory.events.InventorySlotChangedEvent) Test(org.junit.Test)

Example 4 with RemoveItemAction

use of org.terasology.logic.inventory.action.RemoveItemAction in project Terasology by MovingBlocks.

the class InventoryAuthoritySystemTest method removeWholeStackWithDestroy.

@Test
public void removeWholeStackWithDestroy() {
    ItemComponent itemComp = new ItemComponent();
    EntityRef item = Mockito.mock(EntityRef.class);
    setupItemRef(item, itemComp, 2, 10);
    inventoryComp.itemSlots.set(0, item);
    RemoveItemAction action = new RemoveItemAction(instigator, item, true, 2);
    inventoryAuthoritySystem.removeItem(action, inventory);
    assertTrue(action.isConsumed());
    assertNull(action.getRemovedItem());
    assertEquals(EntityRef.NULL, inventoryComp.itemSlots.get(0));
    Mockito.verify(item, atLeast(0)).getComponent(ItemComponent.class);
    Mockito.verify(item, atLeast(0)).exists();
    Mockito.verify(item).destroy();
    Mockito.verify(inventory, atLeast(0)).getComponent(InventoryComponent.class);
    Mockito.verify(inventory).saveComponent(inventoryComp);
    Mockito.verify(inventory, times(1)).send(Mockito.any(BeforeItemRemovedFromInventory.class));
    Mockito.verify(inventory, times(1)).send(Mockito.any(InventorySlotChangedEvent.class));
    Mockito.verifyNoMoreInteractions(instigator, inventory, entityManager, item);
}
Also used : BeforeItemRemovedFromInventory(org.terasology.logic.inventory.events.BeforeItemRemovedFromInventory) RemoveItemAction(org.terasology.logic.inventory.action.RemoveItemAction) EntityRef(org.terasology.entitySystem.entity.EntityRef) InventorySlotChangedEvent(org.terasology.logic.inventory.events.InventorySlotChangedEvent) Test(org.junit.Test)

Example 5 with RemoveItemAction

use of org.terasology.logic.inventory.action.RemoveItemAction in project Terasology by MovingBlocks.

the class InventoryAuthoritySystemTest method removeOverOneStack.

@Test
public void removeOverOneStack() {
    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), false, 3);
    inventoryAuthoritySystem.removeItem(action, inventory);
    assertEquals(EntityRef.NULL, inventoryComp.itemSlots.get(0));
    assertEquals(3, itemComp1.stackCount);
    assertEquals(1, itemComp2.stackCount);
    assertTrue(action.isConsumed());
    assertEquals(item1, 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).saveComponent(itemComp1);
    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);
}
Also used : InventorySlotStackSizeChangedEvent(org.terasology.logic.inventory.events.InventorySlotStackSizeChangedEvent) BeforeItemRemovedFromInventory(org.terasology.logic.inventory.events.BeforeItemRemovedFromInventory) RemoveItemAction(org.terasology.logic.inventory.action.RemoveItemAction) EntityRef(org.terasology.entitySystem.entity.EntityRef) InventorySlotChangedEvent(org.terasology.logic.inventory.events.InventorySlotChangedEvent) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 EntityRef (org.terasology.entitySystem.entity.EntityRef)7 RemoveItemAction (org.terasology.logic.inventory.action.RemoveItemAction)7 BeforeItemRemovedFromInventory (org.terasology.logic.inventory.events.BeforeItemRemovedFromInventory)5 InventorySlotChangedEvent (org.terasology.logic.inventory.events.InventorySlotChangedEvent)4 InventorySlotStackSizeChangedEvent (org.terasology.logic.inventory.events.InventorySlotStackSizeChangedEvent)4