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);
}
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);
}
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));
}
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();
}
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);
}
Aggregations