Search in sources :

Example 1 with OwnerComponent

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

the class ComponentMetadataTest method testOwnsReferencesPopulated.

@Test
public void testOwnsReferencesPopulated() {
    Reflections reflections = new Reflections(getClass().getClassLoader());
    EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, new TypeHandlerLibraryImpl(reflections));
    ComponentLibrary lib = entitySystemLibrary.getComponentLibrary();
    lib.register(new ResourceUrn("unittest:owner"), OwnerComponent.class);
    ComponentMetadata<OwnerComponent> metadata = lib.getMetadata(OwnerComponent.class);
    assertTrue(metadata.isReferenceOwner());
}
Also used : OwnerComponent(org.terasology.unittest.stubs.OwnerComponent) TypeHandlerLibraryImpl(org.terasology.engine.persistence.typeHandling.TypeHandlerLibraryImpl) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Reflections(org.reflections.Reflections) Test(org.junit.jupiter.api.Test)

Example 2 with OwnerComponent

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

the class FieldMetadataTest method testOwnsAnnotationProcessed.

@Test
public void testOwnsAnnotationProcessed() throws NoSuchMethodException {
    ComponentMetadata<OwnerComponent> classMetadata = new ComponentMetadata<>(new ResourceUrn("unittest:owner"), OwnerComponent.class, factory, copyStrategyLibrary);
    ComponentFieldMetadata metadata = classMetadata.getField("child");
    assertTrue(metadata.isOwnedReference());
}
Also used : OwnerComponent(org.terasology.unittest.stubs.OwnerComponent) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Test(org.junit.jupiter.api.Test)

Example 3 with OwnerComponent

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

the class OwnershipHelperTest method testListsOwnedEntities.

@Test
public void testListsOwnedEntities() {
    EntityRef ownedEntity = entityManager.create();
    OwnerComponent ownerComp = new OwnerComponent();
    ownerComp.child = ownedEntity;
    EntityRef ownerEntity = entityManager.create(ownerComp);
    OwnershipHelper helper = new OwnershipHelper(entityManager.getComponentLibrary());
    ArrayList<EntityRef> target = Lists.newArrayList(helper.listOwnedEntities(ownerEntity));
    assertEquals(target.size(), 1);
    assertEquals(target.get(0), ownedEntity);
}
Also used : OwnerComponent(org.terasology.unittest.stubs.OwnerComponent) OwnershipHelper(org.terasology.engine.entitySystem.entity.internal.OwnershipHelper) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 OwnerComponent (org.terasology.unittest.stubs.OwnerComponent)3 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)2 Reflections (org.reflections.Reflections)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 OwnershipHelper (org.terasology.engine.entitySystem.entity.internal.OwnershipHelper)1 TypeHandlerLibraryImpl (org.terasology.engine.persistence.typeHandling.TypeHandlerLibraryImpl)1