Search in sources :

Example 6 with IntegerComponent

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

the class EntitySerializerTest method testDeltaLoadAddedComponent.

@Test
public void testDeltaLoadAddedComponent() throws Exception {
    EntityRef entity = entityManager.create("test:Test");
    entity.addComponent(new IntegerComponent(2));
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    long nextId = entityManager.getNextId();
    entityManager.clear();
    entityManager.setNextId(nextId);
    EntityRef loadedEntity = entitySerializer.deserialize(entityData);
    assertTrue(loadedEntity.exists());
    assertTrue(loadedEntity.hasComponent(StringComponent.class));
    assertEquals("Value", loadedEntity.getComponent(StringComponent.class).value);
    assertTrue(loadedEntity.hasComponent(IntegerComponent.class));
    assertEquals(2, loadedEntity.getComponent(IntegerComponent.class).value);
}
Also used : IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) StringComponent(org.terasology.unittest.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 7 with IntegerComponent

use of org.terasology.unittest.stubs.IntegerComponent 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 8 with IntegerComponent

use of org.terasology.unittest.stubs.IntegerComponent 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 9 with IntegerComponent

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

the class PojoEventSystemTests method testSendEventToEntityWithMultipleComponents.

@Test
public void testSendEventToEntityWithMultipleComponents() {
    entity.addComponent(new StringComponent());
    entity.addComponent(new IntegerComponent());
    TestEventHandler handler = new TestEventHandler();
    eventSystem.registerEventHandler(handler);
    TestEvent event = new TestEvent();
    entity.send(event);
    assertEquals(2, handler.receivedList.size());
    for (TestEventHandler.Received received : handler.receivedList) {
        assertEquals(event, received.event);
        assertEquals(entity, received.entity);
    }
}
Also used : IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) StringComponent(org.terasology.unittest.stubs.StringComponent) Test(org.junit.jupiter.api.Test)

Example 10 with IntegerComponent

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

the class PojoEventSystemTests method testChildEventReceivedByUnfilteredHandler.

@Test
public void testChildEventReceivedByUnfilteredHandler() {
    entity.addComponent(new IntegerComponent());
    TestEventHandler handler = new TestEventHandler();
    eventSystem.registerEvent(new ResourceUrn("test:childEvent"), TestChildEvent.class);
    eventSystem.registerEventHandler(handler);
    TestChildEvent event = new TestChildEvent();
    eventSystem.send(entity, event);
    assertEquals(1, handler.unfilteredEvents.size());
}
Also used : IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)14 IntegerComponent (org.terasology.unittest.stubs.IntegerComponent)14 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)8 StringComponent (org.terasology.unittest.stubs.StringComponent)6 Vector3i (org.joml.Vector3i)4 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)2 EntityData (org.terasology.protobuf.EntityData)2 ByteCodeReflectFactory (org.terasology.engine.reflection.reflect.ByteCodeReflectFactory)1