Search in sources :

Example 26 with StringComponent

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

the class ComponentSerializerTest method testDeltaComponentTypeIdDeserializesWithoutValue.

@Test
public void testDeltaComponentTypeIdDeserializesWithoutValue() throws Exception {
    componentSerializer.setIdMapping(ImmutableMap.<Class<? extends Component>, Integer>builder().put(StringComponent.class, 1).build());
    EntityData.Component compData = EntityData.Component.newBuilder().setTypeIndex(1).addField(EntityData.NameValue.newBuilder().setName("value")).build();
    StringComponent original = new StringComponent("test");
    componentSerializer.deserializeOnto(original, compData);
    assertEquals(null, original.value);
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) Test(org.junit.jupiter.api.Test)

Example 27 with StringComponent

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

the class PojoEntityManagerTest method testIterateEntitiesFindsEntityWithTwoComponents.

@Test
public void testIterateEntitiesFindsEntityWithTwoComponents() {
    EntityRef entity1 = entityManager.create();
    entity1.addComponent(new StringComponent());
    entity1.addComponent(new IntegerComponent());
    List<EntityRef> results = Lists.newArrayList(entityManager.getEntitiesWith(StringComponent.class, IntegerComponent.class));
    assertEquals(Lists.newArrayList(entity1), results);
}
Also used : IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) StringComponent(org.terasology.unittest.stubs.StringComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 28 with StringComponent

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

the class PojoEntityManagerTest method testDestroyEntity.

@Test
public void testDestroyEntity() {
    EntityRef entity = entityManager.create();
    entity.addComponent(new StringComponent());
    entity.addComponent(new IntegerComponent());
    entity.destroy();
    assertNull(entity.getComponent(StringComponent.class));
    assertNull(entity.getComponent(IntegerComponent.class));
}
Also used : IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) StringComponent(org.terasology.unittest.stubs.StringComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 29 with StringComponent

use of org.terasology.unittest.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.unittest.stubs.StringComponent) EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 30 with StringComponent

use of org.terasology.unittest.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.unittest.stubs.StringComponent) EventSystem(org.terasology.engine.entitySystem.event.internal.EventSystem) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Aggregations

StringComponent (org.terasology.unittest.stubs.StringComponent)41 Test (org.junit.jupiter.api.Test)38 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)22 EntityData (org.terasology.protobuf.EntityData)8 IntegerComponent (org.terasology.unittest.stubs.IntegerComponent)8 EventSystem (org.terasology.engine.entitySystem.event.internal.EventSystem)5 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)5 PrefabData (org.terasology.engine.entitySystem.prefab.PrefabData)4 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)3 PojoPrefab (org.terasology.engine.entitySystem.prefab.internal.PojoPrefab)3 Vector3i (org.joml.Vector3i)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 NetworkSystem (org.terasology.engine.network.NetworkSystem)2 Component (org.terasology.gestalt.entitysystem.component.Component)2 GetterSetterComponent (org.terasology.unittest.stubs.GetterSetterComponent)2 Map (java.util.Map)1 Reflections (org.reflections.Reflections)1 StorageManager (org.terasology.engine.persistence.StorageManager)1 EntitySerializer (org.terasology.engine.persistence.serializers.EntitySerializer)1