Search in sources :

Example 1 with Feature

use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.

the class FeaturableModelTest method testAddFeatures.

/**
 * Test the add features.
 */
@Test
void testAddFeatures() {
    final Media media = Medias.create("Features.xml");
    final Xml root = new Xml(FeaturableConfig.NODE_FEATURABLE);
    final Xml unknown = root.createChild(FeaturableConfig.NODE_FEATURE);
    unknown.setText(MyFeature.class.getName());
    root.save(media);
    Featurable featurable = new FeaturableModel(new Services(), new Setup(media));
    featurable.checkListener(featurable);
    assertEquals(media, featurable.getMedia());
    for (final Feature next : featurable.getFeatures()) {
        assertTrue(MyFeature.class.equals(next.getClass()) || Identifiable.class.isAssignableFrom(next.getClass()) || Recycler.class.isAssignableFrom(next.getClass()), next.getClass().getName());
    }
    featurable = new FeaturableModel(new Services(), new Setup(media));
    UtilFile.deleteFile(media.getFile());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Feature(com.b3dgs.lionengine.game.Feature) Test(org.junit.jupiter.api.Test)

Example 2 with Feature

use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.

the class FeaturableModelTest method testFeaturableCompatible.

/**
 * Test the featurable model with compatible feature.
 */
@Test
void testFeaturableCompatible() {
    final Featurable featurable = new FeaturableModel(services, setup);
    final MyFeatureInterface feature = new MyFeature(services, setup);
    featurable.addFeature(feature);
    assertTrue(featurable.hasFeature(MyFeatureInterface.class));
    assertTrue(featurable.hasFeature(MyFeature.class));
    assertEquals(feature, featurable.getFeature(MyFeature.class));
    for (final Feature current : featurable.getFeatures()) {
        assertTrue(feature.getClass().equals(current.getClass()) || Identifiable.class.isAssignableFrom(current.getClass()) || Recycler.class.isAssignableFrom(current.getClass()), current.getClass().getName());
    }
    for (final Class<? extends Feature> type : featurable.getFeaturesType()) {
        assertTrue(MyFeatureInterface.class.isAssignableFrom(type) || Identifiable.class.isAssignableFrom(type) || Recycler.class.isAssignableFrom(type), type.getName());
    }
}
Also used : Feature(com.b3dgs.lionengine.game.Feature) Test(org.junit.jupiter.api.Test)

Example 3 with Feature

use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.

the class FeaturableModelTest method testFeaturableNotcompatible.

/**
 * Test the featurable model with not compatible interface.
 */
@Test
void testFeaturableNotcompatible() {
    final Featurable featurable = new FeaturableModel(services, setup);
    final MyFeatureNotCompatible feature = new MyFeatureNotCompatible(services, setup);
    featurable.addFeature(feature);
    assertTrue(featurable.hasFeature(MyFeatureNotCompatible.class));
    assertEquals(feature, featurable.getFeature(MyFeatureNotCompatible.class));
    for (final Feature current : featurable.getFeatures()) {
        assertTrue(feature.getClass().equals(current.getClass()) || Identifiable.class.isAssignableFrom(current.getClass()) || Recycler.class.isAssignableFrom(current.getClass()), current.getClass().getName());
    }
    for (final Class<? extends Feature> type : featurable.getFeaturesType()) {
        assertTrue(MyFeatureNotCompatible.class.isAssignableFrom(type) || Identifiable.class.isAssignableFrom(type) || Recycler.class.isAssignableFrom(type), type.getName());
    }
}
Also used : Feature(com.b3dgs.lionengine.game.Feature) Test(org.junit.jupiter.api.Test)

Example 4 with Feature

use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.

the class FeaturableModelTest method testFeatureAnnotationNotFound.

/**
 * Test with annotation and feature not found.
 */
@Test
void testFeatureAnnotationNotFound() {
    final Featurable featurable = new FeaturableModel(services, setup);
    final AtomicReference<String> unfilledType = new AtomicReference<>();
    final Feature feature = new FeatureModel(services, setup) {

        @FeatureGet
        private String type;

        @Override
        public void prepare(FeatureProvider provider) {
            super.prepare(provider);
            unfilledType.set(type);
        }
    };
    assertThrows(() -> featurable.addFeature(feature), "[transformable_FeaturableModelTest.xml] Class not found: " + String.class + " in " + feature);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) FeatureProvider(com.b3dgs.lionengine.game.FeatureProvider) Feature(com.b3dgs.lionengine.game.Feature) Test(org.junit.jupiter.api.Test)

Example 5 with Feature

use of com.b3dgs.lionengine.game.Feature in project lionengine by b3dgs.

the class FeaturableConfigTest method testGetFeaturesCache.

/**
 * Test with cached feature class.
 */
@Test
void testGetFeaturesCache() {
    final Xml root = new Xml("test");
    root.createChild(FeaturableConfig.NODE_FEATURES).createChild(FeaturableConfig.NODE_FEATURE).setText(FeatureModel.class.getName());
    final Media media = Medias.create("Object.xml");
    root.save(media);
    final ClassLoader loader = ClassLoader.getSystemClassLoader();
    final Services services = new Services();
    final Setup setup = new Setup(media);
    final List<Feature> a = FeaturableConfig.getFeatures(loader, services, setup);
    final List<Feature> b = FeaturableConfig.getFeatures(loader, services, setup);
    assertNotEquals(a.get(0), b.get(0));
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Feature(com.b3dgs.lionengine.game.Feature) Test(org.junit.jupiter.api.Test)

Aggregations

Feature (com.b3dgs.lionengine.game.Feature)14 Test (org.junit.jupiter.api.Test)8 Media (com.b3dgs.lionengine.Media)3 Xml (com.b3dgs.lionengine.Xml)3 LionEngineException (com.b3dgs.lionengine.LionEngineException)2 XmlReader (com.b3dgs.lionengine.XmlReader)1 FeatureProvider (com.b3dgs.lionengine.game.FeatureProvider)1 ArrayList (java.util.ArrayList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1