Search in sources :

Example 1 with IntegerComponent

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

the class EntityAwareWorldProviderTest method testComponentsAlteredIfBlockInSameFamilyWhenForced.

@Test
public void testComponentsAlteredIfBlockInSameFamilyWhenForced() {
    worldProvider.setBlock(new Vector3i(), blockInFamilyOne);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new IntegerComponent());
    worldProvider.setBlockForceUpdateEntity(new Vector3i(), blockInFamilyTwo);
    assertNull(entity.getComponent(IntegerComponent.class));
}
Also used : IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 2 with IntegerComponent

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

the class EntityAwareWorldProviderTest method testComponentUntouchedIfRetainRequested.

@Test
public void testComponentUntouchedIfRetainRequested() {
    worldProvider.setBlock(new Vector3i(), blockInFamilyOne);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new IntegerComponent());
    worldProvider.setBlockRetainComponent(new Vector3i(), blockWithString, IntegerComponent.class);
    assertNotNull(entity.getComponent(IntegerComponent.class));
}
Also used : IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 3 with IntegerComponent

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

the class ByteCodeReflectFactoryTest method testAccessIntegerField.

@Test
public void testAccessIntegerField() throws Exception {
    ReflectFactory reflectFactory = new ByteCodeReflectFactory();
    FieldAccessor fieldAccessor = reflectFactory.createFieldAccessor(IntegerComponent.class, IntegerComponent.class.getDeclaredField("value"));
    IntegerComponent comp = new IntegerComponent();
    fieldAccessor.setValue(comp, 1);
    assertEquals(1, fieldAccessor.getValue(comp));
}
Also used : ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) Test(org.junit.jupiter.api.Test)

Example 4 with IntegerComponent

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

the class PojoEventSystemTests method testSendEventToEntityComponent.

@Test
public void testSendEventToEntityComponent() {
    entity.addComponent(new StringComponent());
    IntegerComponent intComponent = entity.addComponent(new IntegerComponent());
    TestEventHandler handler = new TestEventHandler();
    eventSystem.registerEventHandler(handler);
    TestEvent event = new TestEvent();
    eventSystem.send(entity, event, intComponent);
    assertEquals(1, handler.receivedList.size());
    assertEquals(event, handler.receivedList.get(0).event);
    assertEquals(entity, handler.receivedList.get(0).entity);
}
Also used : IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) StringComponent(org.terasology.unittest.stubs.StringComponent) Test(org.junit.jupiter.api.Test)

Example 5 with IntegerComponent

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

the class EntitySerializerTest method testDeltaAddNewComponent.

@Test
public void testDeltaAddNewComponent() throws Exception {
    EntityRef entity = entityManager.create(prefab);
    entity.addComponent(new IntegerComponent(1));
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    assertEquals(entity.getId(), entityData.getId());
    assertEquals(prefab.getName(), entityData.getParentPrefab());
    assertEquals(1, entityData.getComponentCount());
    assertEquals(0, entityData.getRemovedComponentCount());
    EntityData.Component componentData = entityData.getComponent(0);
    assertEquals("test:integer", componentData.getType());
    assertEquals(1, componentData.getFieldCount());
    EntityData.NameValue field = componentData.getField(0);
    assertEquals("value", field.getName());
    assertEquals(1, field.getValue().getInteger(0));
}
Also used : IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) 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