Search in sources :

Example 1 with FeatureProvider

use of com.b3dgs.lionengine.game.FeatureProvider 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 2 with FeatureProvider

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

the class ComponentDisplayableTest method testRemoveLayerable.

/**
 * Test the component with layerable remove.
 */
@Test
void testRemoveLayerable() {
    final AtomicBoolean called = new AtomicBoolean();
    final ComponentDisplayable component = new ComponentDisplayable() {

        @Override
        public void notifyLayerChanged(FeatureProvider provider, Integer layerRefreshOld, Integer layerRefreshNew, Integer layerDisplayOld, Integer layerDisplayNew) {
            super.notifyLayerChanged(provider, layerRefreshOld, layerRefreshNew, layerDisplayOld, layerDisplayNew);
            called.set(true);
        }
    };
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeature(new RefreshableModel(extrp -> {
    // Mock
    }));
    final Layerable layerable = featurable.addFeatureAndGet(new LayerableModel(services, setup));
    component.notifyHandlableAdded(featurable);
    component.notifyHandlableRemoved(featurable);
    layerable.setLayer(Integer.valueOf(1), Integer.valueOf(1));
    assertFalse(called.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Medias(com.b3dgs.lionengine.Medias) UtilAssert.assertFalse(com.b3dgs.lionengine.UtilAssert.assertFalse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) FeatureProvider(com.b3dgs.lionengine.game.FeatureProvider) UtilReflection(com.b3dgs.lionengine.UtilReflection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FeatureProvider(com.b3dgs.lionengine.game.FeatureProvider) Test(org.junit.jupiter.api.Test)

Example 3 with FeatureProvider

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

the class ComponentRefreshableTest method testRemoveLayerable.

/**
 * Test the component with layerable remove.
 */
@Test
void testRemoveLayerable() {
    final AtomicBoolean called = new AtomicBoolean();
    final ComponentRefreshable component = new ComponentRefreshable() {

        @Override
        public void notifyLayerChanged(FeatureProvider provider, Integer layerRefreshOld, Integer layerRefreshNew, Integer layerDisplayOld, Integer layerDisplayNew) {
            super.notifyLayerChanged(provider, layerRefreshOld, layerRefreshNew, layerDisplayOld, layerDisplayNew);
            called.set(true);
        }
    };
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeature(new RefreshableModel(extrp -> {
    // Mock
    }));
    final Layerable layerable = featurable.addFeatureAndGet(new LayerableModel(services, setup));
    component.notifyHandlableAdded(featurable);
    component.notifyHandlableRemoved(featurable);
    layerable.setLayer(Integer.valueOf(1), Integer.valueOf(1));
    assertFalse(called.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Medias(com.b3dgs.lionengine.Medias) UtilAssert.assertFalse(com.b3dgs.lionengine.UtilAssert.assertFalse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) FeatureProvider(com.b3dgs.lionengine.game.FeatureProvider) UtilReflection(com.b3dgs.lionengine.UtilReflection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FeatureProvider(com.b3dgs.lionengine.game.FeatureProvider) Test(org.junit.jupiter.api.Test)

Example 4 with FeatureProvider

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

the class LayerableModelTest method testLayer.

/**
 * Test the layer functionality.
 */
@Test
void testLayer() {
    final LayerableModel layerable = new LayerableModel(services, setup);
    final AtomicReference<FeatureProvider> objectRef = new AtomicReference<>();
    final AtomicInteger oldLayerRef = new AtomicInteger();
    final AtomicInteger newLayerRef = new AtomicInteger();
    final LayerableListener listener = (provider, layerRefreshOld, layerRefreshNew, layerDisplayOld, layerDisplayNew) -> {
        objectRef.set(provider);
        oldLayerRef.set(layerRefreshOld.intValue());
        newLayerRef.set(layerRefreshNew.intValue());
    };
    layerable.addListener(listener);
    services.add(new ComponentDisplayable());
    final Featurable featurable = new FeaturableModel(services, setup);
    layerable.prepare(featurable);
    assertEquals(1, layerable.getLayerRefresh().intValue());
    assertEquals(2, layerable.getLayerDisplay().intValue());
    layerable.setLayer(Integer.valueOf(1), Integer.valueOf(2));
    assertEquals(1, layerable.getLayerRefresh().intValue());
    assertEquals(2, layerable.getLayerDisplay().intValue());
    layerable.removeListener(listener);
    objectRef.set(null);
    layerable.setLayer(Integer.valueOf(1), Integer.valueOf(2));
    assertNull(objectRef.get());
}
Also used : AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Medias(com.b3dgs.lionengine.Medias) Xml(com.b3dgs.lionengine.Xml) UtilAssert.assertNull(com.b3dgs.lionengine.UtilAssert.assertNull) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) FeatureProvider(com.b3dgs.lionengine.game.FeatureProvider) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) FeatureProvider(com.b3dgs.lionengine.game.FeatureProvider) Test(org.junit.jupiter.api.Test)

Aggregations

FeatureProvider (com.b3dgs.lionengine.game.FeatureProvider)4 Test (org.junit.jupiter.api.Test)4 Media (com.b3dgs.lionengine.Media)3 Medias (com.b3dgs.lionengine.Medias)3 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)3 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AfterAll (org.junit.jupiter.api.AfterAll)3 BeforeAll (org.junit.jupiter.api.BeforeAll)3 UtilAssert.assertFalse (com.b3dgs.lionengine.UtilAssert.assertFalse)2 UtilReflection (com.b3dgs.lionengine.UtilReflection)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 UtilAssert.assertNull (com.b3dgs.lionengine.UtilAssert.assertNull)1 Xml (com.b3dgs.lionengine.Xml)1 Feature (com.b3dgs.lionengine.game.Feature)1 HashSet (java.util.HashSet)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1