Search in sources :

Example 6 with StringComponent

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

the class EntityAwareWorldProviderTest method testChangedComponentsRevertedBeforeCleanUp.

@Test
public void testChangedComponentsRevertedBeforeCleanUp() {
    worldStub.setBlock(new Vector3i(), blockWithString);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    StringComponent comp = entity.getComponent(StringComponent.class);
    comp.value = "Moo";
    entity.saveComponent(comp);
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);
    worldProvider.update(1.0f);
    assertEquals(Lists.newArrayList(new EventInfo(OnChangedComponent.newInstance(), entity)), checker.receivedEvents);
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 7 with StringComponent

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

the class EntityAwareWorldProviderTest method testEntityExtraComponentsRemovedBeforeCleanUp.

@Test
public void testEntityExtraComponentsRemovedBeforeCleanUp() {
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new StringComponent("test"));
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);
    worldProvider.update(1.0f);
    assertEquals(Lists.newArrayList(new EventInfo(BeforeDeactivateComponent.newInstance(), entity), new EventInfo(BeforeRemoveComponent.newInstance(), entity)), checker.receivedEvents);
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 8 with StringComponent

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

the class ByteCodeReflectFactoryTest method testCreateFieldAccessorDirectToField.

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

Example 9 with StringComponent

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

the class PojoEntityManagerTest method testChangeComponentsDuringIterator.

@Test
public void testChangeComponentsDuringIterator() {
    EntityRef entity1 = entityManager.create();
    entity1.addComponent(new StringComponent());
    EntityRef entity2 = entityManager.create();
    entity2.addComponent(new StringComponent());
    Iterator<Map.Entry<EntityRef, StringComponent>> iterator = entityManager.listComponents(StringComponent.class).iterator();
    iterator.next();
    entity2.removeComponent(StringComponent.class);
    iterator.next();
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 10 with StringComponent

use of org.terasology.unittest.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.unittest.stubs.StringComponent) 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