Search in sources :

Example 6 with IntegerComponent

use of org.terasology.entitySystem.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.entitySystem.stubs.IntegerComponent) StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 7 with IntegerComponent

use of org.terasology.entitySystem.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.entitySystem.stubs.IntegerComponent) StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 8 with IntegerComponent

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

the class PojoEventSystemTests method testSendEventToEntityWithMultipleComponents.

@Test
public void testSendEventToEntityWithMultipleComponents() {
    StringComponent stringComponent = entity.addComponent(new StringComponent());
    IntegerComponent intComponent = 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.entitySystem.stubs.IntegerComponent) StringComponent(org.terasology.entitySystem.stubs.StringComponent) Test(org.junit.Test)

Example 9 with IntegerComponent

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

the class PojoEventSystemTests method testChildEvent.

@Test
public void testChildEvent() {
    entity.addComponent(new IntegerComponent());
    TestEventHandler handler = new TestEventHandler();
    eventSystem.registerEvent(new SimpleUri("test:childEvent"), TestChildEvent.class);
    eventSystem.registerEventHandler(handler);
    TestChildEvent event = new TestChildEvent();
    eventSystem.send(entity, event);
    assertEquals(1, handler.childEventReceived.size());
    assertEquals(1, handler.receivedList.size());
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) SimpleUri(org.terasology.engine.SimpleUri) Test(org.junit.Test)

Example 10 with IntegerComponent

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

the class PojoEventSystemTests method testSendEventToEntityComponent.

@Test
public void testSendEventToEntityComponent() {
    StringComponent component = 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.entitySystem.stubs.IntegerComponent) StringComponent(org.terasology.entitySystem.stubs.StringComponent) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 IntegerComponent (org.terasology.entitySystem.stubs.IntegerComponent)14 EntityRef (org.terasology.entitySystem.entity.EntityRef)8 StringComponent (org.terasology.entitySystem.stubs.StringComponent)6 SimpleUri (org.terasology.engine.SimpleUri)2 EntityData (org.terasology.protobuf.EntityData)2 Vector3i (org.terasology.math.geom.Vector3i)1