Search in sources :

Example 21 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testRemoveComponentEventSent.

@Test
public void testRemoveComponentEventSent() {
    EventSystem eventSystem = mock(EventSystem.class);
    EntityRef entity1 = entityManager.create();
    StringComponent comp = entity1.addComponent(new StringComponent());
    entityManager.setEventSystem(eventSystem);
    entity1.removeComponent(StringComponent.class);
    verify(eventSystem).send(entity1, BeforeDeactivateComponent.newInstance(), comp);
    verify(eventSystem).send(entity1, BeforeRemoveComponent.newInstance(), comp);
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 22 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testPrefabCopiedCorrectly.

@Test
public void testPrefabCopiedCorrectly() {
    EntityRef entity1 = entityManager.create(prefab);
    StringComponent comp = entity1.getComponent(StringComponent.class);
    assertEquals("Test", comp.value);
    comp.value = "One";
    entity1.saveComponent(comp);
    assertEquals("Test", prefab.getComponent(StringComponent.class).value);
    EntityRef entity2 = entityManager.create(prefab);
    assertEquals("Test", prefab.getComponent(StringComponent.class).value);
    assertEquals("One", entity1.getComponent(StringComponent.class).value);
    assertEquals("Test", entity2.getComponent(StringComponent.class).value);
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 23 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testReplaceComponent.

@Test
public void testReplaceComponent() {
    EntityRef entity = entityManager.create();
    StringComponent comp = new StringComponent();
    comp.value = "Hello";
    StringComponent comp2 = new StringComponent();
    comp2.value = "Goodbye";
    entity.addComponent(comp);
    entity.addComponent(comp2);
    assertEquals(comp2, entity.getComponent(StringComponent.class));
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 24 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testIterateComponents.

@Test
public void testIterateComponents() {
    EntityRef entity = entityManager.create();
    StringComponent comp = new StringComponent();
    entity.addComponent(comp);
    for (Map.Entry<EntityRef, StringComponent> item : entityManager.listComponents(StringComponent.class)) {
        assertEquals(entity, item.getKey());
        assertEquals(comp, item.getValue());
    }
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Map(java.util.Map) Test(org.junit.Test)

Example 25 with StringComponent

use of org.terasology.entitySystem.stubs.StringComponent in project Terasology by MovingBlocks.

the class PojoEntityManagerTest method testMassRemovedComponentEventSentOnDestroy.

@Test
public void testMassRemovedComponentEventSentOnDestroy() {
    EventSystem eventSystem = mock(EventSystem.class);
    EntityRef entity1 = entityManager.create();
    entity1.addComponent(new StringComponent());
    entityManager.setEventSystem(eventSystem);
    entity1.destroy();
    verify(eventSystem).send(entity1, BeforeDeactivateComponent.newInstance());
    verify(eventSystem).send(entity1, BeforeRemoveComponent.newInstance());
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Aggregations

StringComponent (org.terasology.entitySystem.stubs.StringComponent)41 Test (org.junit.Test)38 EntityRef (org.terasology.entitySystem.entity.EntityRef)22 IntegerComponent (org.terasology.entitySystem.stubs.IntegerComponent)8 EntityData (org.terasology.protobuf.EntityData)8 EventSystem (org.terasology.entitySystem.event.internal.EventSystem)5 ResourceUrn (org.terasology.assets.ResourceUrn)4 PrefabData (org.terasology.entitySystem.prefab.PrefabData)4 Prefab (org.terasology.entitySystem.prefab.Prefab)3 PojoPrefab (org.terasology.entitySystem.prefab.internal.PojoPrefab)3 Before (org.junit.Before)2 SimpleUri (org.terasology.engine.SimpleUri)2 Component (org.terasology.entitySystem.Component)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 GetterSetterComponent (org.terasology.entitySystem.stubs.GetterSetterComponent)2 Vector3i (org.terasology.math.geom.Vector3i)2 NetworkSystem (org.terasology.network.NetworkSystem)2 Map (java.util.Map)1 EntityRefComponent (org.terasology.entitySystem.stubs.EntityRefComponent)1 StorageManager (org.terasology.persistence.StorageManager)1