Search in sources :

Example 31 with Setup

use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.

the class LauncherModelTest method testLauncherDelay.

/**
 * Test the launcher with delay.
 *
 * @throws InterruptedException If error.
 */
@Test
void testLauncherDelay() throws InterruptedException {
    final Media launcherMedia = UtilLaunchable.createLauncherMedia(launchableMedia, 100);
    final Setup setup = new Setup(launcherMedia);
    final Launcher launcher = UtilLaunchable.createLauncher(services, setup, featurable);
    final AtomicBoolean fired = new AtomicBoolean();
    final AtomicReference<Launchable> firedLaunchable = new AtomicReference<>();
    launcher.addListener(UtilLaunchable.createListener(fired));
    launcher.addListener(UtilLaunchable.createListener(firedLaunchable));
    assertTimeout(1000L, () -> {
        while (!launcher.fire()) {
            launcher.update(1.0);
        }
    });
    final Handler handler = services.get(Handler.class);
    launcher.update(1.0);
    handler.update(1.0);
    assertEquals(0, handler.size());
    assertTrue(fired.get());
    assertNull(firedLaunchable.get());
    assertTimeout(1000L, () -> {
        while (firedLaunchable.get() == null) {
            launcher.update(1.0);
            handler.update(1.0);
        }
    });
    assertEquals(1, handler.size());
    firedLaunchable.set(null);
    handler.removeAll();
    handler.update(1.0);
    assertEquals(0, handler.size());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Media(com.b3dgs.lionengine.Media) Handler(com.b3dgs.lionengine.game.feature.Handler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Test(org.junit.jupiter.api.Test)

Example 32 with Setup

use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.

the class ProducibleModelTest method testProducibleSelf.

/**
 * Test the producible self listener.
 */
@Test
void testProducibleSelf() {
    final Media media = UtilProducible.createProducibleMedia();
    final Setup setup = new Setup(media);
    final ProducibleListenerSelf object = new ProducibleListenerSelf(services, setup);
    final Producible producible = new ProducibleModel(services, setup);
    producible.prepare(object);
    assertTrue(producible.getListeners().contains(object));
    producible.getFeature(Identifiable.class).notifyDestroyed();
    assertTrue(media.getFile().delete());
}
Also used : Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Example 33 with Setup

use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.

the class StateHandlerTest method testHandlerConverter.

/**
 * Test the state handling with custom converter.
 */
@Test
void testHandlerConverter() {
    Medias.setLoadFromJar(StateHandlerTest.class);
    try {
        final Setup setup = new Setup(Medias.create("Object.xml"));
        final Featurable featurable = new FeaturableModel(services, setup);
        final StateHandler handler;
        handler = featurable.addFeatureAndGet(new StateHandler(services, setup, Class::getName));
        handler.prepare(featurable);
        handler.changeState(StateIdle.class);
        assertCause(() -> handler.postUpdate(), "Animation not found: " + StateIdle.class.getName());
    } finally {
        Medias.setLoadFromJar(null);
    }
}
Also used : FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 34 with Setup

use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.

the class StateHandlerTest method testUnknownState.

/**
 * Test is state with invalid parameter.
 */
@Test
void testUnknownState() {
    Medias.setResourcesDirectory(System.getProperty("java.io.tmpdir"));
    final Media config = UtilTransformable.createMedia(StateHandlerTest.class);
    try {
        final Setup setup = new Setup(config);
        final StateHandler handler = new StateHandler(services, setup);
        handler.changeState(State.class);
        assertCause(() -> handler.postUpdate(), NoSuchMethodException.class);
        assertTrue(config.getFile().delete());
    } finally {
        Medias.setResourcesDirectory(null);
    }
}
Also used : Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Test(org.junit.jupiter.api.Test)

Example 35 with Setup

use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.

the class StateHandlerTest method testHandler.

/**
 * Test the state handling.
 */
@Test
void testHandler() {
    Medias.setResourcesDirectory(System.getProperty("java.io.tmpdir"));
    final Media config = UtilTransformable.createMedia(StateHandlerTest.class);
    try {
        final Setup setup = new Setup(config);
        final StateHandler handler = new StateHandler(services, setup);
        assertFalse(handler.isState(StateBase.class));
        assertFalse(StateBase.entered);
        assertFalse(StateBase.updated);
        assertFalse(StateBase.exited);
        handler.update(1.0);
        handler.postUpdate();
        assertFalse(handler.isState(StateBase.class));
        assertFalse(StateBase.entered);
        assertFalse(StateBase.updated);
        assertFalse(StateBase.exited);
        handler.changeState(StateBase.class);
        handler.postUpdate();
        assertTrue(handler.isState(StateBase.class));
        assertTrue(StateBase.entered);
        assertFalse(StateBase.updated);
        assertFalse(StateBase.exited);
        StateBase.reset();
        handler.update(1.0);
        handler.postUpdate();
        assertFalse(StateBase.entered);
        assertTrue(StateBase.updated);
        assertFalse(StateBase.exited);
        assertFalse(StateNext.entered);
        assertFalse(StateNext.updated);
        assertFalse(StateNext.exited);
        StateBase.reset();
        StateBase.check = true;
        handler.update(1.0);
        handler.postUpdate();
        assertFalse(StateBase.entered);
        assertTrue(StateBase.updated);
        assertTrue(StateBase.exited);
        assertTrue(StateNext.entered);
        assertFalse(StateNext.updated);
        assertFalse(StateNext.exited);
        StateBase.reset();
        handler.update(1.0);
        handler.postUpdate();
        assertFalse(StateBase.entered);
        assertFalse(StateBase.updated);
        assertFalse(StateBase.exited);
        assertTrue(StateNext.updated);
        assertFalse(StateNext.exited);
        assertTrue(config.getFile().delete());
    } finally {
        Medias.setResourcesDirectory(null);
    }
}
Also used : Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Test(org.junit.jupiter.api.Test)

Aggregations

Setup (com.b3dgs.lionengine.game.feature.Setup)42 Test (org.junit.jupiter.api.Test)34 Media (com.b3dgs.lionengine.Media)31 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)20 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)18 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)15 Xml (com.b3dgs.lionengine.Xml)11 Featurable (com.b3dgs.lionengine.game.feature.Featurable)11 Transformable (com.b3dgs.lionengine.game.feature.Transformable)11 Services (com.b3dgs.lionengine.game.feature.Services)10 Medias (com.b3dgs.lionengine.Medias)6 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)6 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)6 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)6 Handler (com.b3dgs.lionengine.game.feature.Handler)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 AfterAll (org.junit.jupiter.api.AfterAll)5 BeforeAll (org.junit.jupiter.api.BeforeAll)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 UtilAssert.assertFalse (com.b3dgs.lionengine.UtilAssert.assertFalse)4