Search in sources :

Example 11 with IntegerComponent

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

the class PojoEventSystemTests method testReceiveEventRequiringMultipleComponents.

@Test
public void testReceiveEventRequiringMultipleComponents() {
    entity.addComponent(new StringComponent());
    entity.addComponent(new IntegerComponent());
    TestCompoundComponentEventHandler handler = new TestCompoundComponentEventHandler();
    eventSystem.registerEventHandler(handler);
    TestEvent event = new TestEvent();
    eventSystem.send(entity, event);
    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 12 with IntegerComponent

use of org.terasology.unittest.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 ResourceUrn("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.unittest.stubs.IntegerComponent) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Test(org.junit.jupiter.api.Test)

Example 13 with IntegerComponent

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

the class EntityAwareWorldProviderTest method testComponentsNotAlteredIfBlockInSameFamily.

@Test
public void testComponentsNotAlteredIfBlockInSameFamily() {
    worldProvider.setBlock(new Vector3i(), blockInFamilyOne);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new IntegerComponent());
    worldProvider.setBlock(new Vector3i(), blockInFamilyTwo);
    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 14 with IntegerComponent

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

the class EntityAwareWorldProviderTest method testEntityExtraComponentsRemovedBeforeCleanUpForBlocksWithPrefabs.

@Test
public void testEntityExtraComponentsRemovedBeforeCleanUpForBlocksWithPrefabs() {
    worldStub.setBlock(new Vector3i(), blockWithString);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new IntegerComponent(1));
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), IntegerComponent.class);
    worldProvider.update(1.0f);
    assertEquals(Lists.newArrayList(new EventInfo(BeforeDeactivateComponent.newInstance(), entity), new EventInfo(BeforeRemoveComponent.newInstance(), entity)), checker.receivedEvents);
}
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)

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